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

Method maxByLocalAndGlobal

pkg/ingester/limiter.go:289–309  ·  view source on GitHub ↗
(userID string, localLimitFn, globalLimitFn func(string) int)

Source from the content-addressed store, hash-verified

287}
288
289func (l *Limiter) maxByLocalAndGlobal(userID string, localLimitFn, globalLimitFn func(string) int) int {
290 localLimit := localLimitFn(userID)
291
292 // The global limit is supported only when shard-by-all-labels is enabled,
293 // otherwise we wouldn't get an even split of series/metadata across ingesters and
294 // can't take a "local decision" without any centralized coordination.
295 if l.shardByAllLabels {
296 // We can assume that series/metadata are evenly distributed across ingesters
297 // so we do convert the global limit into a local limit
298 globalLimit := globalLimitFn(userID)
299 localLimit = minNonZero(localLimit, l.convertGlobalToLocalLimit(userID, globalLimit))
300 }
301
302 // If both the local and global limits are disabled, we just
303 // use the largest int value
304 if localLimit == 0 {
305 localLimit = math.MaxInt32
306 }
307
308 return localLimit
309}
310
311func (l *Limiter) convertGlobalToLocalLimit(userID string, globalLimit int) int {
312 if globalLimit == 0 {

Callers 4

maxSeriesPerUserMethod · 0.95
maxMetadataPerUserMethod · 0.95

Calls 2

minNonZeroFunction · 0.85

Tested by

no test coverage detected