- commit
- 4ee7ba6
- parent
- 3ad9fce
- author
- Eric Bower
- date
- 2026-04-19 11:51:22 -0400 EDT
fix(pgs): prom names and set headers instead of add
2 files changed,
+8,
-14
+3,
-3
1@@ -71,19 +71,19 @@ func NewPromCacheMetrics(reg prometheus.Registerer) *PromCacheMetrics {
2 CacheHit: auto.NewCounter(prometheus.CounterOpts{
3 Namespace: name,
4 Subsystem: "http_cache",
5- Name: "cache_hit",
6+ Name: "cache_hit_count",
7 Help: "The number of times there was a cache hit",
8 }),
9 CacheMiss: auto.NewCounter(prometheus.CounterOpts{
10 Namespace: name,
11 Subsystem: "http_cache",
12- Name: "cache_miss",
13+ Name: "cache_miss_count",
14 Help: "The number of times there was a cache miss",
15 }),
16 UpstreamReq: auto.NewCounter(prometheus.CounterOpts{
17 Namespace: name,
18 Subsystem: "http_cache",
19- Name: "upstream_request",
20+ Name: "upstream_request_count",
21 Help: "The number of times the upstream http server was requested",
22 }),
23 }
+5,
-11
1@@ -163,9 +163,7 @@ func (c *HttpCache) ServeHTTP(w http.ResponseWriter, r *http.Request) {
2 if isForbiddenHeader(key) {
3 continue
4 }
5- for _, value := range values {
6- hdr.Add(key, value)
7- }
8+ hdr[key] = values
9 }
10 ageDur := calcAge(cacheValue.CreatedAt)
11 hdr.Set("age", strconv.Itoa(int(ageDur.Seconds())+1))
12@@ -217,15 +215,13 @@ func serveCache(w http.ResponseWriter, freshness time.Duration, cacheKey string,
13 if isForbiddenHeader(key) {
14 continue
15 }
16- for _, value := range values {
17- hdr.Add(key, value)
18- }
19+ hdr[key] = values
20 }
21
22 ageDur := calcAge(cacheValue.CreatedAt)
23 age := ageDur.Seconds()
24- hdr.Add("age", strconv.Itoa(int(age)+1))
25- hdr.Add("cache-status", cacheStatusHit(cacheKey, freshness.Seconds()))
26+ hdr.Set("age", strconv.Itoa(int(age)+1))
27+ hdr.Set("cache-status", cacheStatusHit(cacheKey, freshness.Seconds()))
28 if cacheValue.StatusCode != 0 && cacheValue.StatusCode != http.StatusOK {
29 w.WriteHeader(cacheValue.StatusCode)
30 }
31@@ -652,9 +648,7 @@ func (c *HttpCache) maybeUseCache(cacheKey string, w http.ResponseWriter, r *htt
32 if isForbiddenHeader(key) {
33 continue
34 }
35- for _, value := range values {
36- hdr.Add(key, value)
37- }
38+ hdr[key] = values
39 }
40 ageDur := calcAge(cacheValue.CreatedAt)
41 hdr.Set("age", strconv.Itoa(int(ageDur.Seconds())+1))