ronantakizawa/codereview-bench huggingface dataset:
Repository: prometheus/prometheus
File: model/labels/labels_slicelabels_test.go (Go)

Code before:
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build slicelabels

package labels

var expectedSizeOfLabels = []uint64{ // Values must line up with testCaseLabels.
	72,
	0,
	97,
	326,
	327,
	549,
}

var expectedByteSize = []uint64{ // Values must line up with testCaseLabels.
	72,
	0,
	97,
	326,
	327,
	549,
}


Review comment (suggestion):
Not crucial, but I would probably have assigned this to `expectedSizeOfLabels` with a note that they are identical.

Code after:
// Copyright 2025 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build slicelabels

package labels

var expectedSizeOfLabels = []uint64{ // Values must line up with testCaseLabels.
	72,
	0,
	97,
	326,
	327,
	549,
}

var expectedByteSize = expectedSizeOfLabels // They are identical
Repository: prometheus/prometheus
File: storage/remote/queue_manager_test.go (Go)

Code before:
	}
}

func (c *TestWriteClient) expectMetadataForBatch(metadata []record.RefMetadata, series []record.RefSeries, samples []record.RefSample, exemplars []record.RefExemplar, histograms []record.RefHistogramSample, floatHistograms []record.RefFloatHistogramSample) {
	c.mtx.Lock()
	defer c.mtx.Unlock()

	c.expectedMetadata = map[string][]prompb.MetricMetadata{}
	c.receivedMetadata = map[string][]prompb.MetricMetadata{}

	// Collect refs that have data in this batch
	refsWithData := make(map[chunks.HeadSeriesRef]bool)
	for _, s := range samples {
		refsWithData[s.Ref] = true
	}
	for _, e := range exemplars {
		refsWithData[e.Ref] = true
	}
	for _, h := range histograms {
		refsWithData[h.Ref] = true
	}
	for _, fh := range floatHistograms {
		refsWithData[fh.Ref] = true
	}

	// Only expect metadata for series that have data in this batch
	for _, m := range metadata {
		if !refsWithData[m.Ref] {
			continue
		}
		tsID := getSeriesIDFromRef(series[m.Ref])
		c.expectedMetadata[tsID] = append(c.expectedMetadata[tsID], prompb.MetricMetadata{
			MetricFamilyName: tsID,
			Type:             prompb.FromMetadataType(record.ToMetricType(m.Type)),
			Help:             m.Help,
			Unit:             m.Unit,
		})
	}
}

func deepLen[M any](ms ...map[string][]M) int {
	l := 0
	for _, m := range ms {
		for _, v := range m {
			l += len(v)
		}
	}
	return l
}

func (c *TestWriteClient) waitForExpectedData(tb testing.TB, timeout time.Duration) {

Review comment (performance):
```suggestion
	// Only expect metadata for series that have data in this batch.
```

Code after:
	}
}

func (c *TestWriteClient) expectMetadataForBatch(metadata []record.RefMetadata, series []record.RefSeries, samples []record.RefSample, exemplars []record.RefExemplar, histograms []record.RefHistogramSample, floatHistograms []record.RefFloatHistogramSample) {
	c.mtx.Lock()
	defer c.mtx.Unlock()

	c.expectedMetadata = map[string][]prompb.MetricMetadata{}
	c.receivedMetadata = map[string][]prompb.MetricMetadata{}

	// Collect refs that have data in this batch.
	refsWithData := make(map[chunks.HeadSeriesRef]struct{})
	for _, s := range samples {
		refsWithData[s.Ref] = struct{}{}
	}
	for _, e := range exemplars {
		refsWithData[e.Ref] = struct{}{}
	}
	for _, h := range histograms {
		refsWithData[h.Ref] = struct{}{}
	}
	for _, fh := range floatHistograms {
		refsWithData[fh.Ref] = struct{}{}
	}

	// Only expect metadata for series that have data in this batch.
	for _, m := range metadata {
		if _, ok := refsWithData[m.Ref]; !ok {
			continue
		}
		tsID := getSeriesIDFromRef(series[m.Ref])
		c.expectedMetadata[tsID] = append(c.expectedMetadata[tsID], prompb.MetricMetadata{
			MetricFamilyName: tsID,
			Type:             prompb.FromMetadataType(record.ToMetricType(m.Type)),
			Help:             m.Help,
			Unit:             m.Unit,
		})
	}
}

func deepLen[M any](ms ...map[string][]M) int {
	l := 0
	for _, m := range ms {
		for _, v := range m {
			l += len(v)
		}
	}
	return l
}

func (c *TestWriteClient) waitForExpectedData(tb testing.TB, timeout time.Duration) {
Repository: prometheus/prometheus
File: storage/remote/otlptranslator/prometheusremotewrite/helper_test.go (Go)

Code before:
					Value: defaultScope.schemaURL,
				},
				{
					Name:  "otel_scope_version",
					Value: defaultScope.version,
				},
				{
					Name:  "otel_scope_attr1",
					Value: "value1",
				},
				{
					Name:  "otel_scope_attr2",
					Value: "value2",
				},
			},
		},
	}
	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			settings := Settings{
				PromoteResourceAttributes: NewPromoteResourceAttributes(config.OTLPConfig{
					PromoteAllResourceAttributes: tc.promoteAllResourceAttributes,
					PromoteResourceAttributes:    tc.promoteResourceAttributes,
					IgnoreResourceAttributes:     tc.ignoreResourceAttributes,
				}),
				PromoteScopeMetadata: tc.convertScope,
			}
			lbls := createAttributes(resource, attrs, tc.scope, settings, tc.ignoreAttrs, false, model.MetricNameLabel, "test_metric")

			require.ElementsMatch(t, lbls, tc.expectedLabels)
		})
	}
}

func Test_convertTimeStamp(t *testing.T) {
	tests := []struct {
		name string
		arg  pcommon.Timestamp
		want int64
	}{
		{"zero", 0, 0},
		{"1ms", 1_000_000, 1},
		{"1s", pcommon.Timestamp(time.Unix(1, 0).UnixNano()), 1000},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			got := convertTimeStamp(tt.arg)
			require.Equal(t, tt.want, got)
		})
	}
}

Review comment (suggestion):
nit: consider adjusting in other tests as well

```suggestion
				PromoteScopeMetadata: tc.promoteScope,
```

same in `TestPrometheusConverter_AddSummaryDataPoints` and `TestPrometheusConverter_AddHistogramDataPoints`

Code after:
					Value: defaultScope.schemaURL,
				},
				{
					Name:  "otel_scope_version",
					Value: defaultScope.version,
				},
				{
					Name:  "otel_scope_attr1",
					Value: "value1",
				},
				{
					Name:  "otel_scope_attr2",
					Value: "value2",
				},
			},
		},
	}
	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			settings := Settings{
				PromoteResourceAttributes: NewPromoteResourceAttributes(config.OTLPConfig{
					PromoteAllResourceAttributes: tc.promoteAllResourceAttributes,
					PromoteResourceAttributes:    tc.promoteResourceAttributes,
					IgnoreResourceAttributes:     tc.ignoreResourceAttributes,
				}),
				PromoteScopeMetadata: tc.promoteScope,
			}
			lbls := createAttributes(resource, attrs, tc.scope, settings, tc.ignoreAttrs, false, model.MetricNameLabel, "test_metric")

			require.ElementsMatch(t, lbls, tc.expectedLabels)
		})
	}
}

func Test_convertTimeStamp(t *testing.T) {
	tests := []struct {
		name string
		arg  pcommon.Timestamp
		want int64
	}{
		{"zero", 0, 0},
		{"1ms", 1_000_000, 1},
		{"1s", pcommon.Timestamp(time.Unix(1, 0).UnixNano()), 1000},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			got := convertTimeStamp(tt.arg)
			require.Equal(t, tt.want, got)
		})
	}
}
Repository: prometheus/prometheus
File: scripts/check_release_notes.sh (Shell)

Code before:
#!/bin/bash

set -e

echo "Checking the release-notes block in the PR description"

content=$(cat | tr -d '\r' | sed -n '/```release-notes/,/```/p' | grep -v '```' | grep -v '^[[:space:]]*$' || true)

if [[ -z "$content" ]]; then
    echo "Error: release-notes block empty or not found, see template at https://github.com/prometheus/prometheus/blob/main/.github/PULL_REQUEST_TEMPLATE.md?plain=1"
    exit 1
fi

if [[ "$content" == "NONE" ]]; then
    echo "Release note check passed, content is NONE"
    exit 0
fi

prefixes='FEATURE|ENHANCEMENT|PERF|BUGFIX|SECURITY|CHANGE'

while IFS= read -r line; do
  if [[ ! $line =~ ^\[($prefixes)\] ]]; then
    echo "Error: Invalid prefix in '$line'"
    # Convert pipes to brackets
    echo "Content should be NONE or entries should start with one of: [${prefixes//|/] [}]"
    exit 1
  fi
done <<<"$content"

Review comment (bug):
I recommend against `set -e` since bash does silent exits on errors. This makes it hard to debug.

```suggestion
set -u -o pipefail
```

Then make sure we have good error checking within the script.

Code after:
#!/usr/bin/env bash

set -u -o pipefail

echo "Checking the release-notes block in the PR description"

content=$(cat | tr -d '\r' | sed -n '/```release-notes/,/```/p' | grep -v '```' | grep -v '^[[:space:]]*$')

if [[ -z "$content" ]]; then
    echo "Error: release-notes block empty or not found, see template at https://github.com/prometheus/prometheus/blob/main/.github/PULL_REQUEST_TEMPLATE.md?plain=1"
    exit 1
fi

if [[ "$content" == "NONE" ]]; then
    echo "Release note check passed, content is NONE"
    exit 0
fi

prefixes='FEATURE|ENHANCEMENT|PERF|BUGFIX|SECURITY|CHANGE'

while IFS= read -r line; do
  if [[ ! $line =~ ^\[($prefixes)\] ]]; then
    echo "Error: Invalid prefix in '$line'"
    # Convert pipes to brackets
    echo "Content should be NONE or entries should start with one of: [${prefixes//|/] [}]"
    exit 1
  fi
done <<<"$content"
Repository: prometheus/prometheus
File: storage/remote/otlptranslator/prometheusremotewrite/number_data_points.go (Go)

Code before:
		)
		if err != nil {
			return err
		}
		sample := &prompb.Sample{
			// convert ns to ms
			Timestamp: convertTimeStamp(pt.Timestamp()),
		}
		switch pt.ValueType() {
		case pmetric.NumberDataPointValueTypeInt:
			sample.Value = float64(pt.IntValue())
		case pmetric.NumberDataPointValueTypeDouble:
			sample.Value = pt.DoubleValue()
		}
		if pt.Flags().NoRecordedValue() {
			sample.Value = math.Float64frombits(value.StaleNaN)
		}

		c.addSample(sample, labels)
	}

	return nil
}

func (c *PrometheusConverter) addSumNumberDataPoints(ctx context.Context, dataPoints pmetric.NumberDataPointSlice,
	resource pcommon.Resource, _ pmetric.Metric, settings Settings, metadata prompb.MetricMetadata, scope scope,
) error {
	for x := 0; x < dataPoints.Len(); x++ {
		if err := c.everyN.checkContext(ctx); err != nil {
			return err
		}

		pt := dataPoints.At(x)
		lbls, err := createAttributes(
			resource,
			pt.Attributes(),
			scope,
			settings,
			nil,
			true,
			metadata,
			model.MetricNameLabel,
			metadata.MetricFamilyName,
		)
		if err != nil {
			return err
		}
		sample := &prompb.Sample{
			// convert ns to ms
			Timestamp: convertTimeStamp(pt.Timestamp()),
		}

Review comment (suggestion):
Just remove the unused argument please, it's dead code :)
```suggestion
	resource pcommon.Resource, settings Settings, metadata prompb.MetricMetadata, scope scope,
```

Code after:
		)
		if err != nil {
			return err
		}
		sample := &prompb.Sample{
			// convert ns to ms
			Timestamp: convertTimeStamp(pt.Timestamp()),
		}
		switch pt.ValueType() {
		case pmetric.NumberDataPointValueTypeInt:
			sample.Value = float64(pt.IntValue())
		case pmetric.NumberDataPointValueTypeDouble:
			sample.Value = pt.DoubleValue()
		}
		if pt.Flags().NoRecordedValue() {
			sample.Value = math.Float64frombits(value.StaleNaN)
		}

		c.addSample(sample, labels)
	}

	return nil
}

func (c *PrometheusConverter) addSumNumberDataPoints(ctx context.Context, dataPoints pmetric.NumberDataPointSlice,
	resource pcommon.Resource, settings Settings, metadata prompb.MetricMetadata, scope scope,
) error {
	for x := 0; x < dataPoints.Len(); x++ {
		if err := c.everyN.checkContext(ctx); err != nil {
			return err
		}

		pt := dataPoints.At(x)
		lbls, err := createAttributes(
			resource,
			pt.Attributes(),
			scope,
			settings,
			nil,
			true,
			metadata,
			model.MetricNameLabel,
			metadata.MetricFamilyName,
		)
		if err != nil {
			return err
		}
		sample := &prompb.Sample{
			// convert ns to ms
			Timestamp: convertTimeStamp(pt.Timestamp()),
		}
Repository: prometheus/prometheus
File: promql/promqltest/test_test.go (Go)

Code before:
			expectedError: `error in eval http_requests (line 12): invalid expect lines, multiple expect fail lines are not allowed`,
		},
		"instant query with string literal": {
			input: `
				eval instant at 50m ("Foo")
					expect string Foo
			`,
		},
		"instant query with string literal with leading space": {
			input: `
				eval instant at 50m (" Foo")
					expect string  Foo
			`,
		},
		"instant query with string literal with empty string": {
			input: `
				eval instant at 50m ("")
					expect string
			`,
		},
		"instant query with empty string literal": {
			input: `
				eval instant at 50m ("Foo")
					expect string
			`,
			expectedError: `error in eval ("Foo") (line 2): expected empty string but got Foo`,
		},
		"instant query with error string literal": {
			input: `
				eval instant at 50m ("Foo")
					expect string Bar
			`,
			expectedError: `error in eval ("Foo") (line 2): expected string Bar but got Foo`,
		},
		"instant query with range result": {
			input: `
				load 10s
  					some_metric{env="a"} 1+1x5

				eval instant at 1m some_metric[1m]
					expect range vector from 10s to 1m step 10s
  					some_metric{env="a"} 2 3 4 5 6
  					some_metric{env="b"} 4 6 8 10 12
			`,
			expectedError: `error in eval some_metric[1m] (line 5): expected metric {__name__="some_metric", env="b"} not found`,
		},
		"instant query with invalid range result": {
			input: `
				load 10s
  					some_metric{env="a"} 1+1x5


Review comment (suggestion):
It might be clearer to quote the strings here, for example:

```suggestion
			expectedError: `error in eval ("Foo") (line 2): expected "" but got "Foo"`,
```

Code after:
			expectedError: `error in eval http_requests (line 12): invalid expect lines, multiple expect fail lines are not allowed`,
		},
		"instant query with string literal": {
			input: `
				eval instant at 50m ("Foo")
					expect string "Foo"
			`,
		},
		"instant query with string literal with leading space": {
			input: `
				eval instant at 50m (" Foo")
					expect string " Foo"
			`,
		},
		"instant query with string literal with trailing space": {
			input: `
				eval instant at 50m ("Foo ")
					expect string "Foo "
			`,
		},
		"instant query with string literal as space": {
			input: `
				eval instant at 50m (" ")
					expect string " "
			`,
		},
		"instant query with string literal with empty string": {
			input: `
				eval instant at 50m ("")
					expect string
			`,
			expectedError: `error in eval ("") (line 3): expected string literal not valid - a quoted string literal is required`,
		},
		"instant query with string literal with correctly quoted empty string": {
			input: `
				eval instant at 50m ("")
					expect string ""
			`,
		},
		"instant query with string literal - not quoted": {
			input: `
				eval instant at 50m ("Foo")
					expect string Foo
			`,
			expectedError: `error in eval ("Foo") (line 3): expected string literal not valid - check that the string is correctly quoted`,
		},
		"instant query with empty string literal": {
			input: `
				eval instant at 50m ("Foo")
					expect string ""
			`,
Repository: prometheus/prometheus
File: promql/bench_test.go (Go)

Code before:
	defer stor.Close()
	opts := promql.EngineOpts{
		Logger:     nil,
		Reg:        nil,
		MaxSamples: 50000000,
		Timeout:    100 * time.Second,
	}
	engine := promqltest.NewTestEngineWithOpts(b, opts)

	const interval = 10000 // 10s interval.
	// A day of data plus 10k steps.
	numIntervals := 8640 + 10000

	err := setupJoinQueryTestData(stor, engine, interval, numIntervals, 1000)
	if err != nil {
		b.Fatal(err)
	}

	cases := []benchCase{
		{
			expr:  `rpc_request_success_total + rpc_request_error_total`,
			steps: 10000,
		},
		{
			expr:  `rpc_request_success_total + ON (job, instance) GROUP_LEFT rpc_request_error_total`,
			steps: 10000,
		},
		{
			expr:  `rpc_request_success_total AND rpc_request_error_total{instance=~"0.*"}`,
			steps: 10000,
		},
		{
			expr:  `rpc_request_success_total OR rpc_request_error_total{instance=~"0.*"}`,
			steps: 10000,
		},
		{
			expr:  `rpc_request_success_total UNLESS rpc_request_error_total{instance=~"0.*"}`,
			steps: 10000,
		},
	}

	for _, c := range cases {
		name := fmt.Sprintf("expr=%s,steps=%d", c.expr, c.steps)
		b.Run(name, func(b *testing.B) {
			ctx := context.Background()
			b.ReportAllocs()
			for range b.N {
				qry, err := engine.NewRangeQuery(
					ctx, stor, nil, c.expr,
					time.Unix(int64((numIntervals-c.steps)*10), 0),
					time.Unix(int64(numIntervals*10), 0), time.Second*10)

Review comment (suggestion):
```suggestion
	
	// A day of data plus 10k steps.
```

Code after:
				res := qry.Exec(ctx)
				if res.Err != nil {
					b.Fatal(res.Err)
				}
				qry.Close()
			}
		})
	}
}

func BenchmarkJoinQuery(b *testing.B) {
	stor := teststorage.New(b)
	stor.DisableCompactions() // Don't want auto-compaction disrupting timings.
	defer stor.Close()

	opts := promql.EngineOpts{
		Logger:     nil,
		Reg:        nil,
		MaxSamples: 50000000,
		Timeout:    100 * time.Second,
	}
	engine := promqltest.NewTestEngineWithOpts(b, opts)

	const interval = 10000 // 10s interval.

	// A day of data plus 10k steps.
	numIntervals := 8640 + 10000

	require.NoError(b, setupJoinQueryTestData(stor, engine, interval, numIntervals, 1000))

	for _, c := range []benchCase{
		{
			expr:  `rpc_request_success_total + rpc_request_error_total`,
			steps: 10000,
		},
		{
			expr:  `rpc_request_success_total + ON (job, instance) GROUP_LEFT rpc_request_error_total`,
			steps: 10000,
		},
		{
			expr:  `rpc_request_success_total AND rpc_request_error_total{instance=~"0.*"}`, // 0.* keeps 1/16 of UUID values
			steps: 10000,
		},
		{
			expr:  `rpc_request_success_total OR rpc_request_error_total{instance=~"0.*"}`, // 0.* keeps 1/16 of UUID values
			steps: 10000,
		},
		{
			expr:  `rpc_request_success_total UNLESS rpc_request_error_total{instance=~"0.*"}`, // 0.* keeps 1/16 of UUID values
			steps: 10000,
		},
Repository: prometheus/prometheus
File: promql/bench_test.go (Go)

Code before:
				}
				qry.Close()
			}
		})
	}
}

func BenchmarkJoinQuery(b *testing.B) {
	stor := teststorage.New(b)
	stor.DisableCompactions() // Don't want auto-compaction disrupting timings.
	defer stor.Close()
	opts := promql.EngineOpts{
		Logger:     nil,
		Reg:        nil,
		MaxSamples: 50000000,
		Timeout:    100 * time.Second,
	}
	engine := promqltest.NewTestEngineWithOpts(b, opts)

	const interval = 10000 // 10s interval.
	// A day of data plus 10k steps.
	numIntervals := 8640 + 10000

	err := setupJoinQueryTestData(stor, engine, interval, numIntervals, 1000)
	if err != nil {
		b.Fatal(err)
	}

	cases := []benchCase{
		{
			expr:  `rpc_request_success_total + rpc_request_error_total`,
			steps: 10000,
		},
		{
			expr:  `rpc_request_success_total + ON (job, instance) GROUP_LEFT rpc_request_error_total`,
			steps: 10000,
		},
		{
			expr:  `rpc_request_success_total AND rpc_request_error_total{instance=~"0.*"}`,
			steps: 10000,
		},
		{
			expr:  `rpc_request_success_total OR rpc_request_error_total{instance=~"0.*"}`,
			steps: 10000,
		},
		{
			expr:  `rpc_request_success_total UNLESS rpc_request_error_total{instance=~"0.*"}`,
			steps: 10000,
		},
	}


Review comment (suggestion):
(just opinionated new lines, feel free to ignore, but helps me typically 🙃 )

```suggestion
	
	opts := promql.EngineOpts{
```

Code after:
			ctx := context.Background()
			b.ReportAllocs()
			for i := 0; i < b.N; i++ {
				qry, err := engine.NewRangeQuery(
					ctx, stor, nil, c.expr,
					time.Unix(int64((numIntervals-c.steps)*10), 0),
					time.Unix(int64(numIntervals*10), 0), time.Second*10)
				if err != nil {
					b.Fatal(err)
				}
				res := qry.Exec(ctx)
				if res.Err != nil {
					b.Fatal(res.Err)
				}
				qry.Close()
			}
		})
	}
}

func BenchmarkJoinQuery(b *testing.B) {
	stor := teststorage.New(b)
	stor.DisableCompactions() // Don't want auto-compaction disrupting timings.
	defer stor.Close()

	opts := promql.EngineOpts{
		Logger:     nil,
		Reg:        nil,
		MaxSamples: 50000000,
		Timeout:    100 * time.Second,
	}
	engine := promqltest.NewTestEngineWithOpts(b, opts)

	const interval = 10000 // 10s interval.

	// A day of data plus 10k steps.
	numIntervals := 8640 + 10000

	require.NoError(b, setupJoinQueryTestData(stor, engine, interval, numIntervals, 1000))

	for _, c := range []benchCase{
		{
			expr:  `rpc_request_success_total + rpc_request_error_total`,
			steps: 10000,
		},
		{
			expr:  `rpc_request_success_total + ON (job, instance) GROUP_LEFT rpc_request_error_total`,
			steps: 10000,
		},
		{
			expr:  `rpc_request_success_total AND rpc_request_error_total{instance=~"0.*"}`, // 0.* keeps 1/16 of UUID values
Repository: prometheus/prometheus
File: promql/bench_test.go (Go)

Code before:
				}
				qry.Close()
			}
		})
	}
}

func BenchmarkJoinQuery(b *testing.B) {
	stor := teststorage.New(b)
	stor.DisableCompactions() // Don't want auto-compaction disrupting timings.
	defer stor.Close()
	opts := promql.EngineOpts{
		Logger:     nil,
		Reg:        nil,
		MaxSamples: 50000000,
		Timeout:    100 * time.Second,
	}
	engine := promqltest.NewTestEngineWithOpts(b, opts)

	const interval = 10000 // 10s interval.
	// A day of data plus 10k steps.
	numIntervals := 8640 + 10000

	err := setupJoinQueryTestData(stor, engine, interval, numIntervals, 1000)
	if err != nil {
		b.Fatal(err)
	}

	cases := []benchCase{
		{
			expr:  `rpc_request_success_total + rpc_request_error_total`,
			steps: 10000,
		},
		{
			expr:  `rpc_request_success_total + ON (job, instance) GROUP_LEFT rpc_request_error_total`,
			steps: 10000,
		},
		{
			expr:  `rpc_request_success_total AND rpc_request_error_total{instance=~"0.*"}`,
			steps: 10000,
		},
		{
			expr:  `rpc_request_success_total OR rpc_request_error_total{instance=~"0.*"}`,
			steps: 10000,
		},
		{
			expr:  `rpc_request_success_total UNLESS rpc_request_error_total{instance=~"0.*"}`,
			steps: 10000,
		},
	}


Review comment (suggestion):
```suggestion
	require.NoError(b, setupJoinQueryTestData(stor, engine, interval, numIntervals, 1000))
```

Code after:
			ctx := context.Background()
			b.ReportAllocs()
			for i := 0; i < b.N; i++ {
				qry, err := engine.NewRangeQuery(
					ctx, stor, nil, c.expr,
					time.Unix(int64((numIntervals-c.steps)*10), 0),
					time.Unix(int64(numIntervals*10), 0), time.Second*10)
				if err != nil {
					b.Fatal(err)
				}
				res := qry.Exec(ctx)
				if res.Err != nil {
					b.Fatal(res.Err)
				}
				qry.Close()
			}
		})
	}
}

func BenchmarkJoinQuery(b *testing.B) {
	stor := teststorage.New(b)
	stor.DisableCompactions() // Don't want auto-compaction disrupting timings.
	defer stor.Close()

	opts := promql.EngineOpts{
		Logger:     nil,
		Reg:        nil,
		MaxSamples: 50000000,
		Timeout:    100 * time.Second,
	}
	engine := promqltest.NewTestEngineWithOpts(b, opts)

	const interval = 10000 // 10s interval.

	// A day of data plus 10k steps.
	numIntervals := 8640 + 10000

	require.NoError(b, setupJoinQueryTestData(stor, engine, interval, numIntervals, 1000))

	for _, c := range []benchCase{
		{
			expr:  `rpc_request_success_total + rpc_request_error_total`,
			steps: 10000,
		},
		{
			expr:  `rpc_request_success_total + ON (job, instance) GROUP_LEFT rpc_request_error_total`,
			steps: 10000,
		},
		{
			expr:  `rpc_request_success_total AND rpc_request_error_total{instance=~"0.*"}`, // 0.* keeps 1/16 of UUID values