(t *testing.T)
| 6819 | } |
| 6820 | |
| 6821 | func TestIngester_inflightPushRequests(t *testing.T) { |
| 6822 | limits := InstanceLimits{MaxInflightPushRequests: 1} |
| 6823 | |
| 6824 | // Create a mocked ingester |
| 6825 | cfg := defaultIngesterTestConfig(t) |
| 6826 | cfg.InstanceLimitsFn = func() *InstanceLimits { return &limits } |
| 6827 | cfg.LifecyclerConfig.JoinAfter = 0 |
| 6828 | |
| 6829 | reg := prometheus.NewRegistry() |
| 6830 | i, err := prepareIngesterWithBlocksStorage(t, cfg, reg) |
| 6831 | require.NoError(t, err) |
| 6832 | require.NoError(t, services.StartAndAwaitRunning(context.Background(), i)) |
| 6833 | defer services.StopAndAwaitTerminated(context.Background(), i) //nolint:errcheck |
| 6834 | |
| 6835 | // Wait until the ingester is ACTIVE |
| 6836 | test.Poll(t, 100*time.Millisecond, ring.ACTIVE, func() any { |
| 6837 | return i.lifecycler.GetState() |
| 6838 | }) |
| 6839 | |
| 6840 | ctx := user.InjectOrgID(context.Background(), "test") |
| 6841 | |
| 6842 | startCh := make(chan struct{}) |
| 6843 | |
| 6844 | g, ctx := errgroup.WithContext(ctx) |
| 6845 | g.Go(func() error { |
| 6846 | count := 150000 |
| 6847 | req := generateSamplesForLabel(labels.FromStrings(labels.MetricName, fmt.Sprintf("real-%d", count)), count, 1) |
| 6848 | // Signal that we're going to do the real push now. |
| 6849 | close(startCh) |
| 6850 | |
| 6851 | _, err := i.Push(ctx, req) |
| 6852 | return err |
| 6853 | }) |
| 6854 | |
| 6855 | g.Go(func() error { |
| 6856 | select { |
| 6857 | case <-ctx.Done(): |
| 6858 | // failed to setup |
| 6859 | case <-startCh: |
| 6860 | // we can start the test. |
| 6861 | } |
| 6862 | |
| 6863 | time.Sleep(10 * time.Millisecond) // Give first goroutine a chance to start pushing... |
| 6864 | req := generateSamplesForLabel(labels.FromStrings(labels.MetricName, "testcase"), 1024, 1) |
| 6865 | |
| 6866 | _, err := i.Push(ctx, req) |
| 6867 | require.Equal(t, errTooManyInflightPushRequests, err) |
| 6868 | require.NoError(t, testutil.GatherAndCompare(reg, bytes.NewBufferString(` |
| 6869 | # HELP cortex_ingester_push_errors_total The total number of push errors per user. |
| 6870 | # TYPE cortex_ingester_push_errors_total counter |
| 6871 | cortex_ingester_push_errors_total{reason="tooManyInflightRequests",user="test"} 1 |
| 6872 | `), "cortex_ingester_push_errors_total")) |
| 6873 | return nil |
| 6874 | }) |
| 6875 | |
| 6876 | require.NoError(t, g.Wait()) |
| 6877 | } |
| 6878 |
nothing calls this directly
no test coverage detected