(b *testing.B, samplesCount, seriesCount int)
| 4254 | } |
| 4255 | |
| 4256 | func benchmarkQueryStream(b *testing.B, samplesCount, seriesCount int) { |
| 4257 | cfg := defaultIngesterTestConfig(b) |
| 4258 | |
| 4259 | // Create ingester. |
| 4260 | i, err := prepareIngesterWithBlocksStorage(b, cfg, prometheus.NewRegistry()) |
| 4261 | require.NoError(b, err) |
| 4262 | require.NoError(b, services.StartAndAwaitRunning(context.Background(), i)) |
| 4263 | defer services.StopAndAwaitTerminated(context.Background(), i) //nolint:errcheck |
| 4264 | |
| 4265 | // Wait until it's ACTIVE. |
| 4266 | test.Poll(b, 1*time.Second, ring.ACTIVE, func() any { |
| 4267 | return i.lifecycler.GetState() |
| 4268 | }) |
| 4269 | |
| 4270 | // Push series. |
| 4271 | ctx := user.InjectOrgID(context.Background(), userID) |
| 4272 | |
| 4273 | samples := make([]cortexpb.Sample, 0, samplesCount) |
| 4274 | |
| 4275 | for i := range samplesCount { |
| 4276 | samples = append(samples, cortexpb.Sample{ |
| 4277 | Value: float64(i), |
| 4278 | TimestampMs: int64(i), |
| 4279 | }) |
| 4280 | } |
| 4281 | |
| 4282 | for s := range seriesCount { |
| 4283 | _, err = i.Push(ctx, writeRequestSingleSeries(labels.FromStrings("__name__", "foo", "l", strconv.Itoa(s)), samples)) |
| 4284 | require.NoError(b, err) |
| 4285 | } |
| 4286 | |
| 4287 | req := &client.QueryRequest{ |
| 4288 | StartTimestampMs: 0, |
| 4289 | EndTimestampMs: int64(samplesCount + 1), |
| 4290 | |
| 4291 | Matchers: []*client.LabelMatcher{{ |
| 4292 | Type: client.EQUAL, |
| 4293 | Name: model.MetricNameLabel, |
| 4294 | Value: "foo", |
| 4295 | }}, |
| 4296 | } |
| 4297 | |
| 4298 | mockStream := &mockQueryStreamServer{ctx: ctx} |
| 4299 | |
| 4300 | b.ReportAllocs() |
| 4301 | |
| 4302 | for b.Loop() { |
| 4303 | err := i.QueryStream(req, mockStream) |
| 4304 | require.NoError(b, err) |
| 4305 | } |
| 4306 | } |
| 4307 | |
| 4308 | func mockWriteRequest(t *testing.T, lbls labels.Labels, value float64, timestampMs int64) (*cortexpb.WriteRequest, *client.QueryStreamResponse) { |
| 4309 | samples := []cortexpb.Sample{ |
no test coverage detected