Repository: prometheus/prometheus
File: scrape/scrape_test.go (Go)

Code before:
				if tc.testExemplars != nil {
					tc.testExemplars(t, er)
				} else {
					// Expect no exemplars.
					require.Empty(t, er, "%v is not empty", er)
				}
			})
		}
	}
}

// BenchmarkScrapeLoopAppend benchmarks scrape appends for typical cases.
//
// Benchmark compares append function run across 4 dimensions:
// * `withStorage`: without storage isolates the benchmark to the scrape loop append code. With storage is an
// integration benchmark with the TSDB head appender code. For acceptance criteria run with storage, without for debugging.
// * `appV2`: appender V1 or V2.
// * `appendMetadataToWAL`: metadata-wal-records feature enabled or not (problematic feature we might need to change
// soon, see https://github.com/prometheus/prometheus/issues/15911.
// * `data`: different sizes of metrics scraped e.g. one big gauge metric family
//  with a thousand series and more realistic scenario with common types.
// * `fmt`: different scrape formats which will benchmark different parsers e.g.
//  promtext, omtext and promproto.
//
// NOTE: withStorage=true uses sync.Pool buffers which is heavily non-deterministic and shared across go routines.
// As a results, it's recommended to run dimensions you want to compare with in separate go tool invocations e.g.
// Recommended CLI invocation(s):
/*
	# Acceptance: With storage with V1 and V2 in separate process:
	export bench=appendV1 && go test ./scrape/... \
		-run '^$' -bench '^BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/$' \
		-benchtime 2s -count 6 -cpu 2 -timeout 999m \
		| tee ${bench}.txt

	export bench=appendV2 && go test ./scrape/... \
		-run '^$' -bench '^BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/$' \
		-benchtime 2s -count 6 -cpu 2 -timeout 999m \
		| tee ${bench}.txt

	# For debugging scrape overheads:
	export bench=appendNoStorage && go test ./scrape/... \
		-run '^$' -bench '^BenchmarkScrapeLoopAppend/withStorage=false/$' \
		-benchtime 2s -count 6 -cpu 2 -timeout 999m \
		| tee ${bench}.txt
*/
func BenchmarkScrapeLoopAppend(b *testing.B) {
	for _, withStorage := range []bool{false, true} {
		for _, appV2 := range []bool{false, true} {
			for _, appendMetadataToWAL := range []bool{false, true} {
				for _, data := range []struct {
					name         string

Review comment (suggestion):
Do you mean the following? Not sure what the e.g. at the end is referring to.
```suggestion
// As a result, it's recommended to run dimensions you want to compare with in e.g. separate go tool invocations.
```

Code after:
				if tc.testExemplars != nil {
					tc.testExemplars(t, er)
				} else {
					// Expect no exemplars.
					require.Empty(t, er, "%v is not empty", er)
				}
			})
		}
	}
}

// BenchmarkScrapeLoopAppend benchmarks scrape appends for typical cases.
//
// Benchmark compares append function run across 5 dimensions:
// * `withStorage`: without storage isolates the benchmark to the scrape loop append code. With storage is an
// integration benchmark with the TSDB head appender code. For acceptance criteria run with storage, without for debugging.
// * `appV2`: appender V1 or V2.
// * `appendMetadataToWAL`: metadata-wal-records feature enabled or not (problematic feature we might need to change
// soon, see https://github.com/prometheus/prometheus/issues/15911.
// * `data`: different sizes of metrics scraped e.g. one big gauge metric family
//  with a thousand series and more realistic scenario with common types.
// * `fmt`: different scrape formats which will benchmark different parsers e.g.
//  promtext, omtext and promproto.
//
// NOTE: withStorage=true uses sync.Pool buffers which is heavily non-deterministic and shared across go routines.
// As a result, it's recommended to run dimensions you want to compare with in e.g. separate go tool invocations.
// Recommended CLI invocation(s):
/*
	# Acceptance: With storage with V1 and V2 in separate process:
	export bench=appendV1 && go test ./scrape/... \
		-run '^$' -bench '^BenchmarkScrapeLoopAppend/withStorage=true/appV2=false/$' \
		-benchtime 2s -count 6 -cpu 2 -timeout 999m \
		| tee ${bench}.txt

	export bench=appendV2 && go test ./scrape/... \
		-run '^$' -bench '^BenchmarkScrapeLoopAppend/withStorage=true/appV2=true/$' \
		-benchtime 2s -count 6 -cpu 2 -timeout 999m \
		| tee ${bench}.txt

	# For debugging scrape overheads:
	export bench=appendNoStorage && go test ./scrape/... \
		-run '^$' -bench '^BenchmarkScrapeLoopAppend/withStorage=false/$' \
		-benchtime 2s -count 6 -cpu 2 -timeout 999m \
		| tee ${bench}.txt
*/
func BenchmarkScrapeLoopAppend(b *testing.B) {
	for _, withStorage := range []bool{false, true} {
		for _, appV2 := range []bool{false, true} {
			for _, appendMetadataToWAL := range []bool{false, true} {
				for _, data := range []struct {
					name         string