Commit 4ee7ba6

Eric Bower  ·  2026-04-19 11:51:22 -0400 EDT
parent 3ad9fce
fix(pgs): prom names and set headers instead of add
2 files changed,  +8, -14
+3, -3
......@@ -71,19 +71,19 @@ func NewPromCacheMetrics(reg prometheus.Registerer) *PromCacheMetrics {
7171 CacheHit: auto.NewCounter(prometheus.CounterOpts{
7272 Namespace: name,
7373 Subsystem: "http_cache",
74- Name: "cache_hit",
74+ Name: "cache_hit_count",
7575 Help: "The number of times there was a cache hit",
7676 }),
7777 CacheMiss: auto.NewCounter(prometheus.CounterOpts{
7878 Namespace: name,
7979 Subsystem: "http_cache",
80- Name: "cache_miss",
80+ Name: "cache_miss_count",
8181 Help: "The number of times there was a cache miss",
8282 }),
8383 UpstreamReq: auto.NewCounter(prometheus.CounterOpts{
8484 Namespace: name,
8585 Subsystem: "http_cache",
86- Name: "upstream_request",
86+ Name: "upstream_request_count",
8787 Help: "The number of times the upstream http server was requested",
8888 }),
8989 }
+5, -11
......@@ -163,9 +163,7 @@ func (c *HttpCache) ServeHTTP(w http.ResponseWriter, r *http.Request) {
163163 if isForbiddenHeader(key) {
164164 continue
165165 }
166- for _, value := range values {
167- hdr.Add(key, value)
168- }
166+ hdr[key] = values
169167 }
170168 ageDur := calcAge(cacheValue.CreatedAt)
171169 hdr.Set("age", strconv.Itoa(int(ageDur.Seconds())+1))
......@@ -217,15 +215,13 @@ func serveCache(w http.ResponseWriter, freshness time.Duration, cacheKey string,
217215 if isForbiddenHeader(key) {
218216 continue
219217 }
220- for _, value := range values {
221- hdr.Add(key, value)
222- }
218+ hdr[key] = values
223219 }
224220
225221 ageDur := calcAge(cacheValue.CreatedAt)
226222 age := ageDur.Seconds()
227- hdr.Add("age", strconv.Itoa(int(age)+1))
228- hdr.Add("cache-status", cacheStatusHit(cacheKey, freshness.Seconds()))
223+ hdr.Set("age", strconv.Itoa(int(age)+1))
224+ hdr.Set("cache-status", cacheStatusHit(cacheKey, freshness.Seconds()))
229225 if cacheValue.StatusCode != 0 && cacheValue.StatusCode != http.StatusOK {
230226 w.WriteHeader(cacheValue.StatusCode)
231227 }
......@@ -652,9 +648,7 @@ func (c *HttpCache) maybeUseCache(cacheKey string, w http.ResponseWriter, r *htt
652648 if isForbiddenHeader(key) {
653649 continue
654650 }
655- for _, value := range values {
656- hdr.Add(key, value)
657- }
651+ hdr[key] = values
658652 }
659653 ageDur := calcAge(cacheValue.CreatedAt)
660654 hdr.Set("age", strconv.Itoa(int(ageDur.Seconds())+1))