Skip to content

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

Merged
dmathieu merged 6 commits intoopen-telemetry:mainfrom
highlyavailable:fix/prometheus-exponential-histogram-scale-validation-clean
Jun 16, 2025
Merged

prometheus: validate exponential histogram scale range (#6779)#6822
dmathieu merged 6 commits intoopen-telemetry:mainfrom
highlyavailable:fix/prometheus-exponential-histogram-scale-validation-clean

Conversation

@highlyavailable
Copy link
Copy Markdown
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
Copy Markdown
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
Comment thread CHANGELOG.md Outdated
Comment thread exporters/prometheus/exporter.go
@highlyavailable highlyavailable force-pushed the fix/prometheus-exponential-histogram-scale-validation-clean branch from 4c1e41b to 95c4664 Compare May 30, 2025 03:22
@codecov
Copy link
Copy Markdown

codecov Bot commented May 30, 2025

Codecov Report

Attention: Patch coverage is 90.32258% with 6 lines in your changes missing coverage. Please review.

Project coverage is 82.3%. Comparing base (f2058fa) to head (76a9ca2).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
exporters/prometheus/exporter.go 90.3% 5 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #6822   +/-   ##
=====================================
  Coverage   82.3%   82.3%           
=====================================
  Files        263     263           
  Lines      24420   24476   +56     
=====================================
+ Hits       20101   20151   +50     
- Misses      3937    3942    +5     
- Partials     382     383    +1     
Files with missing lines Coverage Δ
exporters/prometheus/exporter.go 82.3% <90.3%> (+1.5%) ⬆️

... and 3 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
Copy Markdown
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

Comment thread exporters/prometheus/exporter.go Outdated
Removed unnecessary logic for trimming leading and trailing zeros in the downscaleExponentialBucket function.
@pellared pellared requested review from MrAlias and dashpole June 9, 2025 08:57
Comment thread exporters/prometheus/exporter_test.go Outdated
@pellared pellared modified the milestones: v1.37.0, Subsequent v1.37.0 Jun 12, 2025
@highlyavailable
Copy link
Copy Markdown
Contributor Author

It looks like one of the ci compatibility checks is now failing,

ci / compatibility-test (1.23.0, macos-13, amd64) (pull_request) Failing after 1m

Would it be possible to rerun and see if the test fails? Additionally, it looks like the markdown lint check is failing on the CHANGELOG.md format, is this fine?

CHANGELOG.md:46 MD024/no-duplicate-heading/no-duplicate-header Multiple headings with the same content [Context: "### Fixed"]

Comment thread CHANGELOG.md
@dashpole
Copy link
Copy Markdown
Contributor

Fixed your changelog

@dashpole
Copy link
Copy Markdown
Contributor

@open-telemetry/go-approvers This is needs one more review, and then is ready to go

@dmathieu dmathieu merged commit cba6502 into open-telemetry:main Jun 16, 2025
32 checks passed
pellared added a commit that referenced this pull request Jun 25, 2025
### Added

- The `go.opentelemetry.io/otel/semconv/v1.33.0` package.
The package contains semantic conventions from the `v1.33.0` version of
the OpenTelemetry Semantic Conventions.
See the [migration documentation](./semconv/v1.33.0/MIGRATION.md) for
information on how to upgrade from
`go.opentelemetry.io/otel/semconv/v1.32.0.`(#6799)
- The `go.opentelemetry.io/otel/semconv/v1.34.0` package.
The package contains semantic conventions from the `v1.34.0` version of
the OpenTelemetry Semantic Conventions. (#6812)
- Add metric's schema URL as `otel_scope_schema_url` label in
`go.opentelemetry.io/otel/exporters/prometheus`. (#5947)
- Add metric's scope attributes as `otel_scope_[attribute]` labels in
`go.opentelemetry.io/otel/exporters/prometheus`. (#5947)
- Add `EventName` to `EnabledParameters` in
`go.opentelemetry.io/otel/log`. (#6825)
- Add `EventName` to `EnabledParameters` in
`go.opentelemetry.io/otel/sdk/log`. (#6825)
- Changed handling of `go.opentelemetry.io/otel/exporters/prometheus`
metric renaming to add unit suffixes when it doesn't match one of the
pre-defined values in the unit suffix map. (#6839)

### Changed

- The semantic conventions have been upgraded from `v1.26.0` to
`v1.34.0` in `go.opentelemetry.io/otel/bridge/opentracing`. (#6827)
- The semantic conventions have been upgraded from `v1.26.0` to
`v1.34.0` in `go.opentelemetry.io/otel/exporters/zipkin`. (#6829)
- The semantic conventions have been upgraded from `v1.26.0` to
`v1.34.0` in `go.opentelemetry.io/otel/metric`. (#6832)
- The semantic conventions have been upgraded from `v1.26.0` to
`v1.34.0` in `go.opentelemetry.io/otel/sdk/resource`. (#6834)
- The semantic conventions have been upgraded from `v1.26.0` to
`v1.34.0` in `go.opentelemetry.io/otel/sdk/trace`. (#6835)
- The semantic conventions have been upgraded from `v1.26.0` to
`v1.34.0` in `go.opentelemetry.io/otel/trace`. (#6836)
- `Record.Resource` now returns `*resource.Resource` instead of
`resource.Resource` in `go.opentelemetry.io/otel/sdk/log`. (#6864)
- Retry now shows error cause for context timeout in
`go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc`,
`go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc`,
`go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc`,
`go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp`,
`go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`,
`go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp`. (#6898)

### Fixed

- Stop stripping trailing slashes from configured endpoint URL in
`go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc`.
(#6710)
- Stop stripping trailing slashes from configured endpoint URL in
`go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp`.
(#6710)
- Stop stripping trailing slashes from configured endpoint URL in
`go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc`.
(#6710)
- Stop stripping trailing slashes from configured endpoint URL in
`go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`.
(#6710)
- Validate exponential histogram scale range for Prometheus
compatibility in `go.opentelemetry.io/otel/exporters/prometheus`.
(#6822)
- Context cancellation during metric pipeline produce does not corrupt
data in `go.opentelemetry.io/otel/sdk/metric`. (#6914)

### Removed

- `go.opentelemetry.io/otel/exporters/prometheus` no longer exports
`otel_scope_info` metric. (#6770)
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

5 participants