MCPcopy Create free account
hub / github.com/cortexproject/cortex / TestIngester_inflightPushRequests

Function TestIngester_inflightPushRequests

pkg/ingester/ingester_test.go:6821–6877  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6819}
6820
6821func 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

Callers

nothing calls this directly

Calls 11

StartAndAwaitRunningFunction · 0.92
StopAndAwaitTerminatedFunction · 0.92
PollFunction · 0.92
generateSamplesForLabelFunction · 0.85
DoneMethod · 0.80
PushMethod · 0.65
EqualMethod · 0.65
GetStateMethod · 0.45
WaitMethod · 0.45

Tested by

no test coverage detected