(t *testing.T)
| 664 | } |
| 665 | |
| 666 | func 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) |
nothing calls this directly
no test coverage detected