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

promtail: Add support for exclusion patterns in static_config #5943

Merged
merged 7 commits into from
May 2, 2022

Conversation

tpaschalis
Copy link
Member

@tpaschalis tpaschalis commented Apr 18, 2022

Signed-off-by: Paschalis Tsilias [email protected]

What this PR does / why we need it:
As stated in the linked Issue, there's currently no easy way to exclude files from a Promtail config, except for overly restrictive and/or complex glob patterns.

This addition may be helpful in a number of scenarios, from avoiding usage spikes in Grafana cloud, to having separate pipeline_stages for specific file formats, or filtering directories which Promtail couldn't tail due to permissions.

Since the upstream bmatcuk/doublestar package doesn't support negation patterns, this is another way of achieving the same result.

Which issue(s) this PR fixes:
Fixes #5744

Special notes for your reviewer:
From my local tests, this seems to work as intended both in scrape_config and file_sd_config blocks; let me know if I've missed anything ^^

Checklist

  • Documentation added
  • Tests updated
  • Add an entry in the CHANGELOG.md about the changes.

@tpaschalis tpaschalis marked this pull request as ready for review April 18, 2022 10:02
@tpaschalis tpaschalis requested review from KMiller-Grafana and a team as code owners April 18, 2022 10:02
if fi, err := os.Stat(t.pathExclude); err == nil && !fi.IsDir() {
matchesExcluded = []string{t.pathExclude}
} else {
matchesExcluded, err = doublestar.Glob(t.pathExclude)
Copy link
Member Author

@tpaschalis tpaschalis Apr 18, 2022

Choose a reason for hiding this comment

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

If t.pathExclude is empty, then doublestar.Glob returns nil, nil, just skipping the loop below.

Signed-off-by: Paschalis Tsilias <[email protected]>
Signed-off-by: Paschalis Tsilias <[email protected]>
Signed-off-by: Paschalis Tsilias <[email protected]>
This reverts commit 17abb006ce141071c4bca4b7d133bea2aa314594.
Copy link
Contributor

@cyriltovena cyriltovena left a comment

Choose a reason for hiding this comment

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

LGTM

@cyriltovena cyriltovena merged commit 179d741 into grafana:main May 2, 2022
@tpaschalis tpaschalis deleted the add-promtail-exclusion branch May 2, 2022 11:01
@adam0s9
Copy link

adam0s9 commented Jun 26, 2023

is it please possible to make it exclude two files resp. two different logfiles with no common root (how about 3)?

@tpaschalis
Copy link
Member Author

@adam0s9 hey there 👋

Right now this is not possible with the static_configs targets. The workaround is to define more multiple, more fine-grained targets in your scrape configuration to handle nested directories.

If you'd like to propose an enhancement to the way __path_exclude__ works, I'd recommend opening a new issue to start the conversation from scratch and get more eyes on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow exclusion patterns on Promtail's static_config
3 participants