perf(shared-state): batch calibrator counters with the usage write

Each served request spawned a second async write for the calibrator
counters. They now ride the batch accountWith already sends, and only
when shared state is on and a store is configured.
This commit is contained in:
2026-11-26 04:12:38 +00:00
parent 383d477778
commit 367f3b60ff
6 changed files with 98 additions and 21 deletions
+6
View File
@@ -1995,6 +1995,8 @@ type accountExtras struct {
// with a store, accountWith mirrors it, and provenanceTokens, into the
// shared month counters.
provenance string
// calibration is the shared token-calibrator counters of this call; accountWith adds them only with a store.
calibration []counterIncr
// promptCacheSaved is the micro-USD the provider prompt cache saved this call.
promptCacheSaved int64
provenanceTokens int64
@@ -2229,6 +2231,10 @@ func (l *limiter) accountWith(scopes []limitScope, u usage, costMicros int64, x
entries = append(entries, provenanceEntries(x.provider, x.provenance, x.provenanceTokens, wb.month)...)
}
if l.store != nil && len(x.calibration) > 0 {
entries = append(entries, x.calibration...)
}
if x.hasLat && l.statsLatency {
if x.provider != "" {
entries = append(entries, latencyCounterEntries(kindProvider, x.provider, x.lat, wb, et)...)