From e4f940eef65edcd43b91b2dad7417487bc656675 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Fri, 18 Oct 2024 21:47:28 -0500 Subject: [PATCH] Add logs around gRPC requests (#2159) --- flow/auth/middleware.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/flow/auth/middleware.go b/flow/auth/middleware.go index e3fdfabb7f..bb3ee34da5 100644 --- a/flow/auth/middleware.go +++ b/flow/auth/middleware.go @@ -68,24 +68,35 @@ func AuthGrpcMiddleware(unauthenticatedMethods []string) ([]grpc.ServerOption, e for _, method := range unauthenticatedMethods { unauthenticatedMethodsMap[method] = struct{}{} } - return []grpc.ServerOption{ grpc.ChainUnaryInterceptor(func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) { + slog.Info("Received gRPC request", slog.String("method", info.FullMethod)) + if _, unauthorized := unauthenticatedMethodsMap[info.FullMethod]; !unauthorized { var authHeader string authHeaders := metadata.ValueFromIncomingContext(ctx, "Authorization") if len(authHeaders) == 1 { authHeader = authHeaders[0] } else if len(authHeaders) > 1 { + slog.Warn("Multiple Authorization headers supplied, request rejected", slog.String("method", info.FullMethod)) return nil, status.Errorf(codes.Unauthenticated, "multiple Authorization headers supplied, request rejected") } _, err := validateRequestToken(authHeader, cfg.OauthJwtCustomClaims, ip...) if err != nil { - slog.Debug("failed to validate request token", slog.Any("error", err)) + slog.Debug("Failed to validate request token", slog.String("method", info.FullMethod), slog.Any("error", err)) return nil, status.Errorf(codes.Unauthenticated, "%s", err.Error()) } } - return handler(ctx, req) + + resp, err := handler(ctx, req) + + if err != nil { + slog.Error("gRPC request failed", slog.String("method", info.FullMethod), slog.Any("error", err)) + } else { + slog.Info("gRPC request completed successfully", slog.String("method", info.FullMethod)) + } + + return resp, err }), }, nil }