From 7573e0ea8f16d1aa06b49fb0bd899d2ab82ad0ad Mon Sep 17 00:00:00 2001 From: Elio Bischof Date: Thu, 4 Jul 2024 11:37:23 +0200 Subject: [PATCH] feat: add http_server_return_code_counter metric to gateway (#8173) # Which Problems Are Solved The metric `http_server_return_code_counter` doesn't record calls to the gRPC gateway. # How the Problems Are Solved The DefaultMetricsHandler that is used for the gPRC gateway doesn't record `http_server_return_code_counter`. Instead of the DefaultMetricsHandler, a custom metrics handler which includes `http_server_return_code_counter` is created for the gRPC gateway # Additional Changes The DefaultMetricsHandler function is removed, as it is no longer used. # Additional Context Reported by a customer --------- Co-authored-by: Silvan --- internal/api/grpc/server/gateway.go | 7 ++++++- internal/api/http/middleware/metrics_interceptor.go | 6 ------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/internal/api/grpc/server/gateway.go b/internal/api/grpc/server/gateway.go index 327865bd6c..25b4c6996a 100644 --- a/internal/api/grpc/server/gateway.go +++ b/internal/api/grpc/server/gateway.go @@ -20,8 +20,10 @@ import ( client_middleware "github.com/zitadel/zitadel/internal/api/grpc/client/middleware" "github.com/zitadel/zitadel/internal/api/grpc/server/middleware" + http_utils "github.com/zitadel/zitadel/internal/api/http" http_mw "github.com/zitadel/zitadel/internal/api/http/middleware" "github.com/zitadel/zitadel/internal/query" + "github.com/zitadel/zitadel/internal/telemetry/metrics" ) const ( @@ -206,7 +208,10 @@ func addInterceptors( // For some non-obvious reason, the exhaustedCookieInterceptor sends the SetCookie header // only if it follows the http_mw.DefaultTelemetryHandler handler = exhaustedCookieInterceptor(handler, accessInterceptor) - handler = http_mw.DefaultMetricsHandler(handler) + handler = http_mw.MetricsHandler([]metrics.MetricType{ + metrics.MetricTypeTotalCount, + metrics.MetricTypeStatusCode, + }, http_utils.Probes...)(handler) return handler } diff --git a/internal/api/http/middleware/metrics_interceptor.go b/internal/api/http/middleware/metrics_interceptor.go index 32a84f4b15..4b239b8c12 100644 --- a/internal/api/http/middleware/metrics_interceptor.go +++ b/internal/api/http/middleware/metrics_interceptor.go @@ -3,15 +3,9 @@ package middleware import ( "net/http" - http_utils "github.com/zitadel/zitadel/internal/api/http" "github.com/zitadel/zitadel/internal/telemetry/metrics" ) -func DefaultMetricsHandler(handler http.Handler) http.Handler { - metricTypes := []metrics.MetricType{metrics.MetricTypeTotalCount} - return MetricsHandler(metricTypes, http_utils.Probes...)(handler) -} - func MetricsHandler(metricTypes []metrics.MetricType, ignoredMethods ...string) func(http.Handler) http.Handler { return func(handler http.Handler) http.Handler { return metrics.NewMetricsHandler(handler, metricTypes, ignoredMethods...)