(userID string, localLimitFn, globalLimitFn func(string) int)
| 287 | } |
| 288 | |
| 289 | func (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 | |
| 311 | func (l *Limiter) convertGlobalToLocalLimit(userID string, globalLimit int) int { |
| 312 | if globalLimit == 0 { |
no test coverage detected