inputs.docker_log: broken against daemons with API version below 1.40 since the moby client migration
Relevant telegraf.conf
[[inputs.docker_log]]
endpoint = "unix:///var/run/docker.sock"Logs from Telegraf
E! [inputs.docker_log] Error in plugin: listing containers failed: request returned 404 Not Found for API route and version http://.../v1.56/containers/json, check if the server supports the requested API versionThe version in the path is the client library's MaxAPIVersion, so it reads 1.55 on 1.39.x and 1.56 on 1.40.x. Against a real daemon the message is instead Error response from daemon: client version 1.56 is too new. Maximum supported API version is 1.39; the 404 above is what the repro below produces.
System info
Telegraf 1.39.1 through 1.40.1 (also reproduces on master @ 7bd3f120c); any Docker Engine whose maximum API version is below 1.40, e.g. 18.09 (API 1.39)
Steps to reproduce
- Run a Docker daemon that advertises an API version below
client.MinAPIVersion(1.40), e.g. Docker Engine 18.09. - Configure
[[inputs.docker_log]]pointing at its socket. - Start Telegraf and wait for the first gather.
No old daemon is needed. With the mock server sending the Api-Version header the client actually reads, setting APIVersion: "1.39" on a mock.Server in plugins/inputs/docker_log reproduces it:
server.go: unhandled url: "/v1.56/containers/json"
listing containers failed: request returned 404 Not Found for API route and version .../v1.56/containers/jsonExpected behavior
The client downgrades to the API version the daemon advertises and container logs are collected, as it did up to 1.39.0.
Actual behavior
Every request goes out at client.MaxAPIVersion and the daemon rejects it, so ContainerList fails on every gather and no logs are ever collected. Unlike inputs.docker the agent keeps running, since this surfaces as a gather error rather than a startup error.
Additional info
Same root cause as #19789, in the sibling plugin. Introduced by #18879, which moved both plugins from github.com/docker/docker/client to github.com/moby/moby/client. The old client was created with WithAPIVersionNegotiation() and its negotiation had no lower bound; the new library refuses to negotiate below client.MinAPIVersion (1.40) and getAPIPath discards the resulting error, leaving the client at its own maximum:
const MaxAPIVersion = "1.56"
const MinAPIVersion = "1.40"
if versions.LessThan(pingVersion, MinAPIVersion) {
return cerrdefs.ErrInvalidArgument.WithMessage(...)
}_ = cli.checkVersion(ctx)inputs.docker_log differs from inputs.docker in two ways that matter for a fix: it builds its client in Init rather than Start, and it never pings, so the first contact with the daemon is ContainerList during Gather.
I have a fix working locally with tests and will open a PR.
Source: influxdata/telegraf