Skip to content

Fix target_info labels#2546

Merged
ie-pham merged 13 commits intografana:mainfrom
ie-pham:jp/fix_gauge
Jun 13, 2023
Merged

Fix target_info labels#2546
ie-pham merged 13 commits intografana:mainfrom
ie-pham:jp/fix_gauge

Conversation

@ie-pham
Copy link
Copy Markdown
Contributor

@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
Comment thread modules/generator/registry/gauge.go Outdated

for _, s := range g.series {
t := time.UnixMilli(timeMs)
lbls := make(labels.Labels, 1+len(externalLabels)+len(s.labels.names))
Copy link
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
Contributor 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
Copy Markdown

@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
Copy Markdown
Contributor

@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
Copy Markdown
Contributor 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
Copy Markdown
Contributor

@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
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.

4 participants