From 4f1421d22a20f5ca1fb9f30bf9b41645adf8a743 Mon Sep 17 00:00:00 2001 From: Gui Iribarren Date: Mon, 6 Nov 2023 12:15:21 +0100 Subject: [PATCH] httprouter: enable compression support --- httprouter/httprouter.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/httprouter/httprouter.go b/httprouter/httprouter.go index c6e1eabf9..64d1e30f2 100644 --- a/httprouter/httprouter.go +++ b/httprouter/httprouter.go @@ -92,6 +92,7 @@ func (r *HTTProuter) Init(host string, port int) error { r.Mux.Use(middleware.Heartbeat("/ping")) r.Mux.Use(middleware.ThrottleBacklog(5000, 40000, 30*time.Second)) r.Mux.Use(middleware.Timeout(30 * time.Second)) + r.Mux.Use(middleware.Compress(5)) // Cors handler cors := cors.New(cors.Options{ @@ -177,6 +178,11 @@ func (r *HTTProuter) EnablePrometheusMetrics(prometheusID string) { func (r *HTTProuter) ExposePrometheusEndpoint(path string) { r.AddRawHTTPHandler(path, "GET", func(w http.ResponseWriter, req *http.Request) { // upstream packages (cometbft, libp2p) call prometheus.Register(), so expose those metrics first + // + // we need to remove the "Accept-Encoding: gzip" to ensure promhttp.Handler().ServeHTTP() outputs plaintext, + // to be able to append the plaintext from metrics.WritePrometheus, + // and let go-chi take care of compression of the combined output + req.Header.Del("Accept-Encoding") promhttp.Handler().ServeHTTP(w, req) // then append the metrics registered in VictoriaMetrics (our metrics, basically)