Skip to content

feat: implement summary support for OpenMetrics 2.0 - #983

Open
dashpole wants to merge 2 commits into
prometheus:mainfrom
dashpole:om2_summaries
Open

feat: implement summary support for OpenMetrics 2.0#983
dashpole wants to merge 2 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

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>

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
…ic families accepted by other formats

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