From bd26e884aa65b552c796eac04a8f224a6892861a Mon Sep 17 00:00:00 2001 From: Andrew Newdigate Date: Fri, 7 Dec 2018 12:33:10 +0200 Subject: [PATCH 1/3] Log correlation id in Gitaly --- internal/middleware/metadatahandler/metadatahandler.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/middleware/metadatahandler/metadatahandler.go b/internal/middleware/metadatahandler/metadatahandler.go index 06b67b94582..5a8d6ba9034 100644 --- a/internal/middleware/metadatahandler/metadatahandler.go +++ b/internal/middleware/metadatahandler/metadatahandler.go @@ -5,6 +5,7 @@ import ( "github.com/prometheus/client_golang/prometheus" gitalyauth "gitlab.com/gitlab-org/gitaly/auth" "gitlab.com/gitlab-org/gitaly/internal/helper" + "gitlab.com/gitlab-org/labkit/correlation" "golang.org/x/net/context" "google.golang.org/grpc" "google.golang.org/grpc/metadata" @@ -41,6 +42,8 @@ const ClientNameKey = "grpc.meta.client_name" // AuthVersionKey is the key used in ctx_tags to store the auth version const AuthVersionKey = "grpc.meta.auth_version" +const correlationIdKey = "correlation_id" + // Unknown client and feature. Matches the prometheus grpc unknown value const unknownValue = "unknown" @@ -88,6 +91,12 @@ func addMetadataTags(ctx context.Context) metadataTags { tags.Set(AuthVersionKey, authInfo.Version) } + // This is a stop-gap approach to logging correlation_ids + correlationID := correlation.ExtractFromContext(ctx) + if correlationID != "" { + tags.Set(correlationIdKey, correlationID) + } + return metaTags } -- GitLab From e39784729746cf52469fecbe64b6398814d097ef Mon Sep 17 00:00:00 2001 From: Andrew Newdigate Date: Fri, 7 Dec 2018 12:39:50 +0200 Subject: [PATCH 2/3] Add changelog --- changelogs/unreleased/add-correlation_id.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelogs/unreleased/add-correlation_id.yml diff --git a/changelogs/unreleased/add-correlation_id.yml b/changelogs/unreleased/add-correlation_id.yml new file mode 100644 index 00000000000..f88776ea9d3 --- /dev/null +++ b/changelogs/unreleased/add-correlation_id.yml @@ -0,0 +1,5 @@ +--- +title: Log correlation_id field in structured logging output +merge_request: 995 +author: +type: other -- GitLab From 7f2dc47c600673d91ba59250a8b4d4a3acd53121 Mon Sep 17 00:00:00 2001 From: Andrew Newdigate Date: Fri, 7 Dec 2018 23:40:07 +0200 Subject: [PATCH 3/3] Fixing linting problems, changing order of interceptors --- internal/middleware/metadatahandler/metadatahandler.go | 4 ++-- internal/server/server.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/middleware/metadatahandler/metadatahandler.go b/internal/middleware/metadatahandler/metadatahandler.go index 5a8d6ba9034..5091e6654b9 100644 --- a/internal/middleware/metadatahandler/metadatahandler.go +++ b/internal/middleware/metadatahandler/metadatahandler.go @@ -42,7 +42,7 @@ const ClientNameKey = "grpc.meta.client_name" // AuthVersionKey is the key used in ctx_tags to store the auth version const AuthVersionKey = "grpc.meta.auth_version" -const correlationIdKey = "correlation_id" +const correlationIDKey = "correlation_id" // Unknown client and feature. Matches the prometheus grpc unknown value const unknownValue = "unknown" @@ -94,7 +94,7 @@ func addMetadataTags(ctx context.Context) metadataTags { // This is a stop-gap approach to logging correlation_ids correlationID := correlation.ExtractFromContext(ctx) if correlationID != "" { - tags.Set(correlationIdKey, correlationID) + tags.Set(correlationIDKey, correlationID) } return metaTags diff --git a/internal/server/server.go b/internal/server/server.go index a29405c0d73..cf5630badc4 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -74,6 +74,7 @@ func createNewServer(rubyServer *rubyserver.Server, secure bool) *grpc.Server { opts := []grpc.ServerOption{ grpc.StreamInterceptor(grpc_middleware.ChainStreamServer( grpc_ctxtags.StreamServerInterceptor(ctxTagOpts...), + grpccorrelation.StreamServerCorrelationInterceptor(), // Must be above the metadata handler metadatahandler.StreamInterceptor, grpc_prometheus.StreamServerInterceptor, grpc_logrus.StreamServerInterceptor(logrusEntry), @@ -81,13 +82,13 @@ func createNewServer(rubyServer *rubyserver.Server, secure bool) *grpc.Server { cancelhandler.Stream, // Should be below LogHandler lh.StreamInterceptor(), auth.StreamServerInterceptor(), - grpccorrelation.StreamServerCorrelationInterceptor(), // Panic handler should remain last so that application panics will be // converted to errors and logged panichandler.StreamPanicHandler, )), grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer( grpc_ctxtags.UnaryServerInterceptor(ctxTagOpts...), + grpccorrelation.UnaryServerCorrelationInterceptor(), // Must be above the metadata handler metadatahandler.UnaryInterceptor, grpc_prometheus.UnaryServerInterceptor, grpc_logrus.UnaryServerInterceptor(logrusEntry), @@ -95,7 +96,6 @@ func createNewServer(rubyServer *rubyserver.Server, secure bool) *grpc.Server { cancelhandler.Unary, // Should be below LogHandler lh.UnaryInterceptor(), auth.UnaryServerInterceptor(), - grpccorrelation.UnaryServerCorrelationInterceptor(), // Panic handler should remain last so that application panics will be // converted to errors and logged panichandler.UnaryPanicHandler, -- GitLab