Skip to content

promhttp: support OpenMetrics 2.0 - #2132

Draft
bwplotka wants to merge 1 commit into
mainfrom
om2
Draft

bwplotka wants to merge 1 commit into
mainfrom
om2

Conversation

@bwplotka

@bwplotka bwplotka commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

Depends on #2138

Support OpenMetrics 2.0 content negotiation when EnableOpenMetrics: true.

  • Add expfmt.FmtOpenMetrics_2_0_0 to openMetricsAcceptedFormats ahead of stable OpenMetrics formats.
  • Add table-driven tests for OpenMetrics 2.0 negotiation and exposition.

@bwplotka
bwplotka requested a review from dashpole September 22, 2026 10:25
var contentType expfmt.Format
if opts.EnableOpenMetrics {
contentType = expfmt.NegotiateIncludingOpenMetrics(req.Header)
contentType = expfmt.NegotiateAccept(req.Header, openMetricsAcceptedFormats...)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Open question: Can we introduce OM2 by default (experimental stage)? Given our feature flag on collection side, we probably can and should. cc @dashpole @krajorama

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.

The worst that can happen is that there's a client_golang version that exposes OM2.0 that's not 100% up to spec. Enabling on server side will mean failed scrape and lost metrics.

I think maybe a mitigation would be to actually enable server side default with a 2.0.1 version, not 2.0.0, so testing can be done with 2.0.0 , but kind of quality gate to 2.0.1 ?

So in short, I think we can enable this now with 2.0.0 , because we have a way to mitigate the above risk.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

  • What's 2.0.1? Do we plan that?
  • This kind of depends if we plan to make OM 2 a default, highest priority on scrape priority list on Prometheus without major version bump 🤔

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.

If possible, it would be nice to have it be opt-in until the spec is stabilized. But @krajorama is right that the failure modes aren't that bad. But there will definitely be people that use a newer server and an older (possibly broken) client.

If we do decide that we want to distinguish the rc vs stable versions, I'm not sure 2.0.0 and 2.0.1 make sense, given there could theoretically be breaking changes between them. Ideally it would be something like 2.0.0-rc (or 2.0.0-experimental) and 2.0.0 or something like that.

I don't think we can make OM 2 the default, highest priority on the scrape priority list without a major version bump.

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.

Yes, using 2.0.0-rc or something would be ideal.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Interesting, it's true that the protocol is still rc.0 so we could change here to -rc and then update Prometheus side to also put -rc in accept header?

@bwplotka bwplotka Sep 29, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

So, the proposed flow could look like:

  1. Add application/openmetrics-text;version=2.0.0-rc here.
  2. Add Accept application/openmetrics-text;version=2.0.0-rc (as well as the current application/openmetrics-text;version=2.0.0?) on Prometheus behind flag
  3. When 2.0.0 is shipped
    3a: Update client_golang to announce both only the non rc by default, deprecate -rc version
  4. On major version bump in Prometheus we make 2.0.0 a default

Alternatives:

A) Aame as above but literal versions e.g 2.0.0-rc.0
B) Exposer ships application/openmetrics-text;version=2.0.0 by default. We risk surprises on major version default swap to 2.0
C) Exposer ships application/openmetrics-text;version=2.0.0 opt-in, then by-default in some next SDK release. This is odd because we defer the same problem (when and how server would change, how much stability we have here etc) to app owners in a programmatic change

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.

Or one other idea is that the client keeps support for 2.0.0-rc forever, but it is equivalent to 2.0.0 after that is released.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

OK, since this requires prometheus/common etc I allow opt-in for now #2146 - this PR will try to allow default and server opt-in TBD

Comment thread prometheus/promhttp/http.go
@bwplotka
bwplotka force-pushed the om2 branch 2 times, most recently from 1ed82b0 to c864a74 Compare September 28, 2026 10:22
@bwplotka bwplotka changed the title promhttp: update prometheus/common and support OpenMetrics 2.0 promhttp: support OpenMetrics 2.0 Sep 28, 2026
@bwplotka
bwplotka changed the base branch from main to update-common-v0.72.0 September 28, 2026 10:25
@bwplotka
bwplotka marked this pull request as ready for review September 28, 2026 10:25
@bwplotka
bwplotka force-pushed the update-common-v0.72.0 branch from 7a9b278 to c742466 Compare September 28, 2026 11:54
Base automatically changed from update-common-v0.72.0 to main September 28, 2026 12:20
Support OpenMetrics 2.0 content negotiation when EnableOpenMetrics is true.
Add table-driven tests for OpenMetrics 2.0 negotiation and exposition.

Signed-off-by: bwplotka <bwplotka@gmail.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.

3 participants