-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
fix(1693): allow job label to be rewritten in prometheus receiver #3347
Conversation
|
Could this be extended to support internal labels as well, such as |
@dashpole, I think issue #2297 is best treated as a separate issue. The lookup piece in this PR doesn't have any context of name and other hidden labels (that I'm aware of). I.e. if I attempt to log |
for _, target := range targetGroup { | ||
switch { | ||
case target.Labels().Get(model.InstanceLabel) == instance && originalJobLabel == job: | ||
// job label was not rewritten |
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.
Since this will be the common case, can we handle it with the previous direct lookup method and fall back to the iterative search only if it isn't found?
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.
Totally - I'll take a look at refactoring to apply this optimization
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.
for _, target := range targetGroup { | ||
if target.Labels().Get(model.InstanceLabel) == instance { | ||
return &mCache{target}, nil | ||
for originalJobLabel, targetGroup := range s.sm.TargetsAll() { |
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.
Keep targetGroup, ok := s.sm.TargetsAll()[job]
here and fallback to the new loop if it's not found.
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.
Ah, just realized @dashpole already left the same feedback.
This PR was marked stale due to lack of activity. It will be closed in 7 days. |
@Aneurysm9 please take a look, when you get a chance. |
…ry-collector into job-relabel-1693
This PR was marked stale due to lack of activity. It will be closed in 7 days. |
Closed as inactive. Feel free to reopen if this PR is still being worked on. |
Description:
Bugfix - allow job label to be rewritten in prometheus receiver via
file_sd_configs
andrelabel_configs
When the 'job' label is added to the metadata of file discovery targets (see json below) or is rewritten with a
relabel_configs
block, the metadata service was failing to look up the target by job because the map of targets was only able to be indexed by the 'original' job name, not the rewritten job name.This PR solves this issue by iterating through all targets when looking up metadata rather than indexing the job map directly. This lookup operation is done once per scrape per target, so the iteration will take longer given a large number of targets.
Resolves #1693
Testing:
transaction_test.go
Manual testing:
Setup similar to the bug report in #1693
// examples/local/targets.json
// examples/local/otel-config.yaml
Run the collector
Confirmed no longer throwing errors of type
unable to find a target group with job=x"
and confirmed that thejob
label is properly exposed asjob="pushgateway"
at http://localhost:1234/metrics