Skip to content

feat: implement summary support for OpenMetrics 2.0 - #983

Merged
dashpole merged 5 commits into
prometheus:mainfrom
dashpole:om2_summaries
Sep 18, 2026
Merged

dashpole merged 5 commits into
prometheus:mainfrom
dashpole:om2_summaries

Conversation

@dashpole

@dashpole dashpole commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Part of #893

Implement serialization and strict validation for summaries in OpenMetrics 2.0 format according to the specification and ABNF grammar.

Benchmark Results

goos: linux
goarch: amd64
pkg: github.com/prometheus/common/expfmt
cpu: Intel(R) Xeon(R) CPU @ 2.20GHz
BenchmarkConvertMetricFamily/TEXT/SUMMARY-24         	  345410	      3426 ns/op	      56 B/op	       2 allocs/op
BenchmarkConvertMetricFamily/OM1.0/SUMMARY-24        	  273915	      4486 ns/op	      57 B/op	       3 allocs/op
BenchmarkConvertMetricFamily/OM2.0/SUMMARY-24        	  501536	      2026 ns/op	       0 B/op	       0 allocs/op

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.

🟡 Changes recommended

The new summary validation rejects negative SampleSum and negative quantile values, which are valid in existing OpenMetrics summary behavior and would cause the OM2.0 encoder to error on legitimate data.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds OpenMetrics 2.0 composite summary support to expfmt by implementing serialization plus validation, and expands the test suite to cover correct formatting and error cases.

Changes:

  • Implement writeCompositeSummary for OpenMetrics 2.0 composite summary encoding, including label/quantile/timestamp validation.
  • Update OpenMetrics 2.0 encoder documentation comment to reflect newly supported metric types.
  • Add comprehensive summary test vectors (success + validation errors + “no partial bytes on error”).
File summaries
File Description
expfmt/openmetrics_2_0_create.go Implements OpenMetrics 2.0 composite summary encoding and validation logic.
expfmt/openmetrics_2_0_create_test.go Adds summary golden tests, validation error tests, and a no-partial-bytes regression test.
Review details

Suppressed comments (1)

expfmt/openmetrics_2_0_create.go:386

  • Rejecting negative quantile values for summaries is likely incorrect: quantile values are observed sample values and can be negative (the OpenMetrics v1.0 encoder tests include negative quantile values). This validation would cause the OM2.0 encoder to error on otherwise valid summary data.
		v := q.GetValue()
		if !math.IsNaN(v) && v < 0 {
			return 0, fmt.Errorf("summary quantile value cannot be negative (%g) in metric %s", v, name)
		}
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 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
@dashpole
dashpole marked this pull request as ready for review September 2, 2026 16:49

@bwplotka bwplotka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great, tiny nits only.

Comment thread expfmt/openmetrics_2_0_create.go Outdated
Comment thread expfmt/openmetrics_2_0_create_test.go
Comment thread expfmt/openmetrics_2_0_create_test.go Outdated
dashpole and others added 5 commits September 18, 2026 19:12
Implement serialization and strict validation for summaries in OpenMetrics 2.0 format according to the specification and ABNF grammar.

Signed-off-by: David Ashpole <dashpole@google.com>
…ic families accepted by other formats

Signed-off-by: David Ashpole <dashpole@google.com>
Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>
Signed-off-by: David Ashpole <dashpole@google.com>
…AndSum test

Signed-off-by: David Ashpole <dashpole@google.com>
…mp in SummaryError_NoPartialBytes

Signed-off-by: David Ashpole <dashpole@google.com>
@dashpole
dashpole merged commit db5c9e8 into prometheus:main Sep 18, 2026
8 checks passed
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.

3 participants