Skip to content

Commit 025e723

Browse files
kumanikfriedrichg
andauthored
Add ingester flag to customize message in limiter error messages (#5460)
* Add ingester flag to add admin contact details in limiter error messages Signed-off-by: Nikhil Kumar <[email protected]> * Rename flag to AdminLimitMessage Signed-off-by: Nikhil Kumar <[email protected]> * Fix CLI Flag in documentation Signed-off-by: Nikhil Kumar <[email protected]> * Fix Documentation Signed-off-by: Nikhil Kumar <[email protected]> * Changelog updated Signed-off-by: Nikhil Kumar <[email protected]> * Update CHANGELOG.md Signed-off-by: Friedrich Gonzalez <[email protected]> --------- Signed-off-by: Nikhil Kumar <[email protected]> Signed-off-by: Friedrich Gonzalez <[email protected]> Co-authored-by: Friedrich Gonzalez <[email protected]>
1 parent e52014e commit 025e723

File tree

6 files changed

+33
-17
lines changed

6 files changed

+33
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
## master / unreleased
4+
* [FEATURE] Ingester: added `-admin-limit-message` to customize the message contained in limit errors.#5460
45
* [CHANGE] AlertManager: include reason label in cortex_alertmanager_notifications_failed_total.#5409
56
* [CHANGE] Query: Set CORS Origin headers for Query API #5388
67
* [CHANGE] Updating prometheus/alertmanager from v0.25.0 to v0.25.1-0.20230505130626-263ca5c9438e. This includes the below changes. #5276

docs/configuration/config-file-reference.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2620,6 +2620,10 @@ instance_limits:
26202620
# max-global-series-per-metric limits.
26212621
# CLI flag: -ingester.ignore-series-limit-for-metric-names
26222622
[ignore_series_limit_for_metric_names: <string> | default = ""]
2623+
2624+
# Customize the message contained in limit errors
2625+
# CLI flag: -ingester.admin-limit-message
2626+
[admin_limit_message: <string> | default = "please contact administrator to raise it"]
26232627
```
26242628

26252629
### `ingester_client_config`

pkg/ingester/ingester.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ type Config struct {
124124

125125
// For testing, you can override the address and ID of this ingester.
126126
ingesterClientFactory func(addr string, cfg client.Config) (client.HealthAndIngesterClient, error)
127+
128+
// For admin contact details
129+
AdminLimitMessage string `yaml:"admin_limit_message"`
127130
}
128131

129132
// RegisterFlags adds the flags required to config this to the given FlagSet
@@ -144,6 +147,9 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
144147
f.Int64Var(&cfg.DefaultLimits.MaxInflightPushRequests, "ingester.instance-limits.max-inflight-push-requests", 0, "Max inflight push requests that this ingester can handle (across all tenants). Additional requests will be rejected. 0 = unlimited.")
145148

146149
f.StringVar(&cfg.IgnoreSeriesLimitForMetricNames, "ingester.ignore-series-limit-for-metric-names", "", "Comma-separated list of metric names, for which -ingester.max-series-per-metric and -ingester.max-global-series-per-metric limits will be ignored. Does not affect max-series-per-user or max-global-series-per-metric limits.")
150+
151+
f.StringVar(&cfg.AdminLimitMessage, "ingester.admin-limit-message", "please contact administrator to raise it", "Customize the message contained in limit errors")
152+
147153
}
148154

149155
func (cfg *Config) getIgnoreSeriesLimitForMetricNamesMap() map[string]struct{} {
@@ -653,7 +659,9 @@ func New(cfg Config, limits *validation.Overrides, registerer prometheus.Registe
653659
cfg.DistributorShardingStrategy,
654660
cfg.DistributorShardByAllLabels,
655661
cfg.LifecyclerConfig.RingConfig.ReplicationFactor,
656-
cfg.LifecyclerConfig.RingConfig.ZoneAwarenessEnabled)
662+
cfg.LifecyclerConfig.RingConfig.ZoneAwarenessEnabled,
663+
cfg.AdminLimitMessage,
664+
)
657665

658666
i.TSDBState.shipperIngesterID = i.lifecycler.ID
659667

pkg/ingester/limiter.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type Limiter struct {
3434
shuffleShardingEnabled bool
3535
shardByAllLabels bool
3636
zoneAwarenessEnabled bool
37+
AdminLimitMessage string
3738
}
3839

3940
// NewLimiter makes a new in-memory series limiter
@@ -44,6 +45,7 @@ func NewLimiter(
4445
shardByAllLabels bool,
4546
replicationFactor int,
4647
zoneAwarenessEnabled bool,
48+
AdminLimitMessage string,
4749
) *Limiter {
4850
return &Limiter{
4951
limits: limits,
@@ -52,6 +54,7 @@ func NewLimiter(
5254
shuffleShardingEnabled: shardingStrategy == util.ShardingStrategyShuffle,
5355
shardByAllLabels: shardByAllLabels,
5456
zoneAwarenessEnabled: zoneAwarenessEnabled,
57+
AdminLimitMessage: AdminLimitMessage,
5558
}
5659
}
5760

@@ -122,35 +125,35 @@ func (l *Limiter) formatMaxSeriesPerUserError(userID string) error {
122125
localLimit := l.limits.MaxLocalSeriesPerUser(userID)
123126
globalLimit := l.limits.MaxGlobalSeriesPerUser(userID)
124127

125-
return fmt.Errorf("per-user series limit of %d exceeded, please contact administrator to raise it (local limit: %d global limit: %d actual local limit: %d)",
126-
minNonZero(localLimit, globalLimit), localLimit, globalLimit, actualLimit)
128+
return fmt.Errorf("per-user series limit of %d exceeded, %s (local limit: %d global limit: %d actual local limit: %d)",
129+
minNonZero(localLimit, globalLimit), l.AdminLimitMessage, localLimit, globalLimit, actualLimit)
127130
}
128131

129132
func (l *Limiter) formatMaxSeriesPerMetricError(userID string) error {
130133
actualLimit := l.maxSeriesPerMetric(userID)
131134
localLimit := l.limits.MaxLocalSeriesPerMetric(userID)
132135
globalLimit := l.limits.MaxGlobalSeriesPerMetric(userID)
133136

134-
return fmt.Errorf("per-metric series limit of %d exceeded, please contact administrator to raise it (local limit: %d global limit: %d actual local limit: %d)",
135-
minNonZero(localLimit, globalLimit), localLimit, globalLimit, actualLimit)
137+
return fmt.Errorf("per-metric series limit of %d exceeded, %s (local limit: %d global limit: %d actual local limit: %d)",
138+
minNonZero(localLimit, globalLimit), l.AdminLimitMessage, localLimit, globalLimit, actualLimit)
136139
}
137140

138141
func (l *Limiter) formatMaxMetadataPerUserError(userID string) error {
139142
actualLimit := l.maxMetadataPerUser(userID)
140143
localLimit := l.limits.MaxLocalMetricsWithMetadataPerUser(userID)
141144
globalLimit := l.limits.MaxGlobalMetricsWithMetadataPerUser(userID)
142145

143-
return fmt.Errorf("per-user metric metadata limit of %d exceeded, please contact administrator to raise it (local limit: %d global limit: %d actual local limit: %d)",
144-
minNonZero(localLimit, globalLimit), localLimit, globalLimit, actualLimit)
146+
return fmt.Errorf("per-user metric metadata limit of %d exceeded, %s (local limit: %d global limit: %d actual local limit: %d)",
147+
minNonZero(localLimit, globalLimit), l.AdminLimitMessage, localLimit, globalLimit, actualLimit)
145148
}
146149

147150
func (l *Limiter) formatMaxMetadataPerMetricError(userID string) error {
148151
actualLimit := l.maxMetadataPerMetric(userID)
149152
localLimit := l.limits.MaxLocalMetadataPerMetric(userID)
150153
globalLimit := l.limits.MaxGlobalMetadataPerMetric(userID)
151154

152-
return fmt.Errorf("per-metric metadata limit of %d exceeded, please contact administrator to raise it (local limit: %d global limit: %d actual local limit: %d)",
153-
minNonZero(localLimit, globalLimit), localLimit, globalLimit, actualLimit)
155+
return fmt.Errorf("per-metric metadata limit of %d exceeded, %s (local limit: %d global limit: %d actual local limit: %d)",
156+
minNonZero(localLimit, globalLimit), l.AdminLimitMessage, localLimit, globalLimit, actualLimit)
154157
}
155158

156159
func (l *Limiter) maxSeriesPerMetric(userID string) int {

pkg/ingester/limiter_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,12 @@ func runLimiterMaxFunctionTest(
223223
require.NoError(t, err)
224224

225225
// Assert on default sharding strategy.
226-
limiter := NewLimiter(overrides, ring, util.ShardingStrategyDefault, testData.shardByAllLabels, testData.ringReplicationFactor, testData.ringZoneAwarenessEnabled)
226+
limiter := NewLimiter(overrides, ring, util.ShardingStrategyDefault, testData.shardByAllLabels, testData.ringReplicationFactor, testData.ringZoneAwarenessEnabled, "")
227227
actual := runMaxFn(limiter)
228228
assert.Equal(t, testData.expectedDefaultSharding, actual)
229229

230230
// Assert on shuffle sharding strategy.
231-
limiter = NewLimiter(overrides, ring, util.ShardingStrategyShuffle, testData.shardByAllLabels, testData.ringReplicationFactor, testData.ringZoneAwarenessEnabled)
231+
limiter = NewLimiter(overrides, ring, util.ShardingStrategyShuffle, testData.shardByAllLabels, testData.ringReplicationFactor, testData.ringZoneAwarenessEnabled, "")
232232
actual = runMaxFn(limiter)
233233
assert.Equal(t, testData.expectedShuffleSharding, actual)
234234
})
@@ -290,7 +290,7 @@ func TestLimiter_AssertMaxSeriesPerMetric(t *testing.T) {
290290
}, nil)
291291
require.NoError(t, err)
292292

293-
limiter := NewLimiter(limits, ring, util.ShardingStrategyDefault, testData.shardByAllLabels, testData.ringReplicationFactor, false)
293+
limiter := NewLimiter(limits, ring, util.ShardingStrategyDefault, testData.shardByAllLabels, testData.ringReplicationFactor, false, "")
294294
actual := limiter.AssertMaxSeriesPerMetric("test", testData.series)
295295

296296
assert.Equal(t, testData.expected, actual)
@@ -352,7 +352,7 @@ func TestLimiter_AssertMaxMetadataPerMetric(t *testing.T) {
352352
}, nil)
353353
require.NoError(t, err)
354354

355-
limiter := NewLimiter(limits, ring, util.ShardingStrategyDefault, testData.shardByAllLabels, testData.ringReplicationFactor, false)
355+
limiter := NewLimiter(limits, ring, util.ShardingStrategyDefault, testData.shardByAllLabels, testData.ringReplicationFactor, false, "")
356356
actual := limiter.AssertMaxMetadataPerMetric("test", testData.metadata)
357357

358358
assert.Equal(t, testData.expected, actual)
@@ -415,7 +415,7 @@ func TestLimiter_AssertMaxSeriesPerUser(t *testing.T) {
415415
}, nil)
416416
require.NoError(t, err)
417417

418-
limiter := NewLimiter(limits, ring, util.ShardingStrategyDefault, testData.shardByAllLabels, testData.ringReplicationFactor, false)
418+
limiter := NewLimiter(limits, ring, util.ShardingStrategyDefault, testData.shardByAllLabels, testData.ringReplicationFactor, false, "")
419419
actual := limiter.AssertMaxSeriesPerUser("test", testData.series)
420420

421421
assert.Equal(t, testData.expected, actual)
@@ -478,7 +478,7 @@ func TestLimiter_AssertMaxMetricsWithMetadataPerUser(t *testing.T) {
478478
}, nil)
479479
require.NoError(t, err)
480480

481-
limiter := NewLimiter(limits, ring, util.ShardingStrategyDefault, testData.shardByAllLabels, testData.ringReplicationFactor, false)
481+
limiter := NewLimiter(limits, ring, util.ShardingStrategyDefault, testData.shardByAllLabels, testData.ringReplicationFactor, false, "")
482482
actual := limiter.AssertMaxMetricsWithMetadataPerUser("test", testData.metadata)
483483

484484
assert.Equal(t, testData.expected, actual)
@@ -501,7 +501,7 @@ func TestLimiter_FormatError(t *testing.T) {
501501
}, nil)
502502
require.NoError(t, err)
503503

504-
limiter := NewLimiter(limits, ring, util.ShardingStrategyDefault, true, 3, false)
504+
limiter := NewLimiter(limits, ring, util.ShardingStrategyDefault, true, 3, false, "please contact administrator to raise it")
505505

506506
actual := limiter.FormatError("user-1", errMaxSeriesPerUserLimitExceeded)
507507
assert.EqualError(t, actual, "per-user series limit of 100 exceeded, please contact administrator to raise it (local limit: 0 global limit: 100 actual local limit: 100)")

pkg/ingester/user_state_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func TestMetricCounter(t *testing.T) {
7777

7878
// We're testing code that's not dependant on sharding strategy, replication factor, etc. To simplify the test,
7979
// we use local limit only.
80-
limiter := NewLimiter(overrides, nil, util.ShardingStrategyDefault, true, 3, false)
80+
limiter := NewLimiter(overrides, nil, util.ShardingStrategyDefault, true, 3, false, "")
8181
mc := newMetricCounter(limiter, ignored)
8282

8383
for i := 0; i < tc.series; i++ {

0 commit comments

Comments
 (0)