Skip to content

Commit

Permalink
merge telegraf issue-9243
Browse files Browse the repository at this point in the history
  • Loading branch information
arstercz committed Mar 5, 2023
1 parent 4316127 commit 46201a0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
4 changes: 4 additions & 0 deletions plugins/inputs/docker/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Client interface {
ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error)
TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error)
NodeList(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error)
Close() error
}

func NewEnvClient() (Client, error) {
Expand Down Expand Up @@ -76,3 +77,6 @@ func (c *SocketClient) TaskList(ctx context.Context, options types.TaskListOptio
func (c *SocketClient) NodeList(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error) {
return c.client.NodeList(ctx, options)
}
func (c *SocketClient) Close() error {
return c.client.Close()
}
9 changes: 6 additions & 3 deletions plugins/inputs/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ var sampleConfig = `
## Whether to report for each container per-device blkio (8:0, 8:1...),
## network (eth0, eth1, ...) and cpu (cpu0, cpu1, ...) stats or not.
## Usage of this setting is discouraged since it will be deprecated in favor of 'perdevice_include'.
## Default value is 'true' for backwards compatibility, please set it to 'false' so that 'perdevice_include' setting
## Default value is 'true' for backwards compatibility, please set it to 'false' so that 'perdevice_include' setting
## is honored.
perdevice = true
Expand All @@ -136,12 +136,12 @@ var sampleConfig = `
## Whether to report for each container total blkio and network stats or not.
## Usage of this setting is discouraged since it will be deprecated in favor of 'total_include'.
## Default value is 'false' for backwards compatibility, please set it to 'true' so that 'total_include' setting
## Default value is 'false' for backwards compatibility, please set it to 'true' so that 'total_include' setting
## is honored.
total = false
## Specifies for which classes a total metric should be issued. Total is an aggregated of the 'perdevice' values.
## Possible values are 'cpu', 'blkio' and 'network'
## Possible values are 'cpu', 'blkio' and 'network'
## Total 'cpu' is reported directly by Docker daemon, and 'network' and 'blkio' totals are aggregated by this plugin.
## Please note that this setting has no effect if 'total' is set to 'false'
# total_include = ["cpu", "blkio", "network"]
Expand Down Expand Up @@ -215,6 +215,9 @@ func (d *Docker) Gather(acc telegraf.Accumulator) error {
d.client = c
}

// Close any idle connections in the end of gathering
defer d.client.Close()

// Create label filters if not already created
if !d.filtersCreated {
err := d.createLabelFilters()
Expand Down
11 changes: 11 additions & 0 deletions plugins/inputs/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type MockClient struct {
ServiceListF func(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error)
TaskListF func(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error)
NodeListF func(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error)
CloseF func() error
}

func (c *MockClient) Info(ctx context.Context) (types.Info, error) {
Expand Down Expand Up @@ -75,6 +76,10 @@ func (c *MockClient) NodeList(
return c.NodeListF(ctx, options)
}

func (c *MockClient) Close() error {
return c.CloseF()
}

var baseClient = MockClient{
InfoF: func(context.Context) (types.Info, error) {
return info, nil
Expand All @@ -97,6 +102,9 @@ var baseClient = MockClient{
NodeListF: func(context.Context, types.NodeListOptions) ([]swarm.Node, error) {
return NodeList, nil
},
CloseF: func() error {
return nil
}
}

func newClient(host string, tlsConfig *tls.Config) (Client, error) {
Expand Down Expand Up @@ -269,6 +277,9 @@ func TestDocker_WindowsMemoryContainerStats(t *testing.T) {
NodeListF: func(context.Context, types.NodeListOptions) ([]swarm.Node, error) {
return NodeList, nil
},
CloseF: func() error {
return nil
},
}, nil
},
}
Expand Down

0 comments on commit 46201a0

Please sign in to comment.