You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
expfmt: NegotiateIncludingOpenMetrics makes it hard to select the first supported format when a server supports only a subset of formats #928
NegotiateIncludingOpenMetrics (in https://github.com/prometheus/common/blob/main/expfmt/encode.go) returns the single highest-quality format from the Accept header. If a server does not support that format, there is no straightforward way to fall back to the next
recognised format from the client's preference list — the caller would have to reimplement the entire negotiation loop manually.
Example
A server that supports OpenMetrics and text/plain but not protobuf receives:
NegotiateIncludingOpenMetrics returns FmtProtoDelim. The server cannot serve it, but has no API to ask "what is the next format the client accepts that I can serve?" — the only escape hatch today is an unconditional fallback to FmtText, ignoring
application/openmetrics-text which both sides support.
Suggested fix
Add a companion function to expfmt/encode.go, leaving NegotiateIncludingOpenMetrics unchanged:
// NegotiateFormatsIncludingOpenMetrics works like NegotiateIncludingOpenMetrics // but returns all recognised formats from the Accept header in descending // preference order instead of stopping at the first match. If no recognised // formats are found, the slice contains FmtText as the default fallback. funcNegotiateFormatsIncludingOpenMetrics(h http.Header) []Format
The caller can then iterate and pick the first format it supports, without reimplementing the negotiation loop.
Activity
expfmt: add NegotiateFormats and NegotiateFormatsIncludingOpenMetrics
expfmt: add NegotiateFormats and NegotiateFormatsIncludingOpenMetrics
bwplotka commentedon Aug 24, 2026
New method was added that should solve your problem:
common/expfmt/encode.go
Line 83 in 5768e9c
Thanks!