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

Function TestLimiter_AssertMaxSeriesPerMetric

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

Source from the content-addressed store, hash-verified

248}
249
250func TestLimiter_AssertMaxSeriesPerMetric(t *testing.T) {
251 tests := map[string]struct {
252 maxLocalSeriesPerMetric int
253 maxGlobalSeriesPerMetric int
254 ringReplicationFactor int
255 ringIngesterCount int
256 shardByAllLabels bool
257 series int
258 expected error
259 }{
260 "both local and global limit are disabled": {
261 maxLocalSeriesPerMetric: 0,
262 maxGlobalSeriesPerMetric: 0,
263 ringReplicationFactor: 1,
264 ringIngesterCount: 1,
265 shardByAllLabels: false,
266 series: 100,
267 expected: nil,
268 },
269 "current number of series is below the limit": {
270 maxLocalSeriesPerMetric: 0,
271 maxGlobalSeriesPerMetric: 1000,
272 ringReplicationFactor: 3,
273 ringIngesterCount: 10,
274 shardByAllLabels: true,
275 series: 299,
276 expected: nil,
277 },
278 "current number of series is above the limit": {
279 maxLocalSeriesPerMetric: 0,
280 maxGlobalSeriesPerMetric: 1000,
281 ringReplicationFactor: 3,
282 ringIngesterCount: 10,
283 shardByAllLabels: true,
284 series: 300,
285 expected: errMaxSeriesPerMetricLimitExceeded,
286 },
287 }
288
289 for testName, testData := range tests {
290
291 t.Run(testName, func(t *testing.T) {
292 // Mock the ring
293 ring := &ringCountMock{}
294 ring.On("HealthyInstancesCount").Return(testData.ringIngesterCount)
295 ring.On("ZonesCount").Return(1)
296
297 // Mock limits
298 limits := validation.NewOverrides(validation.Limits{
299 MaxLocalSeriesPerMetric: testData.maxLocalSeriesPerMetric,
300 MaxGlobalSeriesPerMetric: testData.maxGlobalSeriesPerMetric,
301 }, nil)
302
303 limiter := NewLimiter(limits, ring, util.ShardingStrategyDefault, testData.shardByAllLabels, testData.ringReplicationFactor, false, "")
304 actual := limiter.AssertMaxSeriesPerMetric("test", testData.series)
305
306 assert.Equal(t, testData.expected, actual)
307 })

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