@@ -201,6 +201,14 @@ func NewRouter() *mux.Router {
201201 // Register a default handler when no routes match
202202 router .NotFoundHandler = middlewares.SimpleLogger {}.Then (http .HandlerFunc (notFoundHandler ))
203203
204+ // Prometheus metrics collection middleware (APIMetrics) to track
205+ // request count, request duration, and client error count for all API endpoints.
206+ router .Use (middlewares.APIMetrics {
207+ RequestCount : RequestCount ,
208+ RequestDuration : RequestDuration ,
209+ ClientErrorCount : ClientErrorCount ,
210+ }.Then )
211+
204212 return router
205213}
206214
@@ -226,11 +234,6 @@ func AuthenticationSubrouter(router *mux.Router, cfg Config) *mux.Router {
226234func CoreSubrouter (router * mux.Router , cfg Config ) * mux.Router {
227235 subrouter := NewSubrouter (
228236 router .PathPrefix ("/api/{group:core}/{version:v2}/" ),
229- middlewares.APIMetrics {
230- RequestCount : RequestCount ,
231- RequestDuration : RequestDuration ,
232- ClientErrorCount : ClientErrorCount ,
233- },
234237 middlewares.Namespace {},
235238 middlewares.Authentication {Store : cfg .Store },
236239 middlewares.SimpleLogger {},
0 commit comments