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

Function TestLimiter_AssertMaxSeriesPerUser

pkg/ingester/limiter_test.go:371–430  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

369}
370
371func TestLimiter_AssertMaxSeriesPerUser(t *testing.T) {
372 tests := map[string]struct {
373 maxLocalSeriesPerUser int
374 maxGlobalSeriesPerUser int
375 ringReplicationFactor int
376 ringIngesterCount int
377 shardByAllLabels bool
378 series int
379 expected error
380 }{
381 "both local and global limit are disabled": {
382 maxLocalSeriesPerUser: 0,
383 maxGlobalSeriesPerUser: 0,
384 ringReplicationFactor: 1,
385 ringIngesterCount: 1,
386 shardByAllLabels: false,
387 series: 100,
388 expected: nil,
389 },
390 "current number of series is below the limit": {
391 maxLocalSeriesPerUser: 0,
392 maxGlobalSeriesPerUser: 1000,
393 ringReplicationFactor: 3,
394 ringIngesterCount: 10,
395 shardByAllLabels: true,
396 series: 299,
397 expected: nil,
398 },
399 "current number of series is above the limit": {
400 maxLocalSeriesPerUser: 0,
401 maxGlobalSeriesPerUser: 1000,
402 ringReplicationFactor: 3,
403 ringIngesterCount: 10,
404 shardByAllLabels: true,
405 series: 300,
406 expected: errMaxSeriesPerUserLimitExceeded,
407 },
408 }
409
410 for testName, testData := range tests {
411
412 t.Run(testName, func(t *testing.T) {
413 // Mock the ring
414 ring := &ringCountMock{}
415 ring.On("HealthyInstancesCount").Return(testData.ringIngesterCount)
416 ring.On("ZonesCount").Return(1)
417
418 // Mock limits
419 limits := validation.NewOverrides(validation.Limits{
420 MaxLocalSeriesPerUser: testData.maxLocalSeriesPerUser,
421 MaxGlobalSeriesPerUser: testData.maxGlobalSeriesPerUser,
422 }, nil)
423
424 limiter := NewLimiter(limits, ring, util.ShardingStrategyDefault, testData.shardByAllLabels, testData.ringReplicationFactor, false, "")
425 actual := limiter.AssertMaxSeriesPerUser("test", testData.series)
426
427 assert.Equal(t, testData.expected, actual)
428 })

Callers

nothing calls this directly

Calls 5

NewOverridesFunction · 0.92
NewLimiterFunction · 0.85
RunMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected