Skip to content
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

loki.source.docker: deduplicate matching container IDs #6055

Merged
merged 9 commits into from
Jan 10, 2024

Conversation

tpaschalis
Copy link
Member

@tpaschalis tpaschalis commented Jan 5, 2024

PR Description

The discovery.docker component was initially built with Prometheus service discovery in mind; this means that it will report a different target for each port, network and network interface that a container exposes/belongs to, so that it can be scraped accordingly.

This means, that when discovery.docker is used as an input to loki.source.docker, it will set up unnecessary load on the Docker API by trying to fetch logs for the same container ID multiple times. This PR makes it so that during a component Update, the targets are deduplicated based on the container ID, keeping only the first one.

Which issue(s) this PR fixes

Related to: #4403

I'd like to gather some more evidence until we say this fixes #4403 outright, so keeping this PR in draft in the meantime.

Notes to the Reviewer

I've run a simplistic benchmark with a chatty container that exposes two ports, and as expected, the CPU time spent on reading logs is ~half here.
image

PR Checklist

  • CHANGELOG.md updated
  • Documentation added
  • Tests updated

Signed-off-by: Paschalis Tsilias <[email protected]>
Signed-off-by: Paschalis Tsilias <[email protected]>
Signed-off-by: Paschalis Tsilias <[email protected]>
@tpaschalis tpaschalis force-pushed the loki-source-docker-unique-targets branch from 6624847 to 7348a5c Compare January 5, 2024 16:35
Signed-off-by: Paschalis Tsilias <[email protected]>
Copy link
Member

@rfratto rfratto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ultimately I think this makes sense, but I think we need to document it, since it might be surprising if you effectively input three targets (with the same ID) into loki.source.docker but the debug info only shows one.

@rfratto rfratto self-assigned this Jan 5, 2024
@tpaschalis tpaschalis marked this pull request as ready for review January 8, 2024 10:10
Signed-off-by: Paschalis Tsilias <[email protected]>
Signed-off-by: Paschalis Tsilias <[email protected]>
Signed-off-by: Paschalis Tsilias <[email protected]>
@tpaschalis
Copy link
Member Author

I think we need to document it, since it might be surprising if you effectively input three targets (with the same ID) into loki.source.docker but the debug info only shows one.

I've added a paragraph to document this new behavior, hopefully it clears things up.

Copy link
Member

@rfratto rfratto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but the docs change should get a review by @clayton-cornell

Copy link
Contributor

@clayton-cornell clayton-cornell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor changes to the doc input

@tpaschalis tpaschalis merged commit ab2be32 into grafana:main Jan 10, 2024
10 checks passed
@clayton-cornell clayton-cornell added the type/docs Docs Squad label across all Grafana Labs repos label Jan 10, 2024
BarunKGP pushed a commit to BarunKGP/grafana-agent that referenced this pull request Feb 20, 2024
@github-actions github-actions bot added the frozen-due-to-age Locked due to a period of inactivity. Please open new issues or PRs if more discussion is needed. label Feb 21, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
frozen-due-to-age Locked due to a period of inactivity. Please open new issues or PRs if more discussion is needed. type/docs Docs Squad label across all Grafana Labs repos
Projects
None yet
Development

Successfully merging this pull request may close these issues.

loki.source.docker error: could not set up a wait request to the Docker client
3 participants