Compression of prometheus metrics without Transfer-Encoding header
When using the prometheus middleware AND the Gzip middleware I get a compressed response for /metrics without the Transfer-Encoding header.
oh, wait -- there's a Content-Encoding header (but all the same, curl doesn't seem to recognize that the content is compressed)
Does your request contains necessary headers? Compression is applied only when there is Accept-Encoding present
https://github.com/labstack/echo/blob/d604704563de63e42a352ffc51b6d633d9d595e3/middleware/compress.go#L72
I had a similar issue where when using both gzip and prometheus I got a gzipped response on the /metrics endpoint, the solution that worked for me was that I added a skipper to the gzip handler.
return middleware.GzipWithConfig(middleware.GzipConfig{
Level: 5,
Skipper: func(c echo.Context) bool {
return strings.HasPrefix(c.Path(), "/metrics")
},
})
This should probably be closed.
At least I can not recreate it.
package main
import (
"errors"
"github.com/labstack/echo-contrib/echoprometheus"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"log"
"net/http"
)
func main() {
e := echo.New()
e.Use(middleware.Gzip())
e.Use(echoprometheus.NewMiddleware("myapp"))
e.GET("/metrics", echoprometheus.NewHandler())
if err := e.Start(":8080"); err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Fatal(err)
}
}
output:
x@x:~/code$ curl -v http://localhost:8080/metrics
* Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /metrics HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.85.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Type: text/plain; version=0.0.4; charset=utf-8
< Vary: Accept-Encoding
< Date: Tue, 23 May 2023 20:45:50 GMT
< Transfer-Encoding: chunked
<
# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 0
go_gc_duration_seconds{quantile="0.25"} 0
...
...
seems to work with curl
This should probably be closed. ... At least I can not recreate it.
I think if you used something like curl -v -s -H 'Accept-Encoding: gzip,deflate' http://localhost:8080/metrics you will see the issue
I think this was done with https://github.com/labstack/echo-contrib/pull/97