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

Code before:

				// Check basic storage stats.
				stats := s.Head().Stats(model.MetricNameLabel, 2000)
				require.Equal(t, tc.expectedSamplesLen, int(stats.NumSeries))

				// Check exemplars.
				eq, err := s.ExemplarQuerier(t.Context())
				require.NoError(t, err)

				er, err := eq.Select(math.MinInt64, math.MaxInt64, nil)
				require.NoError(t, err)

				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


Review comment (suggestion):
```suggestion
// Benchmark compares append function run across 5 dimensions:
```

Code after:

				// Check basic storage stats.
				stats := s.Head().Stats(model.MetricNameLabel, 2000)
				require.Equal(t, tc.expectedSamplesLen, int(stats.NumSeries))

				// Check exemplars.
				eq, err := s.ExemplarQuerier(t.Context())
				require.NoError(t, err)

				er, err := eq.Select(math.MinInt64, math.MaxInt64, nil)
				require.NoError(t, err)

				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