fix: redis plugin goroutine leak triggered by auto reload config mechanism (#11143)
This commit is contained in:
parent
f4eefeadcc
commit
ae98e7f1f6
|
|
@ -37,7 +37,7 @@ type Redis struct {
|
||||||
Password string
|
Password string
|
||||||
tls.ClientConfig
|
tls.ClientConfig
|
||||||
|
|
||||||
Log telegraf.Logger
|
Log telegraf.Logger `toml:"-"`
|
||||||
|
|
||||||
clients []Client
|
clients []Client
|
||||||
connected bool
|
connected bool
|
||||||
|
|
@ -47,6 +47,7 @@ type Client interface {
|
||||||
Do(returnType string, args ...interface{}) (interface{}, error)
|
Do(returnType string, args ...interface{}) (interface{}, error)
|
||||||
Info() *redis.StringCmd
|
Info() *redis.StringCmd
|
||||||
BaseTags() map[string]string
|
BaseTags() map[string]string
|
||||||
|
Close() error
|
||||||
}
|
}
|
||||||
|
|
||||||
type RedisClient struct {
|
type RedisClient struct {
|
||||||
|
|
@ -192,6 +193,10 @@ func (r *RedisClient) BaseTags() map[string]string {
|
||||||
return tags
|
return tags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *RedisClient) Close() error {
|
||||||
|
return r.client.Close()
|
||||||
|
}
|
||||||
|
|
||||||
var replicationSlaveMetricPrefix = regexp.MustCompile(`^slave\d+`)
|
var replicationSlaveMetricPrefix = regexp.MustCompile(`^slave\d+`)
|
||||||
|
|
||||||
var Tracking = map[string]string{
|
var Tracking = map[string]string{
|
||||||
|
|
@ -697,3 +702,17 @@ func coerceType(value interface{}, typ reflect.Type) reflect.Value {
|
||||||
}
|
}
|
||||||
return reflect.ValueOf(value)
|
return reflect.ValueOf(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Redis) Start(telegraf.Accumulator) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
//Stop close the client through ServiceInput interface Start/Stop methods impl.
|
||||||
|
func (r *Redis) Stop() {
|
||||||
|
for _, c := range r.clients {
|
||||||
|
err := c.Close()
|
||||||
|
if err != nil {
|
||||||
|
r.Log.Errorf("error closing client: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,10 @@ func (t *testClient) Do(_ string, _ ...interface{}) (interface{}, error) {
|
||||||
return 2, nil
|
return 2, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *testClient) Close() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func TestRedisConnectIntegration(t *testing.T) {
|
func TestRedisConnectIntegration(t *testing.T) {
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
t.Skip("Skipping integration test in short mode")
|
t.Skip("Skipping integration test in short mode")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue