MCPcopy Index your code
hub / github.com/cortexproject/cortex / TestIngesterUserLimitExceeded

Function TestIngesterUserLimitExceeded

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

Source from the content-addressed store, hash-verified

752}
753
754func TestIngesterUserLimitExceeded(t *testing.T) {
755 limits := defaultLimitsTestConfig()
756 limits.EnableNativeHistograms = true
757 limits.MaxLocalSeriesPerUser = 1
758 limits.MaxLocalNativeHistogramSeriesPerUser = 1
759 limits.MaxLocalMetricsWithMetadataPerUser = 1
760
761 userID := "1"
762 // Series
763 labels1 := labels.FromStrings(labels.MetricName, "testmetric", "foo", "bar")
764 sample1 := cortexpb.Sample{
765 TimestampMs: 0,
766 Value: 1,
767 }
768 sample2 := cortexpb.Sample{
769 TimestampMs: 1,
770 Value: 2,
771 }
772 labels3 := labels.FromStrings(labels.MetricName, "testmetric", "foo", "biz")
773 sample3 := cortexpb.Sample{
774 TimestampMs: 1,
775 Value: 3,
776 }
777 // Metadata
778 metadata1 := &cortexpb.MetricMetadata{MetricFamilyName: "testmetric", Help: "a help for testmetric", Type: cortexpb.COUNTER}
779 metadata2 := &cortexpb.MetricMetadata{MetricFamilyName: "testmetric2", Help: "a help for testmetric2", Type: cortexpb.COUNTER}
780
781 dir := t.TempDir()
782
783 chunksDir := filepath.Join(dir, "chunks")
784 blocksDir := filepath.Join(dir, "blocks")
785 require.NoError(t, os.Mkdir(chunksDir, os.ModePerm))
786 require.NoError(t, os.Mkdir(blocksDir, os.ModePerm))
787
788 blocksIngesterGenerator := func(reg prometheus.Registerer) *Ingester {
789 ing, err := prepareIngesterWithBlocksStorageAndLimits(t, defaultIngesterTestConfig(t), limits, nil, blocksDir, reg)
790 require.NoError(t, err)
791 require.NoError(t, services.StartAndAwaitRunning(context.Background(), ing))
792 // Wait until it's ACTIVE
793 test.Poll(t, time.Second, ring.ACTIVE, func() any {
794 return ing.lifecycler.GetState()
795 })
796
797 return ing
798 }
799
800 tests := []string{"blocks"}
801 for i, ingGenerator := range []func(reg prometheus.Registerer) *Ingester{blocksIngesterGenerator} {
802 t.Run(tests[i], func(t *testing.T) {
803 reg := prometheus.NewRegistry()
804 ing := ingGenerator(reg)
805
806 // Append only one series and one metadata first, expect no error.
807 ctx := user.InjectOrgID(context.Background(), userID)
808 _, err := ing.Push(ctx, cortexpb.ToWriteRequest([]labels.Labels{labels1}, []cortexpb.Sample{sample1}, []*cortexpb.MetricMetadata{metadata1}, nil, cortexpb.API))
809 require.NoError(t, err)
810
811 testLimits := func(reg prometheus.Gatherer) {

Callers

nothing calls this directly

Calls 15

StartAndAwaitRunningFunction · 0.92
PollFunction · 0.92
ToWriteRequestFunction · 0.92
StopAndAwaitTerminatedFunction · 0.92
defaultLimitsTestConfigFunction · 0.85
wrapWithUserFunction · 0.85
makeLimitErrorFunction · 0.85
runTestQueryFunction · 0.85

Tested by

no test coverage detected