mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-16 03:13:11 -06:00
Proper instrumenthandler fix
This commit is contained in:
parent
8f6ee9de9c
commit
f0e81464c1
|
|
@ -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,32 +81,34 @@ func makeDownloadAPI(
|
||||||
activeRemoteRequests *types.ActiveRemoteRequests,
|
activeRemoteRequests *types.ActiveRemoteRequests,
|
||||||
activeThumbnailGeneration *types.ActiveThumbnailGeneration,
|
activeThumbnailGeneration *types.ActiveThumbnailGeneration,
|
||||||
) http.HandlerFunc {
|
) http.HandlerFunc {
|
||||||
handlerInfo := prometheus.NewCounterVec(
|
return promhttp.InstrumentHandlerCounter(
|
||||||
prometheus.CounterOpts{
|
promauto.NewCounterVec(
|
||||||
Name: name,
|
prometheus.CounterOpts{
|
||||||
|
Name: name,
|
||||||
|
Help: "Total number of media_api requests for either thumbnails or full downloads",
|
||||||
|
},
|
||||||
|
[]string{"code"},
|
||||||
|
), http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||||
|
req = util.RequestWithLogging(req)
|
||||||
|
|
||||||
|
// Set common headers returned regardless of the outcome of the request
|
||||||
|
util.SetCORSHeaders(w)
|
||||||
|
// Content-Type will be overridden in case of returning file data, else we respond with JSON-formatted errors
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
vars := mux.Vars(req)
|
||||||
|
Download(
|
||||||
|
w,
|
||||||
|
req,
|
||||||
|
gomatrixserverlib.ServerName(vars["serverName"]),
|
||||||
|
types.MediaID(vars["mediaId"]),
|
||||||
|
cfg,
|
||||||
|
db,
|
||||||
|
client,
|
||||||
|
activeRemoteRequests,
|
||||||
|
activeThumbnailGeneration,
|
||||||
|
name == "thumbnail",
|
||||||
|
)
|
||||||
},
|
},
|
||||||
[]string{name},
|
))
|
||||||
)
|
|
||||||
return promhttp.InstrumentHandlerCounter(handlerInfo, http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
|
||||||
req = util.RequestWithLogging(req)
|
|
||||||
|
|
||||||
// Set common headers returned regardless of the outcome of the request
|
|
||||||
util.SetCORSHeaders(w)
|
|
||||||
// Content-Type will be overridden in case of returning file data, else we respond with JSON-formatted errors
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
|
|
||||||
vars := mux.Vars(req)
|
|
||||||
Download(
|
|
||||||
w,
|
|
||||||
req,
|
|
||||||
gomatrixserverlib.ServerName(vars["serverName"]),
|
|
||||||
types.MediaID(vars["mediaId"]),
|
|
||||||
cfg,
|
|
||||||
db,
|
|
||||||
client,
|
|
||||||
activeRemoteRequests,
|
|
||||||
activeThumbnailGeneration,
|
|
||||||
name == "thumbnail",
|
|
||||||
)
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue