From f303e7c233fc8b6f3e69555e0de0cefe8b1b9097 Mon Sep 17 00:00:00 2001 From: Sanne Raymaekers Date: Thu, 29 Jun 2023 14:31:15 +0200 Subject: [PATCH] cloudapi/v2: rearrange middlewares The duration middleware should come after the tenant channel middleware, otherwise the tenant in the context will be empty. The status middleware can come beforehand because it queries the request context right before sending a response. --- internal/cloudapi/v2/server.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/cloudapi/v2/server.go b/internal/cloudapi/v2/server.go index 06a1da24e..30ae4e542 100644 --- a/internal/cloudapi/v2/server.go +++ b/internal/cloudapi/v2/server.go @@ -93,12 +93,13 @@ func (s *Server) Handler(path string) http.Handler { mws := []echo.MiddlewareFunc{ prometheus.StatusMiddleware(prometheus.ComposerSubsystem), - prometheus.HTTPDurationMiddleware(prometheus.ComposerSubsystem), } if s.config.JWTEnabled { mws = append(mws, auth.TenantChannelMiddleware(s.config.TenantProviderFields, HTTPError(ErrorTenantNotFound))) } - mws = append(mws, prometheus.MetricsMiddleware, s.ValidateRequest) + mws = append(mws, + prometheus.HTTPDurationMiddleware(prometheus.ComposerSubsystem), + prometheus.MetricsMiddleware, s.ValidateRequest) RegisterHandlers(e.Group(path, mws...), &handler) return e