Skip to content

expfmt: add NegotiateFormats and NegotiateFormatsIncludingOpenMetrics - #931

Closed
adziauho wants to merge 1 commit into
prometheus:mainfrom
adziauho:return-sorted-list-of-negotiated-formats
Closed

adziauho wants to merge 1 commit into
prometheus:mainfrom
adziauho:return-sorted-list-of-negotiated-formats

Conversation

@adziauho

Copy link
Copy Markdown

Add NegotiateFormats and NegotiateFormatsIncludingOpenMetrics that return all recognised formats from the Accept header in descending preference order, allowing servers that support only a subset of formats to pick the first one they can serve without reimplementing the negotiation loop.

Rewrite Negotiate and NegotiateIncludingOpenMetrics to delegate to the new functions. Unify the shared negotiation logic into a private negotiateFormats helper parameterised by an includeOpenMetrics flag, eliminating the code duplication between the two variants.

Tests use []string acceptHeaderValues to exercise both comma-separated and multi-header Accept values. The implementation joins multiple Accept header values before parsing to correctly handle both forms.

Fixes #928.

@adziauho
adziauho force-pushed the return-sorted-list-of-negotiated-formats branch from 578faef to 4cde441 Compare June 23, 2026 15:02
Add NegotiateFormats and NegotiateFormatsIncludingOpenMetrics that return
all recognised formats from the Accept header in descending preference
order, allowing servers that support only a subset of formats to pick the
first one they can serve without reimplementing the negotiation loop.

Rewrite Negotiate and NegotiateIncludingOpenMetrics to delegate to the
new functions. Unify the shared negotiation logic into a private
negotiateFormats helper parameterised by an includeOpenMetrics flag,
eliminating the code duplication between the two variants.

Tests use []string acceptHeaderValues to exercise both comma-separated
and multi-header Accept values. The implementation joins multiple Accept
header values before parsing to correctly handle both forms.

Fixes prometheus#928.

Signed-off-by: Aliaksei Dziauho <a.dziauho@sap.com>
@adziauho
adziauho force-pushed the return-sorted-list-of-negotiated-formats branch from 4cde441 to 5d33231 Compare June 23, 2026 15:04
@bwplotka

Copy link
Copy Markdown
Member

The issue should be already fixed #928

@bwplotka bwplotka closed this Aug 26, 2026
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.

expfmt: NegotiateIncludingOpenMetrics makes it hard to select the first supported format when a server supports only a subset of formats

2 participants