Skip to content

expfmt: prevent st@ leaking to Gauge and Untyped samples in OpenMetrics 2.0 - #971

Open
dashpole wants to merge 1 commit into
prometheus:mainfrom
dashpole:fix-om20-timestamps
Open

expfmt: prevent st@ leaking to Gauge and Untyped samples in OpenMetrics 2.0#971
dashpole wants to merge 1 commit into
prometheus:mainfrom
dashpole:fix-om20-timestamps

Conversation

@dashpole

@dashpole dashpole commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Some small follow-ups to the OpenMetrics 2.0 support introduced by #894.

Previously, writeOpenMetrics20Sample inspected metric.Counter.CreatedTimestamp directly when rendering samples. If a dto.Metric struct had multiple type fields populated (e.g., a Gauge with a leftover Counter.CreatedTimestamp), st@ would incorrectly render on Gauge or Untyped sample lines.
This PR:

  • Passes startTimestamp explicitly to writeOpenMetrics20Sample only from the Counter branch (passing nil for Gauge and Untyped).
  • Cleans up dead NaN/Inf branches in writeOpenMetrics20Timestamp in favor of direct strconv.AppendFloat formatting.
  • Adds test cases verifying st@ is isolated to Counter metrics and does not leak onto Gauge/Untyped samples.

@dashpole dashpole changed the title expfmt: prevent st@ leaking to Gauge and Untyped samples in OpenMetri… expfmt: prevent st@ leaking to Gauge and Untyped samples in OpenMetrics 2.0 Aug 24, 2026
@dashpole
dashpole force-pushed the fix-om20-timestamps branch from 50b5d21 to 93d3808 Compare August 24, 2026 16:28
@dashpole
dashpole requested a lite review from Copilot August 24, 2026 16:31

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

Follow-up fixes to the OpenMetrics 2.0 expfmt writer to ensure st@ (start timestamp) is emitted only for Counter samples, plus a small cleanup/adjustment around timestamp formatting and related test coverage.

Changes:

  • Pass CreatedTimestamp explicitly only for Counter samples so st@ doesn’t leak into Gauge/Untyped output.
  • Simplify writeOpenMetrics20Timestamp by relying on strconv.AppendFloat behavior directly.
  • Improve proto timestamp formatting for pre-epoch timestamps and add coverage for those cases.

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 Ensures st@ is only written when explicitly provided (Counters), simplifies timestamp writing, and improves proto timestamp formatting for pre-epoch values.
expfmt/openmetrics_2_0_create_test.go Adds scenarios preventing st@ leakage to Gauge/Untyped and adds tests for pre-epoch proto timestamp formatting; adjusts timestamp unit tests.

💡 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_test.go
…cs 2.0

Signed-off-by: David Ashpole <dashpole@google.com>
@dashpole
dashpole force-pushed the fix-om20-timestamps branch from 8708e66 to 750ac47 Compare August 24, 2026 17:54
@dashpole
dashpole marked this pull request as ready for review August 24, 2026 18:01
@dashpole
dashpole requested review from bwplotka and krajorama August 24, 2026 18:01
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