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

Function TestPushRace

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

Source from the content-addressed store, hash-verified

664}
665
666func TestPushRace(t *testing.T) {
667 cfg := defaultIngesterTestConfig(t)
668 l := defaultLimitsTestConfig()
669 l.EnableNativeHistograms = true
670 cfg.LabelsStringInterningEnabled = true
671 cfg.LifecyclerConfig.JoinAfter = 0
672
673 l.LimitsPerLabelSet = []validation.LimitsPerLabelSet{
674 {
675 LabelSet: labels.FromMap(map[string]string{
676 labels.MetricName: "foo",
677 }),
678 Limits: validation.LimitsPerLabelSetEntry{
679 MaxSeries: 10e10,
680 },
681 },
682 {
683 // Default partition.
684 LabelSet: labels.EmptyLabels(),
685 Limits: validation.LimitsPerLabelSetEntry{
686 MaxSeries: 10e10,
687 },
688 },
689 }
690
691 dir := t.TempDir()
692 blocksDir := filepath.Join(dir, "blocks")
693 require.NoError(t, os.Mkdir(blocksDir, os.ModePerm))
694
695 ing, err := prepareIngesterWithBlocksStorageAndLimits(t, cfg, l, nil, blocksDir, prometheus.NewRegistry())
696 require.NoError(t, err)
697 defer services.StopAndAwaitTerminated(context.Background(), ing) //nolint:errcheck
698 require.NoError(t, services.StartAndAwaitRunning(context.Background(), ing))
699 // Wait until it's ACTIVE
700 test.Poll(t, time.Second, ring.ACTIVE, func() any {
701 return ing.lifecycler.GetState()
702 })
703
704 ctx := user.InjectOrgID(context.Background(), userID)
705 sample1 := cortexpb.Sample{
706 TimestampMs: 0,
707 Value: 1,
708 }
709
710 concurrentRequest := 100
711 numberOfSeries := 100
712 wg := sync.WaitGroup{}
713 wg.Add(numberOfSeries * concurrentRequest)
714 for k := range numberOfSeries {
715 for range concurrentRequest {
716 go func() {
717 defer wg.Done()
718 _, err := ing.Push(ctx, cortexpb.ToWriteRequest([]labels.Labels{labels.FromStrings(labels.MetricName, "foo", "userId", userID, "k", strconv.Itoa(k))}, []cortexpb.Sample{sample1}, nil, nil, cortexpb.API))
719 require.NoError(t, err)
720
721 // Go to default partition.
722 _, err = ing.Push(ctx, cortexpb.ToWriteRequest([]labels.Labels{labels.FromStrings(labels.MetricName, "bar", "userId", userID, "k", strconv.Itoa(k))}, []cortexpb.Sample{sample1}, nil, nil, cortexpb.API))
723 require.NoError(t, err)

Callers

nothing calls this directly

Calls 15

StopAndAwaitTerminatedFunction · 0.92
StartAndAwaitRunningFunction · 0.92
PollFunction · 0.92
ToWriteRequestFunction · 0.92
defaultLimitsTestConfigFunction · 0.85
JoinMethod · 0.80
DoneMethod · 0.80
getTSDBMethod · 0.80
HeadMethod · 0.80
PostingsMethod · 0.80

Tested by

no test coverage detected