docs(limits): correct usage key count comments

This commit is contained in:
2026-11-25 12:11:13 +00:00
parent ad6af8fd0a
commit 34c2bb8dbf
2 changed files with 12 additions and 40 deletions
+10 -30
View File
@@ -1037,37 +1037,17 @@ func usageEntryView(su scopeUsage, limits *LimitsConfig) adminUsageEntryView {
// having nil limits — the dashboard shows usage for every user and group, // having nil limits — the dashboard shows usage for every user and group,
// limited or not. // limited or not.
// adminUsageChunkScopes bounds how many scopes buildAdminUsage sends to // adminUsageChunkScopes bounds how many scopes buildAdminUsage sends to
// limiter.currentUsage in a single storeGetMulti round trip (security // limiter.currentUsage in one storeGetMulti round trip. A single round trip
// audit finding 4, 2026-08-22). currentUsage's own doc comment (limits.go) // for the whole catalog holds the shared, mutex-guarded Redis connection
// already explains why every scope was folded into ONE round trip rather // (respClient, resp.go) for a time that scales with the user and group
// than one per scope — but "one round trip" for the WHOLE catalog means // count, and every concurrent checkAndCount queues behind it while the
// that round trip's own pipeline size, and how long it holds the shared, // dashboard polls every 5s. chunkedCurrentUsage keeps each round trip's key
// mutex-guarded Redis connection (respClient, resp.go), now scales with // count bounded so live traffic interleaves between chunks.
// how many users and groups are configured. With 1,000 users that is
// ~9,000 GETs (usageKeysPerScope=9, F4 v0.3 dashboard task's rej:day
// counter) in one pipelined call, during which
// every concurrent checkAndCount from live LLM traffic queues behind the
// same connection mutex — and the admin dashboard polls this endpoint
// every 5s. chunkedCurrentUsage (below) keeps each individual round trip's
// key count bounded, letting live traffic interleave between chunks,
// while a chunk still batches every scope inside it exactly as before,
// keeping most of currentUsage's own round-trip-collapsing win. 200
// scopes (1,600 keys per chunk) comfortably covers the live cluster's 5
// friends + 4 home users in a single chunk, so today's real deployment
// sees no behavior change at all — chunking only engages once a
// deployment's user+group count actually grows past it. One accepted,
// disclosed side effect: currentUsage's own doc comment notes a transient
// store error marks every scope in ONE call storeDown together; chunking
// narrows that blast radius to one chunk's worth of scopes instead of the
// whole response, which is a strict improvement, not a new risk.
// //
// Lowered from 200 to 160 (admin dashboard redesign, WP-B) when // 123 scopes * usageKeysPerScope (13) = 1,599 keys, within
// usageKeysPerScope grew from 9 to 10 for the new lastSeen counter // usageModelsChunkKeys (1,600). A deployment under 123 users and groups
// (limits.go, WP-A step 1): 160 scopes * 10 keys/scope = 1,600 keys per // sends one chunk. A transient store error marks every scope in one chunk
// chunk, keeping this endpoint's per-round-trip key count at the same // storeDown together, so chunking narrows that blast radius to one chunk.
// order of magnitude this constant has always targeted, rather than
// letting it grow every time a future per-scope counter is added here.
// 123 scopes * 13 keys/scope = 1,599 keys, within usageModelsChunkKeys.
const adminUsageChunkScopes = 123 const adminUsageChunkScopes = 123
// chunkedCurrentUsage calls limiter.currentUsage in batches of at most // chunkedCurrentUsage calls limiter.currentUsage in batches of at most
+2 -10
View File
@@ -2940,16 +2940,8 @@ func (l *limiter) providerUsage(scopes []limitScope) []providerCounters {
} }
// usageKeysPerScope is the number of windowKey strings usageWindowKeys // usageKeysPerScope is the number of windowKey strings usageWindowKeys
// builds per scope, and the stride currentUsage's flat storeGetMulti // builds per scope, and the stride currentUsage's flat storeGetMulti result
// result is sliced back into per-scope chunks by. Named here, closing a // is sliced back into per-scope chunks by. Keep in step with usageWindowKeys.
// v0.2 final review wave follow-up (2026-08-20) that flagged the previous
// literal "6" as a magic-number stride: this task grows the per-scope key
// count from 6 to 8 for the tokens-in/tokens-out split, which is exactly
// the moment a silent off-by-N here would have gone unnoticed. F4 (v0.3
// dashboard task) grows it again, 8 to 9, for the fleet-wide
// rejectionsPerDay counter (metricRej) usageWindowKeys now appends. Grows
// once more, 9 to 10, for the last-seen counter (Q6, DECISIONS) — see
// usageWindowKeys' own doc comment for the appended field's position.
const usageKeysPerScope = 13 const usageKeysPerScope = 13
// scopeUsage is one scope's (a user's, a group's, or the synthetic total // scopeUsage is one scope's (a user's, a group's, or the synthetic total