mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-29 12:42:46 +00:00
Replace deprecated prometheus.InstrumentHandler and unsafe time.Ticker
This commit is contained in:
parent
e959927d0a
commit
8fb2c9c33c
5 changed files with 124 additions and 34 deletions
|
@ -29,6 +29,8 @@ import (
|
|||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/util"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
)
|
||||
|
||||
const pathPrefixR0 = "/_matrix/media/r0"
|
||||
|
@ -83,26 +85,33 @@ func makeDownloadAPI(
|
|||
activeRemoteRequests *types.ActiveRemoteRequests,
|
||||
activeThumbnailGeneration *types.ActiveThumbnailGeneration,
|
||||
) http.HandlerFunc {
|
||||
return prometheus.InstrumentHandler(name, http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
req = util.RequestWithLogging(req)
|
||||
return promhttp.InstrumentHandlerCounter(
|
||||
promauto.NewCounterVec(
|
||||
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, _ := common.URLDecodeMapValues(mux.Vars(req))
|
||||
Download(
|
||||
w,
|
||||
req,
|
||||
gomatrixserverlib.ServerName(vars["serverName"]),
|
||||
types.MediaID(vars["mediaId"]),
|
||||
cfg,
|
||||
db,
|
||||
client,
|
||||
activeRemoteRequests,
|
||||
activeThumbnailGeneration,
|
||||
name == "thumbnail",
|
||||
)
|
||||
}))
|
||||
// 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…
Add table
Add a link
Reference in a new issue