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

Fix target_info labels #2546

Merged
merged 13 commits into from Jun 13, 2023
Merged

Fix target_info labels #2546

merged 13 commits into from Jun 13, 2023

Conversation

ie-pham
Copy link
Collaborator

@ie-pham ie-pham commented Jun 8, 2023

What this PR does: The labels variable in the gauge & counter collectMetrics function was created outside the for loop and so we were constantly adding labels to metrics after metrics.

Which issue(s) this PR fixes:
Fixes #

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@ie-pham ie-pham marked this pull request as ready for review June 8, 2023 16:37
for _, s := range g.series {
t := time.UnixMilli(timeMs)
lbls := make(labels.Labels, 1+len(externalLabels)+len(s.labels.names))
Copy link
Contributor

Choose a reason for hiding this comment

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

We might want to keep the allocations outside of the loop. I think I saw a Reset() method on the lb object that might empty this out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good call

@ie-pham
Copy link
Collaborator Author

ie-pham commented Jun 8, 2023

Tested in dev, there are now only 2 metrics instead of 10+ (2 because there are two m-gen instance)
Screenshot 2023-06-08 at 12 33 57 PM

Copy link

@calebamiles calebamiles left a comment

Choose a reason for hiding this comment

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

🚀

Copy link
Member

@mapno mapno left a comment

Choose a reason for hiding this comment

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

I think it's missing a test to ensure the bug is fixed. Otherwise, LGTM

@ie-pham
Copy link
Collaborator Author

ie-pham commented Jun 9, 2023

added test and made sure they failed before the fix and passed after the fix

@ie-pham ie-pham enabled auto-merge (squash) June 9, 2023 19:34
@ie-pham ie-pham requested a review from mapno June 9, 2023 19:34
Copy link
Member

@mapno mapno left a comment

Choose a reason for hiding this comment

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

LGMT, nice fix

@ie-pham ie-pham merged commit 9ceac67 into grafana:main Jun 13, 2023
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants