diff options
author | Mike Crute <mike@crute.us> | 2023-10-28 15:18:03 -0700 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2023-10-28 15:18:03 -0700 |
commit | 979a55f905a642fc8227f9e8476b2ffa645670da (patch) | |
tree | d9d153df42d06261c8218821a5349e334e6721b1 | |
parent | 9d5f99a5b4f86e5a880296c0d52d55848791871a (diff) | |
download | golib-979a55f905a642fc8227f9e8476b2ffa645670da.tar.bz2 golib-979a55f905a642fc8227f9e8476b2ffa645670da.tar.xz golib-979a55f905a642fc8227f9e8476b2ffa645670da.zip |
echo: prevent double gzip in prometheusecho/v0.15.2
-rw-r--r-- | echo/echo_default.go | 6 | ||||
-rw-r--r-- | echo/prometheus/prometheus.go | 12 |
2 files changed, 12 insertions, 6 deletions
diff --git a/echo/echo_default.go b/echo/echo_default.go index aa9e32a..b5602e6 100644 --- a/echo/echo_default.go +++ b/echo/echo_default.go | |||
@@ -366,14 +366,10 @@ func (w *EchoWrapper) configureRedirects(c *EchoConfig) { | |||
366 | } | 366 | } |
367 | 367 | ||
368 | func (w *EchoWrapper) configureCompression(c *EchoConfig) { | 368 | func (w *EchoWrapper) configureCompression(c *EchoConfig) { |
369 | metricsSkipper := makeMiddlewareSkipper(c.PrometheusConfig) | ||
370 | |||
371 | w.Use(middleware.Decompress()) | 369 | w.Use(middleware.Decompress()) |
372 | 370 | ||
373 | // TODO: This mangles responses but only for Accept: */* (browsers). Why? | ||
374 | w.Use(middleware.GzipWithConfig(middleware.GzipConfig{ | 371 | w.Use(middleware.GzipWithConfig(middleware.GzipConfig{ |
375 | Skipper: metricsSkipper, | 372 | Level: 6, // Nginx default compression level |
376 | Level: 5, | ||
377 | })) | 373 | })) |
378 | } | 374 | } |
379 | 375 | ||
diff --git a/echo/prometheus/prometheus.go b/echo/prometheus/prometheus.go index 2fbf252..5f93bea 100644 --- a/echo/prometheus/prometheus.go +++ b/echo/prometheus/prometheus.go | |||
@@ -64,9 +64,19 @@ func NewPrometheusWithConfig(c *PrometheusConfig) *Prometheus { | |||
64 | c.ExtractHost = DefaultPrometheusConfig.ExtractHost | 64 | c.ExtractHost = DefaultPrometheusConfig.ExtractHost |
65 | } | 65 | } |
66 | 66 | ||
67 | // Mostly matches promhttp.Handler implementation | ||
68 | hnd := echo.WrapHandler(promhttp.InstrumentMetricHandler( | ||
69 | prometheus.DefaultRegisterer, | ||
70 | promhttp.HandlerFor(prometheus.DefaultGatherer, promhttp.HandlerOpts{ | ||
71 | // We gzip by default in the echo warpper; with this enabled we | ||
72 | // double gzip metrics and corrupt them | ||
73 | DisableCompression: true, | ||
74 | }), | ||
75 | )) | ||
76 | |||
67 | return &Prometheus{ | 77 | return &Prometheus{ |
68 | Config: c, | 78 | Config: c, |
69 | MetricsHandler: echo.WrapHandler(promhttp.Handler()), | 79 | MetricsHandler: hnd, |
70 | requestCount: promauto.NewCounterVec(prometheus.CounterOpts{ | 80 | requestCount: promauto.NewCounterVec(prometheus.CounterOpts{ |
71 | Subsystem: c.Subsystem, | 81 | Subsystem: c.Subsystem, |
72 | Name: "requests_total", | 82 | Name: "requests_total", |