Skip to content

expfmt: drop exemplar and created line for counters exposed as unknown - #1047

Open
ismailtrm wants to merge 1 commit into
prometheus:mainfrom
ismailtrm:openmetrics-unknown-counter
Open

ismailtrm wants to merge 1 commit into
prometheus:mainfrom
ismailtrm:openmetrics-unknown-counter

Conversation

@ismailtrm

Copy link
Copy Markdown

MetricFamilyToOpenMetrics exposes a counter without the _total suffix as unknown, "to avoid invalid OpenMetrics output" (godoc). It still writes the counter-only parts next to the unknown sample: the exemplar and, with WithCreatedLines(), a <name>_created line.

# HELP foos Number of foos.
# TYPE foos unknown
foos 42.0 # {foo="bar"} 1.0 12345.6
foos_created 12345.6

Both are invalid for an unknown metric in OpenMetrics 1.0: the spec says the sample name of an Unknown MetricPoint "MUST NOT have a suffix", and it only describes exemplars on a counter's _total sample and on histogram buckets. The OpenMetrics 1.0 parser in this package rejects the output (counter named requests):

  • with an exemplar: exemplar not allowed on untyped metric "requests"
  • with created lines and two series: interleaved metric family "requests"
  • with created lines and one series it parses, but the counter comes back as two metric families

With this change, a counter exposed as unknown gets neither of them:

# HELP foos Number of foos.
# TYPE foos unknown
foos 42.0

Counters with the _total suffix are unchanged. The MetricFamilyToOpenMetrics documentation now also mentions that the exemplar and created line are omitted.

Test: a new TestCreateOpenMetrics case, which fails without the fix. go test -race ./expfmt/ passes, and after the change the output parses with the OpenMetrics 1.0 parser in all three cases.

@roidelapluie

A counter without the _total suffix is written with type unknown, but
the encoder still wrote its exemplar and, with WithCreatedLines, a
_created line. OpenMetrics 1.0 allows neither for an unknown metric,
and the OpenMetrics 1.0 parser in this package rejects that output.

Skip both when the counter is exposed as unknown, and say so in the
MetricFamilyToOpenMetrics documentation.

Signed-off-by: Ismail Tarim <ismailtarim7@gmail.com>
Copilot AI balanced review requested due to automatic review settings November 16, 2026 21:11

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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