From f8a25f6af7febe8bb0ef570e32e17602f341fae0 Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Thu, 17 Sep 2015 14:49:50 +0200 Subject: [PATCH] Apply HTTP handler compression everywhere --- web/api/v1/api.go | 4 +++- web/web.go | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/web/api/v1/api.go b/web/api/v1/api.go index 0809a8a9e..e548a13da 100644 --- a/web/api/v1/api.go +++ b/web/api/v1/api.go @@ -16,6 +16,7 @@ import ( "github.com/prometheus/prometheus/promql" "github.com/prometheus/prometheus/storage/local" "github.com/prometheus/prometheus/storage/metric" + "github.com/prometheus/prometheus/util/httputil" "github.com/prometheus/prometheus/util/route" "github.com/prometheus/prometheus/util/strutil" ) @@ -79,7 +80,7 @@ func (api *API) Register(r *route.Router) { } instr := func(name string, f apiFunc) http.HandlerFunc { - return prometheus.InstrumentHandlerFunc(name, func(w http.ResponseWriter, r *http.Request) { + hf := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { setCORS(w) if data, err := f(r); err != nil { respondError(w, err, data) @@ -87,6 +88,7 @@ func (api *API) Register(r *route.Router) { respond(w, data) } }) + return prometheus.InstrumentHandler(name, httputil.CompressionHandler{hf}) } r.Get("/query", instr("query", api.query)) diff --git a/web/web.go b/web/web.go index d95e8da90..0c9d6fa58 100644 --- a/web/web.go +++ b/web/web.go @@ -41,6 +41,7 @@ import ( "github.com/prometheus/prometheus/rules" "github.com/prometheus/prometheus/storage/local" "github.com/prometheus/prometheus/template" + "github.com/prometheus/prometheus/util/httputil" "github.com/prometheus/prometheus/util/route" "github.com/prometheus/prometheus/version" "github.com/prometheus/prometheus/web/api/legacy" @@ -155,8 +156,12 @@ func New(st local.Storage, qe *promql.Engine, rm *rules.Manager, status *Prometh router = router.WithPrefix(o.ExternalURL.Path) } - instrf := prometheus.InstrumentHandlerFunc - instrh := prometheus.InstrumentHandler + instrh := func(name string, h http.Handler) http.HandlerFunc { + return prometheus.InstrumentHandler(name, httputil.CompressionHandler{h}) + } + instrf := func(name string, f http.HandlerFunc) http.HandlerFunc { + return instrh(name, f) + } router.Get("/", func(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "/graph", http.StatusFound)