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 { | |
| 71 | 71 | CacheHit: auto.NewCounter(prometheus.CounterOpts{ | |
| 72 | 72 | Namespace: name, | |
| 73 | 73 | Subsystem: "http_cache", | |
| 74 | - | Name: "cache_hit", | |
| 74 | + | Name: "cache_hit_count", | |
| 75 | 75 | Help: "The number of times there was a cache hit", | |
| 76 | 76 | }), | |
| 77 | 77 | CacheMiss: auto.NewCounter(prometheus.CounterOpts{ | |
| 78 | 78 | Namespace: name, | |
| 79 | 79 | Subsystem: "http_cache", | |
| 80 | - | Name: "cache_miss", | |
| 80 | + | Name: "cache_miss_count", | |
| 81 | 81 | Help: "The number of times there was a cache miss", | |
| 82 | 82 | }), | |
| 83 | 83 | UpstreamReq: auto.NewCounter(prometheus.CounterOpts{ | |
| 84 | 84 | Namespace: name, | |
| 85 | 85 | Subsystem: "http_cache", | |
| 86 | - | Name: "upstream_request", | |
| 86 | + | Name: "upstream_request_count", | |
| 87 | 87 | Help: "The number of times the upstream http server was requested", | |
| 88 | 88 | }), | |
| 89 | 89 | } |
+5,
-11
| ... | ... | @@ -163,9 +163,7 @@ func (c *HttpCache) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |
| 163 | 163 | if isForbiddenHeader(key) { | |
| 164 | 164 | continue | |
| 165 | 165 | } | |
| 166 | - | for _, value := range values { | |
| 167 | - | hdr.Add(key, value) | |
| 168 | - | } | |
| 166 | + | hdr[key] = values | |
| 169 | 167 | } | |
| 170 | 168 | ageDur := calcAge(cacheValue.CreatedAt) | |
| 171 | 169 | hdr.Set("age", strconv.Itoa(int(ageDur.Seconds())+1)) |
| ... | ... | @@ -217,15 +215,13 @@ func serveCache(w http.ResponseWriter, freshness time.Duration, cacheKey string, | |
| 217 | 215 | if isForbiddenHeader(key) { | |
| 218 | 216 | continue | |
| 219 | 217 | } | |
| 220 | - | for _, value := range values { | |
| 221 | - | hdr.Add(key, value) | |
| 222 | - | } | |
| 218 | + | hdr[key] = values | |
| 223 | 219 | } | |
| 224 | 220 | ||
| 225 | 221 | ageDur := calcAge(cacheValue.CreatedAt) | |
| 226 | 222 | 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())) | |
| 229 | 225 | if cacheValue.StatusCode != 0 && cacheValue.StatusCode != http.StatusOK { | |
| 230 | 226 | w.WriteHeader(cacheValue.StatusCode) | |
| 231 | 227 | } |
| ... | ... | @@ -652,9 +648,7 @@ func (c *HttpCache) maybeUseCache(cacheKey string, w http.ResponseWriter, r *htt | |
| 652 | 648 | if isForbiddenHeader(key) { | |
| 653 | 649 | continue | |
| 654 | 650 | } | |
| 655 | - | for _, value := range values { | |
| 656 | - | hdr.Add(key, value) | |
| 657 | - | } | |
| 651 | + | hdr[key] = values | |
| 658 | 652 | } | |
| 659 | 653 | ageDur := calcAge(cacheValue.CreatedAt) | |
| 660 | 654 | hdr.Set("age", strconv.Itoa(int(ageDur.Seconds())+1)) |