metrics: DisableCompression on promhttp.HandlerOpts (F1 from audit)
- SHA
56e254e49d5d3fa51a4a5300557e3aa90ccfc2dd- Parents
-
f305fee - Tree
7a8ee0e
56e254e
56e254e49d5d3fa51a4a5300557e3aa90ccfc2ddf305fee
7a8ee0e| Status | File | + | - |
|---|---|---|---|
| M |
internal/infra/metrics/metrics.go
|
10 | 1 |
internal/infra/metrics/metrics.gomodified@@ -131,9 +131,18 @@ func init() { | ||
| 131 | 131 | // Handler returns the /metrics HTTP handler. When user/pass is set, the |
| 132 | 132 | // handler enforces HTTP Basic auth; otherwise it serves unauthenticated |
| 133 | 133 | // (S35 will tighten the policy). |
| 134 | +// | |
| 135 | +// DisableCompression: promhttp gzips responses when the scraper sends | |
| 136 | +// Accept-Encoding: gzip. Alloy 1.16's Prometheus scraper advertises gzip | |
| 137 | +// but mishandles the Content-Encoding: gzip response (parses raw 0x1f | |
| 138 | +// magic byte as text, scrape fails with up=0). Bypass at the source — | |
| 139 | +// /metrics payload is small enough that wire savings are irrelevant. | |
| 140 | +// Skipping the chi Compress middleware on this route (handlers.go) is | |
| 141 | +// also necessary but not sufficient; promhttp does its own gzip layer. | |
| 134 | 142 | func Handler(user, pass string) http.Handler { |
| 135 | 143 | h := promhttp.HandlerFor(Registry, promhttp.HandlerOpts{ |
| 136 | - Registry: Registry, | |
| 144 | + Registry: Registry, | |
| 145 | + DisableCompression: true, | |
| 137 | 146 | }) |
| 138 | 147 | if user == "" && pass == "" { |
| 139 | 148 | return h |