diff options
-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", |