Skip to content

textparse: validate series against metric family to prevent wrong metadata#18015

Open
mdxabu wants to merge 3 commits intoprometheus:mainfrom
mdxabu:fix-metadata-parser-issue-17900
Open

textparse: validate series against metric family to prevent wrong metadata#18015
mdxabu wants to merge 3 commits intoprometheus:mainfrom
mdxabu:fix-metadata-parser-issue-17900

Conversation

@mdxabu
Copy link
Copy Markdown
Contributor

@mdxabu mdxabu commented Feb 5, 2026

Move metadata validation from scrape.go into text and OM parsers. Series now only inherit metadata when they actually belong to the metric family, preventing cases like test_metric3_metric4 from incorrectly getting metadata from test_metric3.

This fixes a long-standing issue where metrics could inherit wrong TYPE/HELP/UNIT metadata from unrelated metric families. The validation logic using isSeriesPartOfFamily has been moved directly into the parser's Labels() method, making it more efficient and accurate.

Changes:

  • Added isSeriesPartOfFamily() helper function in textparse/interface.go
  • Modified PromParser and OpenMetricsParser to track current metric family and validate series membership
  • Updated Labels() method to set metadata to unknown when series doesn't belong to the tracked family
  • Fixed test expectations that were previously marked as "knowingly broken"

Example of fixed behavior:

# TYPE test_metric3 gauge
# HELP test_metric3 this represents tricky case of "broken" text
test_metric3_metric4{foo="bar"} 2

Before: test_metric3_metric4 would incorrectly get __type__="gauge"
After: test_metric3_metric4 correctly gets no type label (unknown)

Which issue(s) does the PR fix:

Fixes #17900

Does this PR introduce a user-facing change?

[BUGFIX] textparse: Fix incorrect metadata inheritance for series that don't belong to the current metric family.

…adata

Move metadata validation from scrape.go into text and OM parsers.
Series now only inherit metadata when they actually belong to the
metric family, preventing cases like test_metric3_metric4 from
incorrectly getting metadata from test_metric3.

Fixes prometheus#17900

Signed-off-by: Abu <[email protected]>
@mdxabu mdxabu requested a review from a team as a code owner February 5, 2026 05:58
@mdxabu mdxabu requested a review from jesusvazquez February 5, 2026 05:58
- Remove unused receiver in PromParser.Unit()
- Remove unused todoDetectFamilySwitch function

Signed-off-by: Abu <[email protected]>
@mdxabu
Copy link
Copy Markdown
Contributor Author

mdxabu commented Feb 5, 2026

@jesusvazquez @bwplotka @bboreham, can you review my PR?

Signed-off-by: Abu <[email protected]>
@mdxabu
Copy link
Copy Markdown
Contributor Author

mdxabu commented Feb 5, 2026

prometheus git:(fix-metadata-parser-issue-17900)    go test ./tsdb/... -run TestDiskFillingUpAfterDisablingOOO_AppendV2 -v

=== RUN   TestDiskFillingUpAfterDisablingOOO_AppendV2
=== PAUSE TestDiskFillingUpAfterDisablingOOO_AppendV2
=== CONT  TestDiskFillingUpAfterDisablingOOO_AppendV2
=== RUN   TestDiskFillingUpAfterDisablingOOO_AppendV2/float
=== PAUSE TestDiskFillingUpAfterDisablingOOO_AppendV2/float
=== RUN   TestDiskFillingUpAfterDisablingOOO_AppendV2/integer_histogram
=== PAUSE TestDiskFillingUpAfterDisablingOOO_AppendV2/integer_histogram
=== RUN   TestDiskFillingUpAfterDisablingOOO_AppendV2/float_histogram
=== PAUSE TestDiskFillingUpAfterDisablingOOO_AppendV2/float_histogram
=== RUN   TestDiskFillingUpAfterDisablingOOO_AppendV2/custom_buckets_int_histogram
=== PAUSE TestDiskFillingUpAfterDisablingOOO_AppendV2/custom_buckets_int_histogram
=== RUN   TestDiskFillingUpAfterDisablingOOO_AppendV2/custom_buckets_float_histogram
=== PAUSE TestDiskFillingUpAfterDisablingOOO_AppendV2/custom_buckets_float_histogram
=== RUN   TestDiskFillingUpAfterDisablingOOO_AppendV2/gauge_int_histogram
=== PAUSE TestDiskFillingUpAfterDisablingOOO_AppendV2/gauge_int_histogram
=== RUN   TestDiskFillingUpAfterDisablingOOO_AppendV2/gauge_float_histogram
=== PAUSE TestDiskFillingUpAfterDisablingOOO_AppendV2/gauge_float_histogram
=== CONT  TestDiskFillingUpAfterDisablingOOO_AppendV2/float
=== CONT  TestDiskFillingUpAfterDisablingOOO_AppendV2/custom_buckets_float_histogram
=== CONT  TestDiskFillingUpAfterDisablingOOO_AppendV2/float_histogram
=== CONT  TestDiskFillingUpAfterDisablingOOO_AppendV2/integer_histogram
=== CONT  TestDiskFillingUpAfterDisablingOOO_AppendV2/custom_buckets_int_histogram
=== CONT  TestDiskFillingUpAfterDisablingOOO_AppendV2/gauge_float_histogram
=== CONT  TestDiskFillingUpAfterDisablingOOO_AppendV2/gauge_int_histogram
--- PASS: TestDiskFillingUpAfterDisablingOOO_AppendV2 (0.00s)
    --- PASS: TestDiskFillingUpAfterDisablingOOO_AppendV2/custom_buckets_int_histogram (6.34s)
    --- PASS: TestDiskFillingUpAfterDisablingOOO_AppendV2/float_histogram (6.34s)
    --- PASS: TestDiskFillingUpAfterDisablingOOO_AppendV2/float (6.34s)
    --- PASS: TestDiskFillingUpAfterDisablingOOO_AppendV2/integer_histogram (6.34s)
    --- PASS: TestDiskFillingUpAfterDisablingOOO_AppendV2/gauge_int_histogram (6.34s)
    --- PASS: TestDiskFillingUpAfterDisablingOOO_AppendV2/custom_buckets_float_histogram (6.34s)
    --- PASS: TestDiskFillingUpAfterDisablingOOO_AppendV2/gauge_float_histogram (6.34s)
PASS
ok  	github.com/prometheus/prometheus/tsdb	9.257s
testing: warning: no tests to run
PASS
ok  	github.com/prometheus/prometheus/tsdb/agent	2.160s [no tests to run]
testing: warning: no tests to run
PASS
ok  	github.com/prometheus/prometheus/tsdb/chunkenc	3.676s [no tests to run]
testing: warning: no tests to run
PASS
testing: warning: no tests to run
PASS
ok  	github.com/prometheus/prometheus/tsdb/chunks	7.687s [no tests to run]
?   	github.com/prometheus/prometheus/tsdb/encoding	[no test files]
testing: warning: no tests to run
PASS
ok  	github.com/prometheus/prometheus/tsdb/fileutil	6.854s [no tests to run]
testing: warning: no tests to run
PASS
ok  	github.com/prometheus/prometheus/tsdb/goversion	8.879s [no tests to run]
testing: warning: no tests to run
PASS
ok  	github.com/prometheus/prometheus/tsdb/index	9.303s [no tests to run]
testing: warning: no tests to run
PASS
ok  	github.com/prometheus/prometheus/tsdb/record	4.512s [no tests to run]
testing: warning: no tests to run
PASS
ok  	github.com/prometheus/prometheus/tsdb/tombstones	1.379s [no tests to run]
testing: warning: no tests to run
PASS
ok  	github.com/prometheus/prometheus/tsdb/tsdbutil	5.768s [no tests to run]
testing: warning: no tests to run
PASS
ok  	github.com/prometheus/prometheus/tsdb/wlog	8.611s [no tests to run]

It was passing in my local machine, it was because the test may be stuck in a loop that never completes within the 10-minute default timeout

@mdxabu
Copy link
Copy Markdown
Contributor Author

mdxabu commented Feb 5, 2026

Now, All Tests are Passed!

Copy link
Copy Markdown
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing work, thanks!

Yea, TestDiskFillingUpAfterDisablingOOO* is flaky, you can ignore it for now (trying to find the cause in #18017)

So this PR looks pretty good, but I didn't look ultra closely. Before I do we need to understand the current overhead. The main challenge is performance. How much overhead this is?

We used to do this metric family check ONLY on metadata-wal-feature. Now with this PR we will do it always, on every line. Let's see how much more expensive it is.

Can you run https://github.com/prometheus/prometheus/blob/main/scrape/scrape_test.go#L1760?

We can then later run prombench, once we are happy with microbenchmarks.

@mdxabu
Copy link
Copy Markdown
Contributor Author

mdxabu commented Feb 5, 2026

Amazing work, thanks!

Yea, TestDiskFillingUpAfterDisablingOOO* is flaky, you can ignore it for now (trying to find the cause in #18017)

So this PR looks pretty good, but I didn't look ultra closely. Before I do we need to understand the current overhead. The main challenge is performance. How much overhead this is?

We used to do this metric family check ONLY on metadata-wal-feature. Now with this PR we will do it always, on every line. Let's see how much more expensive it is.

Can you run https://github.com/prometheus/prometheus/blob/main/scrape/scrape_test.go#L1760?

We can then later run prombench, once we are happy with microbenchmarks.

@bwplotka, I'll ignore that one.

I ran the benchmarks as requested. Here's what I found:

Ran BenchmarkScrapeLoopAppend on my M4 Mac. The good news: no measurable performance impact across all configurations.

Without metadata-to-WAL:

  • 1 Family, 2000 Gauges: ~557 ns/op
  • 237 Families, All Types: ~975 ns/op

With metadata-to-WAL (the path we're changing):

  • 1 Family, 2000 Gauges: ~572 ns/op
  • 237 Families, All Types: ~975 ns/op

Similar results for OpenMetrics - basically no difference.

The validation in isSeriesPartOfFamily() is pretty lightweight:

  1. Fast path hits immediately with strings.HasPrefix() for non-matching series
  2. For matching series, we do a few strings.CutSuffix() calls - which we'd need to handle anyway for histograms/summaries
  3. Zero allocations since we're working with existing strings

The only extra work occurs when we encounter mismatched series (like the test_metric3_metric4 bug case), which are rejected early.

Let me know if you'd like me to run any other benchmarks or if prombench would be helpful!

here's the full benchmark,

goos: darwin
goarch: arm64
pkg: github.com/prometheus/prometheus/scrape
cpu: Apple M4
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=PromText-10         	    1039	    560796 ns/op	    2114 B/op	      20 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=PromText-10         	    1051	    556982 ns/op	    2104 B/op	      20 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=PromText-10         	    1060	    555347 ns/op	    2097 B/op	      20 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=OMText-10           	    1086	    542974 ns/op	    2224 B/op	      21 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=OMText-10           	    1081	    541537 ns/op	    2227 B/op	      21 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=OMText-10           	    1095	    541272 ns/op	    2217 B/op	      21 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=PromProto-10        	     877	    679122 ns/op	  113262 B/op	      35 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=PromProto-10        	     877	    685438 ns/op	  113262 B/op	      35 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=PromProto-10        	     813	    710224 ns/op	  113332 B/op	      36 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=PromText-10        	     597	    975260 ns/op	    3584 B/op	      32 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=PromText-10        	     610	   1101699 ns/op	    3541 B/op	      31 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=PromText-10        	     528	   1003408 ns/op	    3852 B/op	      34 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=OMText-10          	     594	    971159 ns/op	    3741 B/op	      33 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=OMText-10          	     610	    965148 ns/op	    3687 B/op	      32 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=OMText-10          	     614	    972440 ns/op	    3674 B/op	      32 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=PromProto-10       	     735	    820386 ns/op	   76247 B/op	    2240 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=PromProto-10       	     744	    809641 ns/op	   76233 B/op	    2240 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=PromProto-10       	     741	    809536 ns/op	   76238 B/op	    2240 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromText-10          	    1009	    565227 ns/op	    2139 B/op	      21 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromText-10          	    1064	    569499 ns/op	    2094 B/op	      20 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromText-10          	    1009	    583339 ns/op	    2139 B/op	      21 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=OMText-10            	    1005	    551280 ns/op	    2288 B/op	      22 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=OMText-10            	    1086	    544044 ns/op	    2224 B/op	      21 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=OMText-10            	    1089	    539897 ns/op	    2222 B/op	      21 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromProto-10         	     861	    686147 ns/op	  113278 B/op	      36 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromProto-10         	     868	    681896 ns/op	  113271 B/op	      36 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromProto-10         	     866	    683706 ns/op	  113274 B/op	      36 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromText-10         	     607	    977012 ns/op	    3551 B/op	      31 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromText-10         	     608	    972373 ns/op	    3547 B/op	      31 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromText-10         	     608	    976114 ns/op	    3547 B/op	      31 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=OMText-10           	     606	    971485 ns/op	    3700 B/op	      32 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=OMText-10           	     613	    969312 ns/op	    3588 B/op	      32 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=OMText-10           	     610	    971731 ns/op	    3687 B/op	      32 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromProto-10        	     744	    801064 ns/op	   76233 B/op	    2240 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromProto-10        	     741	    800236 ns/op	   76237 B/op	    2240 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=false/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromProto-10        	     744	    799162 ns/op	   76161 B/op	    2240 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=PromText-10          	    1059	    565286 ns/op	    2146 B/op	      21 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=PromText-10          	    1045	    567604 ns/op	    2157 B/op	      21 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=PromText-10          	    1057	    562795 ns/op	    2148 B/op	      21 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=OMText-10            	    1065	    551305 ns/op	    2288 B/op	      22 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=OMText-10            	    1084	    549606 ns/op	    2273 B/op	      22 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=OMText-10            	    1070	    549734 ns/op	    2284 B/op	      22 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=PromProto-10         	     872	    686182 ns/op	  113316 B/op	      37 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=PromProto-10         	     872	    684832 ns/op	  113322 B/op	      37 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=PromProto-10         	     862	    686324 ns/op	  113326 B/op	      37 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=PromText-10         	     597	    985954 ns/op	    3632 B/op	      33 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=PromText-10         	     602	    983036 ns/op	    3615 B/op	      32 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=PromText-10         	     602	    985350 ns/op	    3615 B/op	      32 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=OMText-10           	     607	    977440 ns/op	    3745 B/op	      33 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=OMText-10           	     607	    981150 ns/op	    3745 B/op	      33 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=OMText-10           	     609	    977454 ns/op	    3738 B/op	      33 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=PromProto-10        	     738	    795068 ns/op	   76215 B/op	    2241 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=PromProto-10        	     746	    797865 ns/op	   76274 B/op	    2241 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=PromProto-10        	     748	    795148 ns/op	   76199 B/op	    2241 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromText-10           	    1000	    586115 ns/op	    2194 B/op	      22 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromText-10           	    1008	    587658 ns/op	    2188 B/op	      22 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromText-10           	    1003	    587910 ns/op	    2192 B/op	      22 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=OMText-10             	    1022	    581213 ns/op	    2322 B/op	      22 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=OMText-10             	    1021	    579339 ns/op	    2323 B/op	      22 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=OMText-10             	    1021	    576110 ns/op	    2323 B/op	      22 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromProto-10          	     834	    712716 ns/op	  113356 B/op	      37 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromProto-10          	     835	    708244 ns/op	  113354 B/op	      37 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromProto-10          	     834	    711314 ns/op	  113356 B/op	      37 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromText-10          	     583	   1012264 ns/op	    3588 B/op	      33 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromText-10          	     586	   1011874 ns/op	    3671 B/op	      33 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromText-10          	     583	   1017046 ns/op	    3682 B/op	      33 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=OMText-10            	     583	   1010925 ns/op	    3828 B/op	      34 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=OMText-10            	     585	   1012369 ns/op	    3727 B/op	      34 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=OMText-10            	     588	   1013403 ns/op	    3810 B/op	      34 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromProto-10         	     705	    833927 ns/op	   76351 B/op	    2242 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromProto-10         	     714	    830665 ns/op	   76336 B/op	    2242 allocs/op
BenchmarkScrapeLoopAppend/withStorage=false/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromProto-10         	     715	    833569 ns/op	   76333 B/op	    2242 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=PromText-10          	     918	    611767 ns/op	    5660 B/op	      38 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=PromText-10          	     924	    611975 ns/op	    5620 B/op	      37 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=PromText-10          	     948	    606476 ns/op	    5518 B/op	      37 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=OMText-10            	     958	    588841 ns/op	    5624 B/op	      38 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=OMText-10            	     958	    587394 ns/op	    5635 B/op	      38 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=OMText-10            	     968	    587952 ns/op	    5582 B/op	      37 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=PromProto-10         	     798	    730484 ns/op	  117941 B/op	      55 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=PromProto-10         	     768	    745519 ns/op	  117999 B/op	      55 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=PromProto-10         	     771	    742198 ns/op	  117740 B/op	      55 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=PromText-10         	     568	   1002223 ns/op	    8100 B/op	      51 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=PromText-10         	     586	    990830 ns/op	    7856 B/op	      50 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=PromText-10         	     598	    984214 ns/op	    7783 B/op	      49 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=OMText-10           	     600	    973561 ns/op	    7867 B/op	      50 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=OMText-10           	     597	    973495 ns/op	    7897 B/op	      50 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=OMText-10           	     600	    973112 ns/op	    7865 B/op	      50 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=PromProto-10        	     709	    812856 ns/op	   79991 B/op	    2256 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=PromProto-10        	     711	    810789 ns/op	   79799 B/op	    2256 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=PromProto-10        	     710	    809859 ns/op	   80098 B/op	    2256 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromText-10           	     834	    649843 ns/op	    6660 B/op	      40 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromText-10           	     818	    627560 ns/op	    6450 B/op	      40 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromText-10           	     930	    621489 ns/op	    5903 B/op	      37 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=OMText-10             	     926	    636004 ns/op	    6036 B/op	      38 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=OMText-10             	     975	    600418 ns/op	    5818 B/op	      37 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=OMText-10             	     986	    586084 ns/op	    5774 B/op	      37 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromProto-10          	     812	    733402 ns/op	  118504 B/op	      54 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromProto-10          	     783	    733293 ns/op	  117906 B/op	      55 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromProto-10          	     793	    735127 ns/op	  118112 B/op	      55 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromText-10          	     594	    983034 ns/op	    8254 B/op	      50 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromText-10          	     594	    979253 ns/op	    8118 B/op	      49 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromText-10          	     595	    979197 ns/op	    8248 B/op	      50 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=OMText-10            	     598	    974196 ns/op	    8220 B/op	      50 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=OMText-10            	     597	    974777 ns/op	    8324 B/op	      50 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=OMText-10            	     595	    977084 ns/op	    8809 B/op	      51 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromProto-10         	     716	    812894 ns/op	   80207 B/op	    2256 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromProto-10         	     708	    822204 ns/op	   80278 B/op	    2256 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromProto-10         	     468	   1121788 ns/op	   82869 B/op	    2267 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=PromText-10           	     859	    663310 ns/op	    6291 B/op	      40 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=PromText-10           	     831	    786976 ns/op	    6116 B/op	      41 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=PromText-10           	     715	    905300 ns/op	    6840 B/op	      45 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=OMText-10             	     534	   1078825 ns/op	    8738 B/op	      55 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=OMText-10             	     514	   1031454 ns/op	    9011 B/op	      57 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=OMText-10             	     586	   1081051 ns/op	    8551 B/op	      52 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=PromProto-10          	     685	    873897 ns/op	  119648 B/op	      59 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=PromProto-10          	     552	    910258 ns/op	  119874 B/op	      66 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=false/data=1Fam2000Gauges/fmt=PromProto-10          	     680	    867189 ns/op	  118848 B/op	      59 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=PromText-10          	     516	   1132341 ns/op	    8876 B/op	      56 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=PromText-10          	     536	   1078256 ns/op	    8462 B/op	      54 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=PromText-10          	     510	   1136974 ns/op	    8795 B/op	      56 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=OMText-10            	     480	   1327926 ns/op	    9378 B/op	      59 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=OMText-10            	     580	   1033621 ns/op	    8112 B/op	      52 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=OMText-10            	     565	   1156595 ns/op	    8278 B/op	      53 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=PromProto-10         	     579	   1016194 ns/op	   81520 B/op	    2262 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=PromProto-10         	     579	   1089587 ns/op	   80993 B/op	    2262 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=false/data=237FamsAllTypes/fmt=PromProto-10         	     663	    898401 ns/op	   80261 B/op	    2259 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromText-10            	     775	    903634 ns/op	    6854 B/op	      43 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromText-10            	     777	    747252 ns/op	    6822 B/op	      42 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromText-10            	     849	    685619 ns/op	    6481 B/op	      40 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=OMText-10              	     858	    674362 ns/op	    6483 B/op	      41 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=OMText-10              	     820	    680060 ns/op	    6700 B/op	      42 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=OMText-10              	     854	    706427 ns/op	    6505 B/op	      41 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromProto-10           	     642	    869680 ns/op	  119829 B/op	      61 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromProto-10           	     638	   1026311 ns/op	  119761 B/op	      61 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromProto-10           	     722	    877325 ns/op	  118416 B/op	      58 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromText-10           	     530	   1072334 ns/op	   10127 B/op	      55 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromText-10           	     552	   1075898 ns/op	    8837 B/op	      53 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromText-10           	     546	   1075014 ns/op	    9059 B/op	      53 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=OMText-10             	     547	   1065822 ns/op	    8946 B/op	      54 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=OMText-10             	     549	   1068959 ns/op	    9018 B/op	      54 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=OMText-10             	     549	   1066611 ns/op	    9021 B/op	      54 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromProto-10          	     654	    890071 ns/op	   81205 B/op	    2259 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromProto-10          	     654	    893481 ns/op	   80834 B/op	    2259 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromProto-10          	     646	    893906 ns/op	   80874 B/op	    2259 allocs/op
BenchmarkScrapeLoopAppend_HistogramsWithExemplars/appV2=false-10                                                              	     391	   1499972 ns/op	  146815 B/op	    2481 allocs/op
BenchmarkScrapeLoopAppend_HistogramsWithExemplars/appV2=false-10                                                              	     396	   1490392 ns/op	  146851 B/op	    2480 allocs/op
BenchmarkScrapeLoopAppend_HistogramsWithExemplars/appV2=false-10                                                              	     394	   1493240 ns/op	  145689 B/op	    2480 allocs/op
BenchmarkScrapeLoopAppend_HistogramsWithExemplars/appV2=true-10                                                               	     388	   1514843 ns/op	  146048 B/op	    2483 allocs/op
BenchmarkScrapeLoopAppend_HistogramsWithExemplars/appV2=true-10                                                               	     384	   1518606 ns/op	  146025 B/op	    2483 allocs/op
BenchmarkScrapeLoopAppend_HistogramsWithExemplars/appV2=true-10                                                               	     386	   1526047 ns/op	  145973 B/op	    2483 allocs/op
PASS
ok  	github.com/prometheus/prometheus/scrape	89.640s

@bwplotka
Copy link
Copy Markdown
Member

bwplotka commented Feb 5, 2026

I think you tried to compare metadata Wal feature false to true, right? We don't change metadata to wal feature. We change general metadata parsing which is always happening.

What we want instead is to do this benchmark (you can focus test on "appV2=true/appendMetadataToWAL=true/") on current main (lets call this "ref"). Then do the same on your pr ("pr").

Then do "benchstat ref.txt pr.txt" which will aggregate result and give concrete % of more or less time/allocs.

@bwplotka
Copy link
Copy Markdown
Member

bwplotka commented Feb 5, 2026

But btw great work on running those benchmarks so far! We just need to do 2 of them. We can also focus on text formarts

@mdxabu
Copy link
Copy Markdown
Contributor Author

mdxabu commented Feb 6, 2026

But btw great work on running those benchmarks so far! We just need to do 2 of them. We can also focus on text formarts

@bwplotka, What's next?

@bwplotka
Copy link
Copy Markdown
Member

bwplotka commented Feb 6, 2026

This: #18015 (comment)

You didn't compare results with correct thing. We need to know if this PR is making production slower and more expensive or not (and how much). Not across features, but vs main.

@mdxabu
Copy link
Copy Markdown
Contributor Author

mdxabu commented Feb 6, 2026

This: #18015 (comment)

You didn't compare results with correct thing. We need to know if this PR is making production slower and more expensive or not (and how much). Not across features, but vs main.

OMG, I miss this comment :)

@mdxabu
Copy link
Copy Markdown
Contributor Author

mdxabu commented Feb 6, 2026

@bwplotka
comparing main (ref) vs my PR branch, focused on appV2=true/appendMetadataToWAL=true/

fix-metadata-parser-issue-17900 branch test:

  -run '^$' -bench 'BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/' \
  -benchtime 5s -count 6 -cpu 2 -timeout 999m \
  | tee pr.txt

goos: darwin
goarch: arm64
pkg: github.com/prometheus/prometheus/scrape
cpu: Apple M4
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromText-2         	     16909	      352291 ns/op	      1903 B/op	        18 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromText-2         	     17098	      350657 ns/op	      1900 B/op	        18 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromText-2         	     16874	      354132 ns/op	      1904 B/op	        18 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromText-2         	     16364	      374176 ns/op	      1911 B/op	        18 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromText-2         	     17122	      350177 ns/op	      1900 B/op	        18 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromText-2         	     17038	      352023 ns/op	      1901 B/op	        18 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=OMText-2           	     16694	      356757 ns/op	      2053 B/op	        19 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=OMText-2           	     17104	    349901 ns/op	    2046 B/op	      19 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=OMText-2           	   17073	    350385 ns/op	    2058 B/op	      19 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=OMText-2           	   17060	    351408 ns/op	    2047 B/op	      19 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=OMText-2           	   17152	    348814 ns/op	    2046 B/op	      19 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=OMText-2           	   17160	    349224 ns/op	    2045 B/op	      19 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromProto-2        	   14394	    417031 ns/op	  113500 B/op	      34 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromProto-2        	   14341	    417361 ns/op	  113211 B/op	      34 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromProto-2        	   14391	    417076 ns/op	  113071 B/op	      34 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromProto-2        	   14373	    417275 ns/op	  113108 B/op	      34 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromProto-2        	   14432	    416611 ns/op	  113311 B/op	      34 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromProto-2        	   14299	    419323 ns/op	  113101 B/op	      34 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromText-2        	   10000	    558449 ns/op	    2351 B/op	      19 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromText-2        	   10000	    558987 ns/op	    2305 B/op	      19 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromText-2        	   10000	    561156 ns/op	    2305 B/op	      19 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromText-2        	   10000	    562643 ns/op	    2305 B/op	      19 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromText-2        	   10000	    566354 ns/op	    2300 B/op	      19 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromText-2        	    9684	    580355 ns/op	    2317 B/op	      20 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=OMText-2          	   10000	    560465 ns/op	    2452 B/op	      20 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=OMText-2          	   10000	    556911 ns/op	    2445 B/op	      20 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=OMText-2          	   10000	    560034 ns/op	    2451 B/op	      20 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=OMText-2          	   10000	    557110 ns/op	    2451 B/op	      20 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=OMText-2          	   10000	    559547 ns/op	    2440 B/op	      20 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=OMText-2          	   10000	    557722 ns/op	    2446 B/op	      20 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromProto-2       	   12750	    471129 ns/op	   75618 B/op	    2237 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromProto-2       	   12631	    475416 ns/op	   75543 B/op	    2237 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromProto-2       	   12528	    481341 ns/op	   75577 B/op	    2237 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromProto-2       	   12535	    479042 ns/op	   75546 B/op	    2237 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromProto-2       	   12430	    482494 ns/op	   75547 B/op	    2237 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromProto-2       	   12470	    481050 ns/op	   75547 B/op	    2237 allocs/op
PASS
ok  	github.com/prometheus/prometheus/scrape	211.835s

and main branch test:

prometheus git:(main) ✗ go test ./scrape/... \
  -run '^$' -bench 'BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/' \
  -benchtime 5s -count 6 -cpu 2 -timeout 999m \
  | tee ref.txt
goos: darwin
goarch: arm64
pkg: github.com/prometheus/prometheus/scrape
cpu: Apple M4
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromText-2         	     16962	      354186 ns/op	      1898 B/op	        18 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromText-2         	     17000	      354179 ns/op	      1869 B/op	        18 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromText-2         	     16880	      355321 ns/op	      1871 B/op	        18 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromText-2         	     16822	      356385 ns/op	      1872 B/op	        18 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromText-2         	     17002	      352800 ns/op	      1869 B/op	        18 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromText-2         	     16935	      354706 ns/op	      1870 B/op	        18 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=OMText-2           	     16963	      352972 ns/op	      2017 B/op	        19 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=OMText-2           	     16848	      355143 ns/op	      2018 B/op	        19 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=OMText-2           	     17223	      348823 ns/op	      2036 B/op	        19 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=OMText-2           	     17066	      351159 ns/op	      2015 B/op	        19 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=OMText-2           	     17086	    352236 ns/op	    2014 B/op	      19 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=OMText-2           	   17082	    351376 ns/op	    2014 B/op	      19 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromProto-2        	   14428	    415670 ns/op	  113351 B/op	      34 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromProto-2        	   14508	    413213 ns/op	  113244 B/op	      34 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromProto-2        	   14535	    412796 ns/op	  113128 B/op	      34 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromProto-2        	   14487	    414426 ns/op	  113200 B/op	      34 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromProto-2        	   14266	    426050 ns/op	  113183 B/op	      34 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromProto-2        	   14229	    419736 ns/op	  113088 B/op	      34 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromText-2        	   10000	    556116 ns/op	    2311 B/op	      19 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromText-2        	   10000	    558226 ns/op	    2311 B/op	      19 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromText-2        	   10000	    558056 ns/op	    2265 B/op	      19 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromText-2        	   10000	    558895 ns/op	    2265 B/op	      19 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromText-2        	   10000	    558343 ns/op	    2265 B/op	      19 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromText-2        	   10000	    561440 ns/op	    2265 B/op	      19 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=OMText-2          	   10000	    564762 ns/op	    2412 B/op	      20 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=OMText-2          	   10000	    566926 ns/op	    2411 B/op	      20 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=OMText-2          	   10000	    570699 ns/op	    2411 B/op	      20 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=OMText-2          	   10000	    573050 ns/op	    2411 B/op	      20 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=OMText-2          	    9104	    572278 ns/op	    2448 B/op	      20 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=OMText-2          	   10000	    564982 ns/op	    2411 B/op	      20 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromProto-2       	   13141	    456710 ns/op	   75591 B/op	    2237 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromProto-2       	   13108	    458794 ns/op	   75584 B/op	    2237 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromProto-2       	   13120	    456688 ns/op	   75549 B/op	    2237 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromProto-2       	   13052	    460352 ns/op	   75585 B/op	    2237 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromProto-2       	   13056	    459160 ns/op	   75533 B/op	    2237 allocs/op
BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromProto-2       	   13087	    458082 ns/op	   75537 B/op	    2237 allocs/op
PASS
ok  	github.com/prometheus/prometheus/scrape	212.221s

and for benchstat ref.txt pr.txt:

prometheus git:(fix-metadata-parser-issue-17900) ✗ benchstat ref.txt pr.txt
goos: darwin
goarch: arm64
pkg: github.com/prometheus/prometheus/scrape
cpu: Apple M4
                                                                                                           │   ref.txt   │              pr.txt               │
                                                                                                           │   sec/op    │   sec/op     vs base              │
ScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromText-2     354.4µ ± 1%   352.2µ ± 6%       ~ (p=0.093 n=6)
ScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=OMText-2       351.8µ ± 1%   350.1µ ± 2%       ~ (p=0.394 n=6)
ScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromProto-2    415.0µ ± 3%   417.2µ ± 1%       ~ (p=0.394 n=6)
ScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromText-2    558.3µ ± 1%   561.9µ ± 3%  +0.65% (p=0.026 n=6)
ScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=OMText-2      568.8µ ± 1%   558.6µ ± 0%  -1.79% (p=0.002 n=6)
ScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromProto-2   458.4µ ± 0%   480.0µ ± 2%  +4.71% (p=0.002 n=6)
geomean                                                                                                      442.8µ        444.9µ       +0.47%

                                                                                                           │   ref.txt    │               pr.txt               │
                                                                                                           │     B/op     │     B/op      vs base              │
ScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromText-2     1.827Ki ± 1%   1.857Ki ± 0%  +1.68% (p=0.002 n=6)
ScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=OMText-2       1.969Ki ± 1%   1.999Ki ± 1%  +1.51% (p=0.002 n=6)
ScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromProto-2    110.5Ki ± 0%   110.5Ki ± 0%       ~ (p=0.937 n=6)
ScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromText-2    2.212Ki ± 2%   2.251Ki ± 2%       ~ (p=0.136 n=6)
ScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=OMText-2      2.354Ki ± 2%   2.391Ki ± 0%  +1.56% (p=0.013 n=6)
ScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromProto-2   73.80Ki ± 0%   73.78Ki ± 0%       ~ (p=0.900 n=6)
geomean                                                                                                      7.312Ki        7.390Ki       +1.07%

                                                                                                           │   ref.txt   │               pr.txt                │
                                                                                                           │  allocs/op  │  allocs/op   vs base                │
ScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromText-2      18.00 ± 0%    18.00 ± 0%       ~ (p=1.000 n=6) ¹
ScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=OMText-2        19.00 ± 0%    19.00 ± 0%       ~ (p=1.000 n=6) ¹
ScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=1Fam2000Gauges/fmt=PromProto-2     34.00 ± 0%    34.00 ± 0%       ~ (p=1.000 n=6) ¹
ScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromText-2     19.00 ± 0%    19.00 ± 5%       ~ (p=1.000 n=6)
ScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=OMText-2       20.00 ± 0%    20.00 ± 0%       ~ (p=1.000 n=6) ¹
ScrapeLoopAppend/withStorage=true/appV2=true/appendMetadataToWAL=true/data=237FamsAllTypes/fmt=PromProto-2   2.237k ± 0%   2.237k ± 0%       ~ (p=1.000 n=6) ¹
geomean                                                                                                       46.33         46.33       +0.00%
¹ all samples are equal

+0.57% geomean time, +1.14% geomean memory, zero new allocations. The PromProto path is essentially unaffected. The small overhead comes from the metadata validation that cross-checks series against their declared metric family type in text-based parsers.

@mdxabu mdxabu requested a review from bwplotka February 6, 2026 14:51
@mdxabu
Copy link
Copy Markdown
Contributor Author

mdxabu commented Feb 10, 2026

@bwplotka, can you review my PR now?

@beorn7
Copy link
Copy Markdown
Member

beorn7 commented Mar 31, 2026

Hello from the bug scrub!

@bwplotka what do you think about @mdxabu's latest additions to this PR?

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.

textparse: Move scrape.isSeriesPartOfFamily to text parser and optimize

3 participants