Skip to content

expfmt: fix wildcard content negotiation regression for Negotiate and NegotiateIncludingOpenMetrics - #966

Merged
bwplotka merged 1 commit into
prometheus:mainfrom
dashpole:fix-negotiate-wildcard
Aug 24, 2026
Merged

expfmt: fix wildcard content negotiation regression for Negotiate and NegotiateIncludingOpenMetrics#966
bwplotka merged 1 commit into
prometheus:mainfrom
dashpole:fix-negotiate-wildcard

Conversation

@dashpole

Copy link
Copy Markdown
Contributor

Fixes a regression introduced by #894.

Clients sending Accept: / or browser Accept headers containing wildcards should receive standard Prometheus text format (FmtText) when using Negotiate or NegotiateIncludingOpenMetrics.

Previously, matchFormat short-circuited on /, immediately returning the first format in the accepted list (Protobuf for Negotiate, and OpenMetrics 1.0 for NegotiateIncludingOpenMetrics).

Remove the / short-circuit from matchFormat so wildcard Accept headers fall back to the text-preferring fallback logic in NegotiateAccept.

… NegotiateIncludingOpenMetrics

Clients sending Accept: */* or browser Accept headers containing wildcards
should receive standard Prometheus text format (FmtText) when using Negotiate
or NegotiateIncludingOpenMetrics.

Previously, matchFormat short-circuited on */*, immediately returning the first
format in the accepted list (Protobuf for Negotiate, and OpenMetrics 1.0 for
NegotiateIncludingOpenMetrics).

Remove the */* short-circuit from matchFormat so wildcard Accept headers fall
back to the text-preferring fallback logic in NegotiateAccept.

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.

Pull request overview

Fixes a content negotiation regression in expfmt where wildcard Accept headers (e.g., */* and common browser headers containing wildcards) incorrectly selected the first offered format (notably Protobuf / OpenMetrics) instead of falling back to the expected Prometheus text format.

Changes:

  • Removes the */* short-circuit in matchFormat, allowing wildcard Accept headers to fall through to NegotiateAccept’s text-preferring fallback behavior.
  • Adds/updates tests to cover */*, browser-style wildcard headers, and mixed headers (e.g., application/json, */*) for both Negotiate and NegotiateIncludingOpenMetrics.
  • Updates NegotiateAccept wildcard expectations, including the case where no text format is available (fallback to first accepted format).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
expfmt/encode.go Removes */* special-casing in format matching so wildcard headers no longer force selection of the first accepted format.
expfmt/encode_test.go Adds/updates negotiation tests to verify wildcard Accept headers prefer Prometheus text when available.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@dashpole
dashpole requested a review from bwplotka August 24, 2026 16:23
@dashpole
dashpole marked this pull request as ready for review August 24, 2026 16:23

@bwplotka bwplotka left a comment

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.

Thanks!

Comment thread expfmt/encode_test.go
"github.com/prometheus/common/model"
)

func TestNegotiate(t *testing.T) {

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.

observation: Probably a duplicated test, we could DRY here

@bwplotka
bwplotka merged commit 7832844 into prometheus:main Aug 24, 2026
8 checks passed
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