mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
fix(metrics): render fleet-wide families from the shared store
The /metrics route runs in its own instance. That instance handles no chat traffic, so its in-memory families stayed empty. With a limiter store, /metrics now reads the router, decision, latency, prompt-cache, provenance and rejection families from shared counters. Their HELP text uses the store-backed aggregation note. Without a store, or without the stats flag a family needs, the in-memory rendering is unchanged. The latency counters gain day-window sums in milliseconds and streaming-only bucket counters. The histograms can then emit a real _sum and keep the stream label. Provenance writes use countAsync. The rejection month counter rides the existing rejection batch. A store read failure skips the affected families.
This commit is contained in:
@@ -1908,6 +1908,9 @@ func (l *limiter) settleRejection(entries []counterIncr, violatedIdx int, scopes
|
||||
if totalPresent {
|
||||
comp = append(comp, rejectionCounterIncr(totalScopeKind, totalScopeID, windowDay, wb.day, et.day))
|
||||
}
|
||||
if l.store != nil {
|
||||
comp = append(comp, rejectionCounterIncr(violated.kind, violated.id, windowMonth, wb.month, et.month))
|
||||
}
|
||||
// rej/hour (always-on-with-admin, DECISIONS): rides this SAME
|
||||
// compensation batch, never a second round trip, alongside the
|
||||
// existing always-on rej/day entries above.
|
||||
@@ -1924,13 +1927,16 @@ func (l *limiter) settleRejection(entries []counterIncr, violatedIdx int, scopes
|
||||
|
||||
// rejectionCounterIncr builds the single rej counterIncr entry
|
||||
// settleRejection adds per scope it attributes a rejection to, for window
|
||||
// (windowDay, always-on; windowHour, admin-gated) — delta 1, ttl the
|
||||
// window's own matching constant (dayWindowTTL/hourWindowTTL), enforceTTL
|
||||
// the caller's own et.day/et.hour.
|
||||
// (windowDay, always-on; windowHour, admin-gated; windowMonth, store-only,
|
||||
// read by /metrics) — delta 1, ttl the window's own matching constant,
|
||||
// enforceTTL the caller's own et value.
|
||||
func rejectionCounterIncr(kind, id, window, bucket string, enforceTTL time.Duration) counterIncr {
|
||||
ttl := dayWindowTTL
|
||||
if window == windowHour {
|
||||
switch window {
|
||||
case windowHour:
|
||||
ttl = hourWindowTTL
|
||||
case windowMonth:
|
||||
ttl = monthWindowTTL
|
||||
}
|
||||
return counterIncr{key: windowKeyForBucket(kind, id, metricRej, window, bucket), delta: 1, ttl: ttl, enforceTTL: enforceTTL}
|
||||
}
|
||||
@@ -2267,7 +2273,7 @@ func latencyCounterEntries(kind, id string, lat latencySample, wb windowBuckets,
|
||||
counterIncr{key: windowKeyForBucket(kind, id, ttfbMetric, windowDay, wb.day), delta: 1, ttl: dayWindowTTL, enforceTTL: et.day},
|
||||
)
|
||||
}
|
||||
return out
|
||||
return append(out, fleetLatencyEntries(kind, id, lat, wb, et)...)
|
||||
}
|
||||
|
||||
// recordCacheHit accounts one response-cache HIT (Q7, DECISIONS:
|
||||
|
||||
Reference in New Issue
Block a user