tenseleyflow/shithub / 56e254e

Browse files

metrics: DisableCompression on promhttp.HandlerOpts (F1 from audit)

Authored by espadonne
SHA
56e254e49d5d3fa51a4a5300557e3aa90ccfc2dd
Parents
f305fee
Tree
7a8ee0e

1 changed file

StatusFile+-
M internal/infra/metrics/metrics.go 10 1
internal/infra/metrics/metrics.gomodified
@@ -131,9 +131,18 @@ func init() {
131131
 // Handler returns the /metrics HTTP handler. When user/pass is set, the
132132
 // handler enforces HTTP Basic auth; otherwise it serves unauthenticated
133133
 // (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.
134142
 func Handler(user, pass string) http.Handler {
135143
 	h := promhttp.HandlerFor(Registry, promhttp.HandlerOpts{
136
-		Registry: Registry,
144
+		Registry:          Registry,
145
+		DisableCompression: true,
137146
 	})
138147
 	if user == "" && pass == "" {
139148
 		return h