Skip to content

feat: implement histogram and gauge histogram support for OpenMetrics 2.0 - #964

Draft
dashpole wants to merge 3 commits into
prometheus:mainfrom
dashpole:om2_histograms
Draft

feat: implement histogram and gauge histogram support for OpenMetrics 2.0#964
dashpole wants to merge 3 commits into
prometheus:mainfrom
dashpole:om2_histograms

Conversation

@dashpole

@dashpole dashpole commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Part 2 of #893

Implement serialization and strict validation for classic, native, dual, and gauge histograms in OpenMetrics 2.0 format according to the specification and ABNF grammar.

goos: linux
goarch: amd64
pkg: github.com/prometheus/common/expfmt
cpu: AMD EPYC 7B12
                                             │    sec/op     │     B/op      │   allocs/op   │
ConvertMetricFamily/TEXT/COUNTER-24              502.8n ± 2%      0.000 ± 0%     0.000 ± 0%
ConvertMetricFamily/OM1.0/COUNTER-24             1.211µ ± 4%      33.00 ± 0%     2.000 ± 0%
ConvertMetricFamily/OM2.0/COUNTER-24             1.100µ ± 5%      0.000 ± 0%     0.000 ± 0%
ConvertMetricFamily/TEXT/GAUGE-24                487.5n ± 5%      0.000 ± 0%     0.000 ± 0%
ConvertMetricFamily/OM1.0/GAUGE-24               735.8n ± 5%      1.000 ± 0%     1.000 ± 0%
ConvertMetricFamily/OM2.0/GAUGE-24               653.2n ± 3%      0.000 ± 0%     0.000 ± 0%
ConvertMetricFamily/TEXT/UNTYPED-24              428.9n ± 4%      0.000 ± 0%     0.000 ± 0%
ConvertMetricFamily/OM1.0/UNTYPED-24             599.5n ± 8%      1.000 ± 0%     1.000 ± 0%
ConvertMetricFamily/OM2.0/UNTYPED-24             573.3n ± 7%      0.000 ± 0%     0.000 ± 0%
ConvertMetricFamily/TEXT/SUMMARY-24              2.125µ ± 4%      56.00 ± 0%     2.000 ± 0%
ConvertMetricFamily/OM1.0/SUMMARY-24             2.745µ ± 7%      57.00 ± 0%     3.000 ± 0%
ConvertMetricFamily/TEXT/HISTOGRAM-24            4.298µ ± 7%      288.0 ± 0%     6.000 ± 0%
ConvertMetricFamily/OM1.0/HISTOGRAM-24           5.265µ ± 5%      289.0 ± 0%     7.000 ± 0%
ConvertMetricFamily/OM2.0/HISTOGRAM-24           2.867µ ± 5%      104.0 ± 0%     5.000 ± 0%
ConvertMetricFamily/TEXT/GAUGE_HISTOGRAM-24      2.261µ ± 4%      160.0 ± 0%     5.000 ± 0%
ConvertMetricFamily/OM1.0/GAUGE_HISTOGRAM-24     2.736µ ± 5%      161.0 ± 0%     6.000 ± 0%
ConvertMetricFamily/OM2.0/GAUGE_HISTOGRAM-24     1.624µ ± 2%      48.00 ± 0%     2.000 ± 0%

… 2.0

Implement serialization and strict validation for classic, native, dual, and gauge histograms in OpenMetrics 2.0 format according to the specification and ABNF grammar.

Signed-off-by: David Ashpole <dashpole@google.com>

Copilot AI left a comment

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.

Pull request overview

This PR extends the OpenMetrics 2.0 encoder to support serialization and validation of histogram and gauge-histogram metrics, aligning output formatting with the OM2 structure (inline histogram fields plus optional exemplars), and adjusts exemplar emission rules to allow empty-label exemplars when a timestamp is present.

Changes:

  • Implemented OpenMetrics 2.0 serialization/validation for classic, native, dual, and gauge histograms (including spans/buckets encoding and created timestamps where applicable).
  • Updated exemplar handling to no longer drop exemplars solely due to having an empty label set (still dropped if missing timestamp), emitting {} for empty labels.
  • Added comprehensive golden/output and error-case test coverage for histogram variants in OM2.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
expfmt/openmetrics_2_0_create.go Implements histogram/gaugehistogram encoding + validation and updates exemplar formatting for empty-label exemplars.
expfmt/openmetrics_2_0_create_test.go Adds output and error tests covering classic/native/dual/gauge histogram serialization and validation rules.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread expfmt/openmetrics_2_0_create.go
Signed-off-by: David Ashpole <dashpole@google.com>
Signed-off-by: David Ashpole <dashpole@google.com>
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.

2 participants