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

[exporter/prometheus] fix: validate metric types and help/descriptions #36356

Merged

Conversation

kristinapathak
Copy link
Contributor

@kristinapathak kristinapathak commented Nov 13, 2024

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:

Exporters MUST drop entire metrics to prevent conflicting TYPE comments, but SHOULD NOT drop metric points as a result of conflicting UNIT or HELP comments. Instead, all but one of the conflicting UNIT and HELP comments (but not metric points) SHOULD be dropped. If dropping a comment or metric points, the exporter SHOULD warn the user through error logging.

Based on open-telemetry/opentelemetry-go#3469

Link to tracking issue

Fixes #28617

Testing

Unit test cases added.

@kristinapathak kristinapathak changed the title prometheus exporter: validate metric types and help/descriptions [exporter/prometheus] fix: validate metric types and help/descriptions Nov 13, 2024
@dashpole dashpole added the ready to merge Code review completed; ready to merge by maintainers label Nov 14, 2024
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))
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed!

Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -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()))
Copy link
Contributor

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

@codeboten codeboten merged commit ade3e4b into open-telemetry:main Nov 18, 2024
157 of 158 checks passed
@github-actions github-actions bot added this to the next release milestone Nov 18, 2024
@kristinapathak kristinapathak deleted the prometheus-metric-types-help branch November 18, 2024 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exporter/prometheus ready to merge Code review completed; ready to merge by maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prometheus exporter should allow conflicting help and unit metadata
6 participants