Skip to content

expfmt: add ABNF-based OpenMetrics 1.0 parser - #1015

Merged
bwplotka merged 4 commits into
mainfrom
bwplotka/om1-abnf-parser
Oct 27, 2026
Merged

bwplotka merged 4 commits into
mainfrom
bwplotka/om1-abnf-parser

Conversation

@bwplotka

@bwplotka bwplotka commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Implement an ABNF-based OpenMetrics 0.0.1 / 1.0.0 text format parser in expfmt using github.com/pandatix/go-abnf, wired into NewDecoder and ResponseFormat.

go-abnf dependency is pretty slim: https://github.com/pandatix/go-abnf/blob/main/go.mod

info and stateset metric types return an error until prometheus/client_model is expanded to represent them. Tests are ported from prometheus/prometheus/model/textparse.

Replaces #904

[FEATURE] expfmt: Add ABNF-based OpenMetrics 1.0 parser to `NewDecoder` and `ResponseFormat`.
@bwplotka

Copy link
Copy Markdown
Member Author

@krajorama wanted to double check if we need a feature flag. Small analysis, but TL;DR I think it's a low risk addition that does not need a feature flag.

Looking at public Go callers on GitHub:

  1. ~790 files call expfmt.NewTextParser directly, including promtool, pushgateway, node_exporter, prom2json, client_golang/prometheus/testutil, Thanos, Loki, Cilium, Linkerd, K3s, and Teleport. None of these are affected because TextParser is untouched. Prometheus server scraping is also unaffected since it uses its own model/textparse package.
  2. ~440 files call expfmt.NewDecoder with a hardcoded format like FmtText, TypeTextPlain, or FmtProtoDelim, including client_golang/prometheus/testutil/promlint, Kubernetes metrics/testutil, Kata Containers, Pixie, and Promxy. These still route to textDecoder or protoDecoder.
  3. ~120 files pair expfmt.NewDecoder with expfmt.ResponseFormat. Almost all of them either send no Accept header (like cAdvisor and Splunk OTel Collector lightprometheusreceiver) or explicitly request only TypeProtoDelim and text/plain; version=0.0.4 (like Kubernetes metrics/testutil, OpenShift Telemeter, Telegraf, and reverse_exporter), so exporters using promhttp.Handler or expfmt.Negotiate still send them 0.0.4 text or protobuf.

The most risk would be from (3) but: 0 files on GitHub combine NegotiateIncludingOpenMetrics with ResponseFormat and NewDecoder, and only 2 projects (fanyang89/prom-cli and older forks of elastic/beats) send application/openmetrics-text in Accept before calling ResponseFormat and NewDecoder. Previously, ResponseFormat returned FmtUnknown for application/openmetrics-text and NewDecoder fell through to the 0.0.4 textDecoder, forcing projects like Istio (pilot-agent) and upstream elastic/beats to work around expfmt (see #812).

Comment thread expfmt/openmetrics_parse.go Resolved
Comment thread expfmt/openmetrics_parse.go Resolved
Comment thread expfmt/openmetrics_parse.go Resolved
Implement an ABNF-based OpenMetrics 1.0 parser using github.com/pandatix/go-abnf and wire it into NewDecoder and ResponseFormat for FmtOpenMetrics_0_0_1 and FmtOpenMetrics_1_0_0. Port test cases from prometheus/prometheus/model/textparse/openmetricsparse_test.go.

Signed-off-by: Bartek Plotka <bwplotka@gmail.com>
…d require _total sample

Signed-off-by: Bartek Plotka <bwplotka@gmail.com>
… is nil

Signed-off-by: Bartek Plotka <bwplotka@gmail.com>
…sion

Signed-off-by: Bartek Plotka <bwplotka@gmail.com>
@bwplotka
bwplotka force-pushed the bwplotka/om1-abnf-parser branch from 0886513 to d127845 Compare October 23, 2026 07:18

@bwplotka bwplotka left a comment

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.

addressed!

Comment thread expfmt/openmetrics_parse.go Resolved
Comment thread expfmt/openmetrics_parse.go Resolved
Comment thread expfmt/openmetrics_parse.go Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants