Proper instrumenthandler fix

This commit is contained in:
Andrew Morgan 2019-06-19 11:46:39 +01:00
parent 8f6ee9de9c
commit f0e81464c1

View file

@ -29,6 +29,7 @@ import (
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util" "github.com/matrix-org/util"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
) )
@ -80,13 +81,14 @@ func makeDownloadAPI(
activeRemoteRequests *types.ActiveRemoteRequests, activeRemoteRequests *types.ActiveRemoteRequests,
activeThumbnailGeneration *types.ActiveThumbnailGeneration, activeThumbnailGeneration *types.ActiveThumbnailGeneration,
) http.HandlerFunc { ) http.HandlerFunc {
handlerInfo := prometheus.NewCounterVec( return promhttp.InstrumentHandlerCounter(
promauto.NewCounterVec(
prometheus.CounterOpts{ prometheus.CounterOpts{
Name: name, Name: name,
Help: "Total number of media_api requests for either thumbnails or full downloads",
}, },
[]string{name}, []string{"code"},
) ), http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
return promhttp.InstrumentHandlerCounter(handlerInfo, http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
req = util.RequestWithLogging(req) req = util.RequestWithLogging(req)
// Set common headers returned regardless of the outcome of the request // Set common headers returned regardless of the outcome of the request
@ -107,5 +109,6 @@ func makeDownloadAPI(
activeThumbnailGeneration, activeThumbnailGeneration,
name == "thumbnail", name == "thumbnail",
) )
})) },
))
} }