diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-11-20 11:28:42 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-11-20 11:28:42 +0300 |
commit | 5378715a77e05b2c00e4b6aabc2c61981a69fbb2 (patch) | |
tree | 63025e4082586b0ca7216023a0630acf7509b8eb | |
parent | fb633253db7808a08840f3618e2da327e99c24e6 (diff) | |
parent | d06cb5f4209eeb10102483e85fd604befaa9b99f (diff) |
Merge branch 'sh-fix-issue-5694' into 'master'
requestinfohandler: Restore missing log fields in SSHReceivePack
See merge request https://gitlab.com/gitlab-org/gitaly/-/merge_requests/6534
Merged-by: Patrick Steinhardt <psteinhardt@gitlab.com>
Approved-by: karthik nayak <knayak@gitlab.com>
Co-authored-by: Stan Hu <stanhu@gmail.com>
-rw-r--r-- | internal/grpc/middleware/requestinfohandler/requestinfohandler.go | 10 | ||||
-rw-r--r-- | internal/grpc/middleware/requestinfohandler/requestinfohandler_test.go | 13 |
2 files changed, 23 insertions, 0 deletions
diff --git a/internal/grpc/middleware/requestinfohandler/requestinfohandler.go b/internal/grpc/middleware/requestinfohandler/requestinfohandler.go index 01ca81929..0d738c98e 100644 --- a/internal/grpc/middleware/requestinfohandler/requestinfohandler.go +++ b/internal/grpc/middleware/requestinfohandler/requestinfohandler.go @@ -4,6 +4,7 @@ import ( "context" "strings" + grpcmwtags "github.com/grpc-ecosystem/go-grpc-middleware/tags" "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging" grpcprometheus "github.com/grpc-ecosystem/go-grpc-prometheus" "github.com/prometheus/client_golang/prometheus" @@ -196,9 +197,18 @@ func (i *RequestInfo) extractRequestInfo(request any) { } func (i *RequestInfo) injectTags(ctx context.Context) context.Context { + tags := grpcmwtags.NewTags() + for key, value := range i.Tags() { ctx = logging.InjectLogField(ctx, key, value) + tags.Set(key, value) } + + // This maintains backward compatibility for tags in the v1 grpc-go-middleware. + // This can be removed when the v1 interceptors are removed: + // https://gitlab.com/gitlab-org/gitaly/-/work_items/5661 + ctx = grpcmwtags.SetInContext(ctx, tags) + return ctx } diff --git a/internal/grpc/middleware/requestinfohandler/requestinfohandler_test.go b/internal/grpc/middleware/requestinfohandler/requestinfohandler_test.go index 5e62707cd..38e40faeb 100644 --- a/internal/grpc/middleware/requestinfohandler/requestinfohandler_test.go +++ b/internal/grpc/middleware/requestinfohandler/requestinfohandler_test.go @@ -7,6 +7,7 @@ import ( "testing" "time" + grpcmwtags "github.com/grpc-ecosystem/go-grpc-middleware/tags" "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging" "github.com/stretchr/testify/require" gitalylog "gitlab.com/gitlab-org/gitaly/v16/internal/log" @@ -283,6 +284,18 @@ func TestGRPCTags(t *testing.T) { "grpc.request.fullMethod": "/gitaly.RepositoryService/OptimizeRepository", }, gitalylog.ConvertLoggingFields(fields)) + legacyFields := grpcmwtags.Extract(ctx).Values() + + require.Equal(t, map[string]any{ + "correlation_id": correlationID, + "grpc.meta.client_name": clientName, + "grpc.meta.deadline_type": "none", + "grpc.meta.method_type": "unary", + "grpc.meta.method_operation": "maintenance", + "grpc.meta.method_scope": "repository", + "grpc.request.fullMethod": "/gitaly.RepositoryService/OptimizeRepository", + }, legacyFields) + return nil, nil }) require.NoError(t, err) |