Commit 9baad06
Eric Bower
·
2026-04-19 13:39:58 -0400 EDT
parent 1e1cc0b
chore(pgs): log key eviction
1 files changed,
+5,
-2
+5,
-2
| ... | ... | @@ -44,6 +44,7 @@ func (c *PgsCacheKey) GetCacheKey(r *http.Request) string { | |
| 44 | 44 | } | |
| 45 | 45 | ||
| 46 | 46 | type PromCacheMetrics struct { | |
| 47 | + | Logger *slog.Logger | |
| 47 | 48 | Cache httpcache.Cacher | |
| 48 | 49 | CacheItems prometheus.Gauge | |
| 49 | 50 | CacheSizeBytes prometheus.Gauge |
| ... | ... | @@ -52,10 +53,11 @@ type PromCacheMetrics struct { | |
| 52 | 53 | UpstreamReq prometheus.Counter | |
| 53 | 54 | } | |
| 54 | 55 | ||
| 55 | - | func NewPromCacheMetrics(reg prometheus.Registerer) *PromCacheMetrics { | |
| 56 | + | func NewPromCacheMetrics(logger *slog.Logger, reg prometheus.Registerer) *PromCacheMetrics { | |
| 56 | 57 | name := "pgs" | |
| 57 | 58 | auto := promauto.With(reg) | |
| 58 | 59 | return &PromCacheMetrics{ | |
| 60 | + | Logger: logger, | |
| 59 | 61 | CacheItems: auto.NewGauge(prometheus.GaugeOpts{ | |
| 60 | 62 | Namespace: name, | |
| 61 | 63 | Subsystem: "http_cache", |
| ... | ... | @@ -93,6 +95,7 @@ func (p *PromCacheMetrics) AddCacheItem(size float64) { | |
| 93 | 95 | p.CacheSizeBytes.Add(size) | |
| 94 | 96 | } | |
| 95 | 97 | func (p *PromCacheMetrics) EvictCacheItem(key string, value []byte) { | |
| 98 | + | p.Logger.Info("evicting cache key", "key", key, "len_bytes", len(value)) | |
| 96 | 99 | p.CacheItems.Add(-1) | |
| 97 | 100 | p.CacheSizeBytes.Add(-float64(len(value))) | |
| 98 | 101 | } |
| ... | ... | @@ -108,7 +111,7 @@ func (p *PromCacheMetrics) AddUpstreamRequest() { | |
| 108 | 111 | ||
| 109 | 112 | func NewPgsHttpCache(cfg *PgsConfig, upstream http.Handler) *httpcache.HttpCache { | |
| 110 | 113 | ttl := cfg.CacheTTL | |
| 111 | - | metrics := NewPromCacheMetrics(prometheus.DefaultRegisterer) | |
| 114 | + | metrics := NewPromCacheMetrics(cfg.Logger, prometheus.DefaultRegisterer) | |
| 112 | 115 | cache := expirable.NewLRU(0, metrics.EvictCacheItem, ttl) | |
| 113 | 116 | httpCache := &httpcache.HttpCache{ | |
| 114 | 117 | Ttl: ttl, |