(b *testing.B, limits validation.Limits, errorsExpected bool)
| 2685 | } |
| 2686 | |
| 2687 | func benchmarkIngesterPush(b *testing.B, limits validation.Limits, errorsExpected bool) { |
| 2688 | registry := prometheus.NewRegistry() |
| 2689 | ctx := user.InjectOrgID(context.Background(), userID) |
| 2690 | |
| 2691 | // Create a mocked ingester |
| 2692 | cfg := defaultIngesterTestConfig(b) |
| 2693 | cfg.LifecyclerConfig.JoinAfter = 0 |
| 2694 | |
| 2695 | ingester, err := prepareIngesterWithBlocksStorage(b, cfg, registry) |
| 2696 | require.NoError(b, err) |
| 2697 | require.NoError(b, services.StartAndAwaitRunning(context.Background(), ingester)) |
| 2698 | defer services.StopAndAwaitTerminated(context.Background(), ingester) //nolint:errcheck |
| 2699 | |
| 2700 | // Wait until the ingester is ACTIVE |
| 2701 | test.Poll(b, 100*time.Millisecond, ring.ACTIVE, func() any { |
| 2702 | return ingester.lifecycler.GetState() |
| 2703 | }) |
| 2704 | |
| 2705 | // Push a single time series to set the TSDB min time. |
| 2706 | metricLabelAdapters := []cortexpb.LabelAdapter{{Name: labels.MetricName, Value: "test"}} |
| 2707 | metricLabels := cortexpb.FromLabelAdaptersToLabels(metricLabelAdapters) |
| 2708 | startTime := util.TimeToMillis(time.Now()) |
| 2709 | |
| 2710 | currTimeReq := cortexpb.ToWriteRequest( |
| 2711 | []labels.Labels{metricLabels}, |
| 2712 | []cortexpb.Sample{{Value: 1, TimestampMs: startTime}}, |
| 2713 | nil, |
| 2714 | nil, |
| 2715 | cortexpb.API) |
| 2716 | _, err = ingester.Push(ctx, currTimeReq) |
| 2717 | require.NoError(b, err) |
| 2718 | |
| 2719 | const ( |
| 2720 | series = 10000 |
| 2721 | samples = 10 |
| 2722 | ) |
| 2723 | |
| 2724 | allLabels, allSamples := benchmarkData(series) |
| 2725 | |
| 2726 | for iter := 0; b.Loop(); iter++ { |
| 2727 | // Bump the timestamp on each of our test samples each time round the loop |
| 2728 | for j := range samples { |
| 2729 | for i := range allSamples { |
| 2730 | allSamples[i].TimestampMs = startTime + int64(iter*samples+j+1) |
| 2731 | } |
| 2732 | _, err := ingester.Push(ctx, cortexpb.ToWriteRequest(allLabels, allSamples, nil, nil, cortexpb.API)) |
| 2733 | if !errorsExpected { |
| 2734 | require.NoError(b, err) |
| 2735 | } |
| 2736 | } |
| 2737 | } |
| 2738 | } |
| 2739 | |
| 2740 | func verifyErrorString(tb testing.TB, err error, expectedErr string) { |
| 2741 | if err == nil || !strings.Contains(err.Error(), expectedErr) { |
no test coverage detected