Only perform mediaapi metrics if enabled in config

This commit is contained in:
Devon Hudson 2023-01-20 11:52:54 -07:00
parent 33cdc5adb7
commit a2be8ca873
No known key found for this signature in database
GPG key ID: CD06B18E77F6A628

View file

@ -108,13 +108,16 @@ func makeDownloadAPI(
activeRemoteRequests *types.ActiveRemoteRequests,
activeThumbnailGeneration *types.ActiveThumbnailGeneration,
) http.HandlerFunc {
counterVec := promauto.NewCounterVec(
prometheus.CounterOpts{
Name: name,
Help: "Total number of media_api requests for either thumbnails or full downloads",
},
[]string{"code"},
)
var counterVec *prometheus.CounterVec
if cfg.Matrix.Metrics.Enabled {
counterVec = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: name,
Help: "Total number of media_api requests for either thumbnails or full downloads",
},
[]string{"code"},
)
}
httpHandler := func(w http.ResponseWriter, req *http.Request) {
req = util.RequestWithLogging(req)
@ -166,5 +169,12 @@ func makeDownloadAPI(
vars["downloadName"],
)
}
return promhttp.InstrumentHandlerCounter(counterVec, http.HandlerFunc(httpHandler))
var handlerFunc http.HandlerFunc
if counterVec != nil {
handlerFunc = promhttp.InstrumentHandlerCounter(counterVec, http.HandlerFunc(httpHandler))
} else {
handlerFunc = http.HandlerFunc(httpHandler)
}
return handlerFunc
}