Skip to content

expfmt: bump go-abnf to v0.5.5 - #1029

Merged
SuperQ merged 1 commit into
prometheus:mainfrom
PerryLink:fix/go-abnf-0.5.5
Nov 10, 2026
Merged

SuperQ merged 1 commit into
prometheus:mainfrom
PerryLink:fix/go-abnf-0.5.5

Conversation

@PerryLink

Copy link
Copy Markdown
Contributor

What

Bumps github.com/pandatix/go-abnf from v0.5.3 to v0.5.5.

Why

After #1015/#1016, expfmt.NewDecoder parses every OpenMetrics line with goabnf.ParseForest, whose SPPF construction is cubic. In #1028 a valid 4 KiB label value took 15–17 s to decode, which blocks any scrape far longer than its 10 s timeout.

The upstream fix is pandatix/go-abnf#277, tagged v0.5.5: a lookahead that avoids the useless parse paths. go.mod still pinned v0.5.3, so the decoder did not get it.

Benchmark

BenchmarkLongLine1028 (4 KiB label value, -benchtime=1x, linux/amd64, Go 1.26.10):

go-abnf ns/op
v0.5.3 16,884,997,606 (≈16.9 s)
v0.5.5 71,586,382 (≈71.6 ms)

≈236× faster. The remaining cost is still the ABNF forest, but a 4 KiB line no longer blows a scrape timeout. The linear-parser direction discussed in #1028 is still open if you want to go further.

Checks

  • go test ./... passes (all packages).
  • Only go.mod and go.sum change (one require line plus the two sum lines).
  • Ref #1028

The OpenMetrics decoder parses every line with goabnf.ParseForest, which
is cubic in the input length. A valid 4 KiB label value took ~17s to
decode on v0.5.3.

go-abnf v0.5.5 adds the lookahead that avoids the useless paths
(pandatix/go-abnf#277). Bump the dependency; go.sum follows.

Ref #1028

Signed-off-by: PerryLink <[email protected]>
@PerryLink

Copy link
Copy Markdown
Contributor Author

One more data point for this bump, from the OpenMetrics 2.0 decoder that landed in #1016: it has the same uncapped goabnf.ParseForest per line, and fuzzing the decoder at 203c789 stops on it.

dec := expfmt.NewDecoder(bytes.NewReader(bytes.Repeat([]byte("l"), n)), expfmt.FmtOpenMetrics_2_0_0)
dec.Decode(&dto.MetricFamily{})
line length FmtOpenMetrics_2_0_0
512 B 0.11 s
1 KiB 0.62 s
2 KiB 3.20 s
4 KiB 16.60 s

(Go 1.26.10, linux/amd64. The line is not valid OpenMetrics — it is a single long token — so the decoder pays the parse cost before rejecting it, which is the untrusted-input case from #1028.)

A go test -fuzz harness over NewDecoder with FmtOpenMetrics_2_0_0 finds such an input within ~20 seconds and reports fuzzing process hung or terminated unexpectedly; replaying it as a plain test passes, it just takes ~6.6 s. So the 2.0 decoder inherits the same superlinear behaviour as 1.0 and would benefit from the same bump.

@SuperQ SuperQ 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. Typically we just use dependabot to maintain these updates.

@SuperQ
SuperQ merged commit 998a85a into prometheus:main Nov 10, 2026
8 checks passed
@SuperQ SuperQ mentioned this pull request Nov 11, 2026
SuperQ added a commit that referenced this pull request Nov 12, 2026
What's Changed
* expfmt: add ABNF parser for OpenMetrics 2.0 by @bwplotka in #1016
* build(deps): bump ossf/scorecard-action from 2.4.4 to 2.5.0 by @dependabot[bot] in #1032
* build(deps): bump actions/upload-artifact from 7.0.1 to 7.0.2 by @dependabot[bot] in #1033
* build(deps): bump golang.org/x/net from 0.61.0 to 0.62.0 in the golang-org-x group across 1 directory by @dependabot[bot] in #1030
* expfmt: bump go-abnf to v0.5.5 by @PerryLink in #1029
* config: move Secret into its own package by @mrueg in #1024
* build(deps): bump the codeql group with 4 updates by @dependabot[bot] in #1031
* version: fix Slog godoc example to compile by @sueun-dev in #935
* build(deps): bump go.yaml.in/yaml/v2 from 2.4.4 to 2.4.5 by @dependabot[bot] in #1043
* build(deps): bump golang.org/x/oauth2 from 0.37.0 to 0.38.0 in the golang-org-x group across 1 directory by @dependabot[bot] in #1042
* expfmt: support Prometheus text format 1.0.0 by @ArthurSens in #1035

New Contributors
* @PerryLink made their first contribution in #1029
* @sueun-dev made their first contribution in #935

**Full Changelog**: v0.73.1...v0.74.0

Signed-off-by: SuperQ <[email protected]>
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.

2 participants