Close idle connections in influxdb outputs when reloading (#5912)
This commit is contained in:
@@ -448,3 +448,7 @@ func makeQueryURL(loc *url.URL) (string, error) {
|
||||
}
|
||||
return u.String(), nil
|
||||
}
|
||||
|
||||
func (c *httpClient) Close() {
|
||||
internal.CloseIdleConnections(c.client)
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ type Client interface {
|
||||
CreateDatabase(ctx context.Context, database string) error
|
||||
Database() string
|
||||
URL() string
|
||||
Close()
|
||||
}
|
||||
|
||||
// InfluxDB struct is the primary data structure for the plugin
|
||||
@@ -183,6 +184,9 @@ func (i *InfluxDB) Connect() error {
|
||||
}
|
||||
|
||||
func (i *InfluxDB) Close() error {
|
||||
for _, client := range i.clients {
|
||||
client.Close()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ type MockClient struct {
|
||||
WriteF func(context.Context, []telegraf.Metric) error
|
||||
CreateDatabaseF func(ctx context.Context, database string) error
|
||||
DatabaseF func() string
|
||||
CloseF func()
|
||||
}
|
||||
|
||||
func (c *MockClient) URL() string {
|
||||
@@ -37,6 +38,10 @@ func (c *MockClient) Database() string {
|
||||
return c.DatabaseF()
|
||||
}
|
||||
|
||||
func (c *MockClient) Close() {
|
||||
c.CloseF()
|
||||
}
|
||||
|
||||
func TestDeprecatedURLSupport(t *testing.T) {
|
||||
var actual *influxdb.UDPConfig
|
||||
output := influxdb.InfluxDB{
|
||||
|
||||
@@ -136,3 +136,6 @@ func scanLines(data []byte, atEOF bool) (advance int, token []byte, err error) {
|
||||
}
|
||||
return 0, nil, nil
|
||||
}
|
||||
|
||||
func (c *udpClient) Close() {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user