-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use consistent container name in docker input plugin #8703
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤝 ✅ CLA has been signed. Thank you!
a18fe94
to
3cf7c65
Compare
@danielnelson I'd really appreciate a review of this if you have the time! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
@jagularr Any other blockers to getting this merged? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks also good to me.
@@ -434,7 +434,7 @@ func (d *Docker) gatherContainer( | |||
var cname string | |||
for _, name := range container.Names { | |||
trimmedName := strings.TrimPrefix(name, "/") | |||
if len(strings.Split(trimmedName, "/")) == 1 { | |||
if !strings.Contains(trimmedName, "/") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about /name/
should that match? Maybe it would be better to trim both leading and trailing slashed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you can get a name like that.
I'd prefer to keep this implementation as similar as possible to the Docker CLI implementation. I imagine that users expect the implementation of the name filter to be consistent with the output of docker ps
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok than that's fine with me.
Required for all PRs:
Before this PR
I have noticed that the docker input plugin occasionally gathers metrics for containers with a container name that does not match the configured filter. For example, I have a container named
influxdb
and have configured the docker input plugin withcontainer_name_include = ["influxdb"]
, but the docker input plugin sometimes produces metrics with acontainer_name
tag of something like689a5b5f3679_influxdb
.Upon further investigation, I discovered that this happens when the metrics are gathered while docker-compose is recreating the container. When docker-compose recreates the container, it temporarily renames the original container to
{id}_{name}
before removing it.The docker input plugin uses the name from the
ListContainer
call when checking the filter, but uses the name from theContainerStats
call when setting thecontainer_name
tag. If the container is renamed between these calls, it will result in the confusing behavior described above.After this PR
The docker input plugin uses the name from the
ListContainer
call both when checking the filter and when setting thecontainer_name
tag.Because we want the
container_name
tag to be the canonical container name, this PR removes support for matching based on all container names and now only matches on the default container name. Other container names come from links (see moby/moby#14128), which is a legacy feature that has been deprecated for a while. See https://docs.docker.com/network/links/.This implementation now matches the behavior of
docker ps
(when used without--no-trunc
). You can see the current implementation here:https://github.com/docker/cli/blob/cde469bf1aad14146d57710205399899e465aadc/cli/command/formatter/container.go#L124-L138
This behavior in the docker CLI was first introduced over 5 years ago in moby/moby#8505.
I can't think of a good reason to allow matching on names from links, especially given that they are deprecated, so it seemed reasonable to make this change.