package metrics // Cache hit/miss counters per subsystem (v1.0.9 W3 Day 11). // // Three call-sites instrumented in v1.0.9: // - rate_limiter — Redis INCR result classified as "hit" if the key // already existed in the window (in-window request), // "miss" if it was a new window (key just created). // - chat_pubsub — "hit" on a successful Publish/Subscribe round-trip, // "miss" on connection error (Redis unreachable). // - presence — "hit" on a successful Get/Set/Del, "miss" on a key // that didn't exist (presence stale or never set) or // on an underlying Redis error. // // Subsystems are passed as labels rather than baked into separate metrics // so dashboards can pivot. Cardinality is fixed at the three values above // (plus future additions in W3+); never label by user_id / room_id / // per-key — that would explode cardinality. import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" ) var ( cacheHits = promauto.NewCounterVec( prometheus.CounterOpts{ Name: "veza_cache_hits_total", Help: "Total cache hits per subsystem", }, []string{"subsystem"}, ) cacheMisses = promauto.NewCounterVec( prometheus.CounterOpts{ Name: "veza_cache_misses_total", Help: "Total cache misses per subsystem", }, []string{"subsystem"}, ) ) // RecordCacheHit increments the hit counter for a subsystem. Subsystem // must be one of the bounded set documented at file-level — adding a // new value is a deliberate choice that should also update Grafana. func RecordCacheHit(subsystem string) { cacheHits.WithLabelValues(subsystem).Inc() } // RecordCacheMiss increments the miss counter for a subsystem. func RecordCacheMiss(subsystem string) { cacheMisses.WithLabelValues(subsystem).Inc() }