registerNameOverride method
Override concurrent / long-lived thresholds for name. Survives
empty-bucket sweep, LRU drops, and isEnabled = false — override
is config, not registration.
Merge: omitted or invalid axis preserves prior. Explicit both-null
clears. Invalid value (<= 0) counts via droppedOverridesCount.
New-name overflow past _maxNameOverridesCap silently drops +
counts; updates to existing names always succeed.
Public entry point: Sleuth.setResourceThreshold.
Implementation
void registerNameOverride(
String name, {
int? maxConcurrent,
int? longLivedSeconds,
}) {
// Caller intent: both args literally absent → explicit clear.
// Distinct from validation reducing both to null (which preserves).
if (maxConcurrent == null && longLivedSeconds == null) {
_nameOverrides.remove(name);
return;
}
// Per-axis validation: invalid axis drops + counts.
int? validMax = maxConcurrent;
int? validLongLived = longLivedSeconds;
if (validMax != null && validMax < 1) {
_droppedOverrides++;
validMax = null;
}
if (validLongLived != null && validLongLived < 1) {
_droppedOverrides++;
validLongLived = null;
}
if (validMax == null && validLongLived == null) {
// All supplied axes invalid; preserve prior (axis-level no-op).
return;
}
// Merge: omitted / invalid axis preserves the prior entry's value.
final existing = _nameOverrides[name];
final mergedMax = validMax ?? existing?.maxConcurrent;
final mergedLongLived = validLongLived ?? existing?.longLivedSeconds;
if (mergedMax == null && mergedLongLived == null) {
// Invalid axes + no prior entry — nothing to store.
return;
}
if (existing == null && _nameOverrides.length >= _maxNameOverridesCap) {
_droppedOverrides++;
return;
}
_nameOverrides[name] = _NameOverride(
maxConcurrent: mergedMax,
longLivedSeconds: mergedLongLived,
);
}