Skip to content

prometheus: validate exponential histogram scale range (#6779) #6822

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

highlyavailable
Copy link
Contributor

Fixes #6779

Changes

  • Added scale validation for Prometheus exponential histograms in addExponentialHistogramMetric
  • Rejects scales below -4 (logs error and skips data point)
  • Clamps scales above 8 down to 8 (logs warning)
  • Prometheus native histograms support scales in range [-4, 8]

Testing

  • All existing tests pass
  • Added TestExponentialHistogramScaleValidation to verify error handling doesn't break normal operation

@highlyavailable highlyavailable force-pushed the fix/prometheus-exponential-histogram-scale-validation-clean branch from 6f10f59 to 4c1e41b Compare May 24, 2025 23:48
@MrAlias
Copy link
Contributor

MrAlias commented May 26, 2025

cc @dashpole

@MrAlias MrAlias added the pkg:exporter:prometheus Related to the Prometheus exporter package label May 26, 2025
@MrAlias MrAlias added this to the v1.37.0 milestone May 26, 2025
@highlyavailable highlyavailable force-pushed the fix/prometheus-exponential-histogram-scale-validation-clean branch from 4c1e41b to 95c4664 Compare May 30, 2025 03:22
Copy link

codecov bot commented May 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.4%. Comparing base (dc210e9) to head (f6be0b5).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #6822     +/-   ##
=======================================
+ Coverage   82.3%   82.4%   +0.1%     
=======================================
  Files        263     263             
  Lines      24416   24472     +56     
=======================================
+ Hits       20095   20184     +89     
+ Misses      3939    3908     -31     
+ Partials     382     380      -2     
Files with missing lines Coverage Δ
exporters/prometheus/exporter.go 90.7% <100.0%> (+10.1%) ⬆️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@highlyavailable highlyavailable force-pushed the fix/prometheus-exponential-histogram-scale-validation-clean branch from 332fca7 to e058c03 Compare May 30, 2025 11:16
Fixes open-telemetry#6779

Add scale validation for Prometheus exponential histograms to ensure
compatibility with Prometheus native histogram format.

Changes:
- Validate scale is within Prometheus supported range [-4, 8]
- Reject scales below -4 (log error and skip data point)
- Downscale histograms with scale > 8 by re-aggregating buckets
- Add comprehensive test coverage for scale validation and downscaling
- Implement downscaling logic based on OpenTelemetry Collector Contrib

The downscaling implementation merges buckets using bit-shifting to
maintain accuracy while conforming to Prometheus limitations.
@highlyavailable highlyavailable force-pushed the fix/prometheus-exponential-histogram-scale-validation-clean branch from e058c03 to 764b9f2 Compare May 30, 2025 11:47
@highlyavailable
Copy link
Contributor Author

Hey @MrAlias, I updated my PR based on your feedback. Now there is only 1 new commit, and its passing test cases. Let me know if there are any issues with the change, and thanks for the initial feedback

Removed unnecessary logic for trimming leading and trailing zeros in the downscaleExponentialBucket function.
@pellared pellared requested review from dashpole and MrAlias June 9, 2025 08:57
})
}

func TestGaugeMetrics(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I see a couple of unrelated tests added here. Are you just trying to increase test coverage, or were these mistakenly copied from somewhere else?

Copy link
Member

Choose a reason for hiding this comment

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

@highlyavailable, can you please respond?

@pellared pellared modified the milestones: v1.37.0, Subsequent v1.37.0 Jun 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:exporter:prometheus Related to the Prometheus exporter package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prometheus exponential histogram validate scale range
4 participants