Skip to content

Commit 3728dbd

Browse files
committed
Fixed docker depedency issue
1 parent bdfad70 commit 3728dbd

File tree

7 files changed

+191
-181
lines changed

7 files changed

+191
-181
lines changed

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ module github.com/influxdata/telegraf
22

33
go 1.22.0
44

5-
65
require (
76
collectd.org v0.6.0
87
github.com/99designs/keyring v1.2.2
@@ -34,7 +33,7 @@ require (
3433
github.com/coreos/go-systemd/v22 v22.5.0
3534
github.com/couchbase/go-couchbase v0.1.1
3635
github.com/dimchansky/utfbom v1.1.1
37-
github.com/docker/docker v27.1.1+incompatible
36+
github.com/docker/docker v28.0.4+incompatible
3837
github.com/docker/go-connections v0.5.0
3938
github.com/eclipse/paho.golang v0.21.0
4039
github.com/eclipse/paho.mqtt.golang v1.4.3
@@ -118,6 +117,7 @@ require (
118117
dario.cat/mergo v1.0.0 // indirect
119118
filippo.io/edwards25519 v1.1.0 // indirect
120119
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
120+
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
121121
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
122122
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
123123
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
@@ -146,7 +146,6 @@ require (
146146
github.com/bufbuild/protocompile v0.10.0 // indirect
147147
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
148148
github.com/cespare/xxhash/v2 v2.3.0 // indirect
149-
github.com/containerd/containerd v1.7.18 // indirect
150149
github.com/containerd/log v0.1.0 // indirect
151150
github.com/containerd/platforms v0.2.1 // indirect
152151
github.com/couchbase/gomemcached v0.1.3 // indirect
@@ -226,6 +225,7 @@ require (
226225
github.com/moby/patternmatcher v0.6.0 // indirect
227226
github.com/moby/sys/sequential v0.5.0 // indirect
228227
github.com/moby/sys/user v0.1.0 // indirect
228+
github.com/moby/sys/userns v0.1.0 // indirect
229229
github.com/moby/term v0.5.0 // indirect
230230
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
231231
github.com/modern-go/reflect2 v1.0.2 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,6 @@ github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I
172172
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
173173
github.com/compose-spec/compose-go v1.20.2 h1:u/yfZHn4EaHGdidrZycWpxXgFffjYULlTbRfJ51ykjQ=
174174
github.com/compose-spec/compose-go v1.20.2/go.mod h1:+MdqXV4RA7wdFsahh/Kb8U0pAJqkg7mr4PM9tFKU8RM=
175-
github.com/containerd/containerd v1.7.18 h1:jqjZTQNfXGoEaZdW1WwPU0RqSn1Bm2Ay/KJPUuO8nao=
176-
github.com/containerd/containerd v1.7.18/go.mod h1:IYEk9/IO6wAPUz2bCMVUbsfXjzw5UNP5fLz4PsUygQ4=
177175
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
178176
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
179177
github.com/containerd/platforms v0.2.1 h1:zvwtM3rz2YHPQsF2CHYM8+KtB5dvhISiXh5ZpSBQv6A=
@@ -210,8 +208,8 @@ github.com/dimchansky/utfbom v1.1.1 h1:vV6w1AhK4VMnhBno/TPVCoK9U/LP0PkLCS9tbxHdi
210208
github.com/dimchansky/utfbom v1.1.1/go.mod h1:SxdoEBH5qIqFocHMyGOXVAybYJdr71b1Q/j0mACtrfE=
211209
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
212210
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
213-
github.com/docker/docker v27.1.1+incompatible h1:hO/M4MtV36kzKldqnA37IWhebRA+LnqqcqDja6kVaKY=
214-
github.com/docker/docker v27.1.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
211+
github.com/docker/docker v28.0.4+incompatible h1:JNNkBctYKurkw6FrHfKqY0nKIDf5nrbxjVBtS+cdcok=
212+
github.com/docker/docker v28.0.4+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
215213
github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c=
216214
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
217215
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
@@ -618,6 +616,8 @@ github.com/moby/sys/sequential v0.5.0 h1:OPvI35Lzn9K04PBbCLW0g4LcFAJgHsvXsRyewg5
618616
github.com/moby/sys/sequential v0.5.0/go.mod h1:tH2cOOs5V9MlPiXcQzRC+eEyab644PWKGRYaaV5ZZlo=
619617
github.com/moby/sys/user v0.1.0 h1:WmZ93f5Ux6het5iituh9x2zAG7NFY9Aqi49jjE1PaQg=
620618
github.com/moby/sys/user v0.1.0/go.mod h1:fKJhFOnsCN6xZ5gSfbM6zaHGgDJMrqt9/reuj4T7MmU=
619+
github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g=
620+
github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28=
621621
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
622622
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
623623
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=

plugins/inputs/docker/stats_helpers.go renamed to plugins/common/docker/stats_helpers.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
// https://github.com/docker/cli/blob/master/cli/command/container/stats_helpers.go
33
package docker
44

5-
import "github.com/docker/docker/api/types"
5+
import (
6+
"github.com/docker/docker/api/types/container"
7+
)
68

7-
func CalculateCPUPercentUnix(previousCPU, previousSystem uint64, v *types.StatsJSON) float64 {
9+
// CalculateCPUPercentUnix calculate CPU usage (for Unix, in percentages)
10+
func CalculateCPUPercentUnix(previousCPU, previousSystem uint64, v *container.StatsResponse) float64 {
811
var (
912
cpuPercent = 0.0
1013
// calculate the change for the cpu usage of the container in between readings
@@ -23,7 +26,8 @@ func CalculateCPUPercentUnix(previousCPU, previousSystem uint64, v *types.StatsJ
2326
return cpuPercent
2427
}
2528

26-
func calculateCPUPercentWindows(v *types.StatsJSON) float64 {
29+
// CalculateCPUPercentWindows calculate CPU usage (for Windows, in percentages)
30+
func CalculateCPUPercentWindows(v *container.StatsResponse) float64 {
2731
// Max number of 100ns intervals between the previous time read and now
2832
possIntervals := uint64(v.Read.Sub(v.PreRead).Nanoseconds()) // Start with number of ns intervals
2933
possIntervals /= 100 // Convert to number of 100ns intervals
@@ -48,7 +52,7 @@ func calculateCPUPercentWindows(v *types.StatsJSON) float64 {
4852
//
4953
// This definition is designed to be consistent with past values and the latest docker CLI
5054
// * https://github.com/docker/cli/blob/6e2838e18645e06f3e4b6c5143898ccc44063e3b/cli/command/container/stats_helpers.go#L239
51-
func CalculateMemUsageUnixNoCache(mem types.MemoryStats) float64 {
55+
func CalculateMemUsageUnixNoCache(mem container.MemoryStats) float64 {
5256
// Docker 19.03 and older
5357
if v, isOldDocker := mem.Stats["cache"]; isOldDocker && v < mem.Usage {
5458
return float64(mem.Usage - v)
@@ -64,7 +68,8 @@ func CalculateMemUsageUnixNoCache(mem types.MemoryStats) float64 {
6468
return float64(mem.Usage)
6569
}
6670

67-
func CalculateMemPercentUnixNoCache(limit float64, usedNoCache float64) float64 {
71+
// CalculateMemPercentUnixNoCache calculate memory usage of the container, in percentages.
72+
func CalculateMemPercentUnixNoCache(limit, usedNoCache float64) float64 {
6873
// MemoryStats.Limit will never be 0 unless the container is not running and we haven't
6974
// got any data from cgroup
7075
if limit != 0 {

plugins/inputs/docker/client.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ import (
99
"github.com/docker/docker/api/types/container"
1010
"github.com/docker/docker/api/types/swarm"
1111
"github.com/docker/docker/api/types/system"
12-
dockerClient "github.com/docker/docker/client"
12+
"github.com/docker/docker/client"
1313
)
1414

1515
var (
1616
defaultHeaders = map[string]string{"User-Agent": "engine-api-cli-1.0"}
1717
)
1818

19-
type Client interface {
19+
type dockerClient interface {
2020
Info(ctx context.Context) (system.Info, error)
21-
ContainerList(ctx context.Context, options container.ListOptions) ([]types.Container, error)
22-
ContainerStats(ctx context.Context, containerID string, stream bool) (types.ContainerStats, error)
23-
ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error)
21+
ContainerList(ctx context.Context, options container.ListOptions) ([]container.Summary, error)
22+
ContainerStats(ctx context.Context, containerID string, stream bool) (container.StatsResponseReader, error)
23+
ContainerInspect(ctx context.Context, containerID string) (container.InspectResponse, error)
2424
ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error)
2525
TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error)
2626
NodeList(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error)
@@ -29,65 +29,65 @@ type Client interface {
2929
Close() error
3030
}
3131

32-
func NewEnvClient() (Client, error) {
33-
client, err := dockerClient.NewClientWithOpts(dockerClient.FromEnv)
32+
func newEnvClient() (dockerClient, error) {
33+
dockerClient, err := client.NewClientWithOpts(client.FromEnv)
3434
if err != nil {
3535
return nil, err
3636
}
37-
return &SocketClient{client}, nil
37+
return &socketClient{dockerClient}, nil
3838
}
3939

40-
func NewClient(host string, tlsConfig *tls.Config) (Client, error) {
40+
func newClient(host string, tlsConfig *tls.Config) (dockerClient, error) {
4141
transport := &http.Transport{
4242
TLSClientConfig: tlsConfig,
4343
}
4444
httpClient := &http.Client{Transport: transport}
4545

46-
client, err := dockerClient.NewClientWithOpts(
47-
dockerClient.WithHTTPHeaders(defaultHeaders),
48-
dockerClient.WithHTTPClient(httpClient),
49-
dockerClient.WithAPIVersionNegotiation(),
50-
dockerClient.WithHost(host))
46+
dockerClient, err := client.NewClientWithOpts(
47+
client.WithHTTPHeaders(defaultHeaders),
48+
client.WithHTTPClient(httpClient),
49+
client.WithAPIVersionNegotiation(),
50+
client.WithHost(host))
5151
if err != nil {
5252
return nil, err
5353
}
5454

55-
return &SocketClient{client}, nil
55+
return &socketClient{dockerClient}, nil
5656
}
5757

58-
type SocketClient struct {
59-
client *dockerClient.Client
58+
type socketClient struct {
59+
client *client.Client
6060
}
6161

62-
func (c *SocketClient) Info(ctx context.Context) (system.Info, error) {
62+
func (c *socketClient) Info(ctx context.Context) (system.Info, error) {
6363
return c.client.Info(ctx)
6464
}
65-
func (c *SocketClient) ContainerList(ctx context.Context, options container.ListOptions) ([]types.Container, error) {
65+
func (c *socketClient) ContainerList(ctx context.Context, options container.ListOptions) ([]container.Summary, error) {
6666
return c.client.ContainerList(ctx, options)
6767
}
68-
func (c *SocketClient) ContainerStats(ctx context.Context, containerID string, stream bool) (types.ContainerStats, error) {
68+
func (c *socketClient) ContainerStats(ctx context.Context, containerID string, stream bool) (container.StatsResponseReader, error) {
6969
return c.client.ContainerStats(ctx, containerID, stream)
7070
}
71-
func (c *SocketClient) ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error) {
71+
func (c *socketClient) ContainerInspect(ctx context.Context, containerID string) (container.InspectResponse, error) {
7272
return c.client.ContainerInspect(ctx, containerID)
7373
}
74-
func (c *SocketClient) ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error) {
74+
func (c *socketClient) ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error) {
7575
return c.client.ServiceList(ctx, options)
7676
}
77-
func (c *SocketClient) TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error) {
77+
func (c *socketClient) TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error) {
7878
return c.client.TaskList(ctx, options)
7979
}
80-
func (c *SocketClient) NodeList(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error) {
80+
func (c *socketClient) NodeList(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error) {
8181
return c.client.NodeList(ctx, options)
8282
}
83-
func (c *SocketClient) DiskUsage(ctx context.Context, options types.DiskUsageOptions) (types.DiskUsage, error) {
83+
func (c *socketClient) DiskUsage(ctx context.Context, options types.DiskUsageOptions) (types.DiskUsage, error) {
8484
return c.client.DiskUsage(ctx, options)
8585
}
8686

87-
func (c *SocketClient) ClientVersion() string {
87+
func (c *socketClient) ClientVersion() string {
8888
return c.client.ClientVersion()
8989
}
9090

91-
func (c *SocketClient) Close() error {
91+
func (c *socketClient) Close() error {
9292
return c.client.Close()
9393
}

0 commit comments

Comments
 (0)