-
Notifications
You must be signed in to change notification settings - Fork 2.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
[exporter/prometheus] fix: validate metric types and help/descriptions #36356
[exporter/prometheus] fix: validate metric types and help/descriptions #36356
Conversation
8ad2967
to
94be2f5
Compare
94be2f5
to
c7af22a
Compare
a3e03fa
to
544dc23
Compare
544dc23
to
a540704
Compare
c.metricFamilies.Range(func(key, value any) bool { | ||
v := value.(metricFamily) | ||
if expirationTime.After(v.lastSeen) { | ||
c.logger.Debug(fmt.Sprintf("metric expired: %s", key)) |
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.
any way to avoid calling fmt.Sprintf here
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.
fixed!
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.
thanks @kristinapathak
Co-authored-by: Alex Boten <[email protected]>
@@ -403,4 +428,50 @@ func (c *collector) Collect(ch chan<- prometheus.Metric) { | |||
ch <- m | |||
c.logger.Debug(fmt.Sprintf("metric served: %s", m.Desc().String())) |
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.
Doesn't need to be in this PR but as a followup would be good to clean up this sprintf as well
Description
Fixes bug where exporting fails due to different help messages for the same metric. With this solution, the exporter will always export metrics of the same name with the first description it receives. This also rejects metrics whose types have changed. These changes follow the spec:
Based on open-telemetry/opentelemetry-go#3469
Link to tracking issue
Fixes #28617
Testing
Unit test cases added.