(t *testing.T)
| 308 | } |
| 309 | } |
| 310 | func TestLimiter_AssertMaxMetadataPerMetric(t *testing.T) { |
| 311 | tests := map[string]struct { |
| 312 | maxLocalMetadataPerMetric int |
| 313 | maxGlobalMetadataPerMetric int |
| 314 | ringReplicationFactor int |
| 315 | ringIngesterCount int |
| 316 | shardByAllLabels bool |
| 317 | metadata int |
| 318 | expected error |
| 319 | }{ |
| 320 | "both local and global limit are disabled": { |
| 321 | maxLocalMetadataPerMetric: 0, |
| 322 | maxGlobalMetadataPerMetric: 0, |
| 323 | ringReplicationFactor: 1, |
| 324 | ringIngesterCount: 1, |
| 325 | shardByAllLabels: false, |
| 326 | metadata: 100, |
| 327 | expected: nil, |
| 328 | }, |
| 329 | "current number of metadata is below the limit": { |
| 330 | maxLocalMetadataPerMetric: 0, |
| 331 | maxGlobalMetadataPerMetric: 1000, |
| 332 | ringReplicationFactor: 3, |
| 333 | ringIngesterCount: 10, |
| 334 | shardByAllLabels: true, |
| 335 | metadata: 299, |
| 336 | expected: nil, |
| 337 | }, |
| 338 | "current number of metadata is above the limit": { |
| 339 | maxLocalMetadataPerMetric: 0, |
| 340 | maxGlobalMetadataPerMetric: 1000, |
| 341 | ringReplicationFactor: 3, |
| 342 | ringIngesterCount: 10, |
| 343 | shardByAllLabels: true, |
| 344 | metadata: 300, |
| 345 | expected: errMaxMetadataPerMetricLimitExceeded, |
| 346 | }, |
| 347 | } |
| 348 | |
| 349 | for testName, testData := range tests { |
| 350 | |
| 351 | t.Run(testName, func(t *testing.T) { |
| 352 | // Mock the ring |
| 353 | ring := &ringCountMock{} |
| 354 | ring.On("HealthyInstancesCount").Return(testData.ringIngesterCount) |
| 355 | ring.On("ZonesCount").Return(1) |
| 356 | |
| 357 | // Mock limits |
| 358 | limits := validation.NewOverrides(validation.Limits{ |
| 359 | MaxLocalMetadataPerMetric: testData.maxLocalMetadataPerMetric, |
| 360 | MaxGlobalMetadataPerMetric: testData.maxGlobalMetadataPerMetric, |
| 361 | }, nil) |
| 362 | |
| 363 | limiter := NewLimiter(limits, ring, util.ShardingStrategyDefault, testData.shardByAllLabels, testData.ringReplicationFactor, false, "") |
| 364 | actual := limiter.AssertMaxMetadataPerMetric("test", testData.metadata) |
| 365 | |
| 366 | assert.Equal(t, testData.expected, actual) |
| 367 | }) |
nothing calls this directly
no test coverage detected