diff --git a/lib/streamaggr/streamaggr_timing_test.go b/lib/streamaggr/streamaggr_timing_test.go index f69d2aa17..25712ce1c 100644 --- a/lib/streamaggr/streamaggr_timing_test.go +++ b/lib/streamaggr/streamaggr_timing_test.go @@ -37,42 +37,38 @@ func benchmarkAggregatorsPush(b *testing.B, output string) { without: [job] outputs: [%q] `, output) - pushCalls := 0 - pushFunc := func(tss []prompbmarshal.TimeSeries) { - pushCalls++ - if pushCalls > 1 { - panic(fmt.Errorf("pushFunc is expected to be called exactly once at MustStop")) - } - } + pushFunc := func(tss []prompbmarshal.TimeSeries) {} a, err := newAggregatorsFromData([]byte(config), pushFunc, 0) if err != nil { b.Fatalf("unexpected error when initializing aggregators: %s", err) } defer a.MustStop() + const loops = 5 + b.ReportAllocs() - b.SetBytes(int64(len(benchSeries))) + b.SetBytes(int64(len(benchSeries) * loops)) b.RunParallel(func(pb *testing.PB) { var matchIdxs []byte for pb.Next() { - matchIdxs = a.Push(benchSeries, matchIdxs) + for i := 0; i < loops; i++ { + matchIdxs = a.Push(benchSeries, matchIdxs) + } } }) } -func newBenchSeries(seriesCount, samplesPerSeries int) []prompbmarshal.TimeSeries { - a := make([]string, seriesCount*samplesPerSeries) - for i := 0; i < samplesPerSeries; i++ { - for j := 0; j < seriesCount; j++ { - s := fmt.Sprintf(`http_requests_total{path="/foo/%d",job="foo",instance="bar"} %d`, j, i*10) - a = append(a, s) - } +func newBenchSeries(seriesCount int) []prompbmarshal.TimeSeries { + a := make([]string, seriesCount) + for j := 0; j < seriesCount; j++ { + s := fmt.Sprintf(`http_requests_total{path="/foo/%d",job="foo",instance="bar",pod="pod-123232312",namespace="kube-foo-bar",node="node-123-3434-443",`+ + `some_other_label="foo-bar-baz",environment="prod",label1="value1",label2="value2",label3="value3"} %d`, j, j*1000) + a = append(a, s) } metrics := strings.Join(a, "\n") return mustParsePromMetrics(metrics) } -const seriesCount = 10000 -const samplesPerSeries = 10 +const seriesCount = 10_000 -var benchSeries = newBenchSeries(seriesCount, samplesPerSeries) +var benchSeries = newBenchSeries(seriesCount)