Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Ju <eju@gitlab.com>2024-01-22 18:29:01 +0300
committerEric Ju <eju@gitlab.com>2024-01-22 18:29:01 +0300
commit410a311e251c5f4024ef8f29eed8b6b0267bbef8 (patch)
tree1fb4453ad224676a3dcf1aadd30bccace3e2bdfd
parentc15c9d250a7e80fe868fe037bfd58e1f7b5f7584 (diff)
requestinfohandler: SSHReceivePack RPC is missing glProjectPath in logej/5794/glProjectPath-is-missing-in-SSHReceivePack
The grpc.request.glProjectPath of SSHReceivePack RPCs is missing in gitaly log. The tags is declared every time we call injectTags resulting any tags from previous call is missing.
-rw-r--r--internal/grpc/middleware/requestinfohandler/requestinfohandler.go16
-rw-r--r--internal/grpc/middleware/requestinfohandler/requestinfohandler_test.go4
2 files changed, 12 insertions, 8 deletions
diff --git a/internal/grpc/middleware/requestinfohandler/requestinfohandler.go b/internal/grpc/middleware/requestinfohandler/requestinfohandler.go
index 0d738c98e..50dd39305 100644
--- a/internal/grpc/middleware/requestinfohandler/requestinfohandler.go
+++ b/internal/grpc/middleware/requestinfohandler/requestinfohandler.go
@@ -196,9 +196,7 @@ func (i *RequestInfo) extractRequestInfo(request any) {
}
}
-func (i *RequestInfo) injectTags(ctx context.Context) context.Context {
- tags := grpcmwtags.NewTags()
-
+func (i *RequestInfo) injectTags(ctx context.Context, tags grpcmwtags.Tags) context.Context {
for key, value := range i.Tags() {
ctx = logging.InjectLogField(ctx, key, value)
tags.Set(key, value)
@@ -297,12 +295,14 @@ func (i *RequestInfo) ExtractServiceAndMethodName() (string, string) {
// UnaryInterceptor returns a Unary Interceptor
func UnaryInterceptor(ctx context.Context, req interface{}, serverInfo *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
+ tags := grpcmwtags.NewTags()
+
info := newRequestInfo(ctx, serverInfo.FullMethod, "unary")
info.extractRequestInfo(req)
ctx = context.WithValue(ctx, requestInfoKey{}, info)
- ctx = info.injectTags(ctx)
+ ctx = info.injectTags(ctx, tags)
res, err := handler(ctx, req)
info.reportPrometheusMetrics(err)
@@ -311,6 +311,8 @@ func UnaryInterceptor(ctx context.Context, req interface{}, serverInfo *grpc.Una
// StreamInterceptor returns a Stream Interceptor
func StreamInterceptor(srv interface{}, stream grpc.ServerStream, serverInfo *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
+ tags := grpcmwtags.NewTags()
+
ctx := stream.Context()
info := newRequestInfo(ctx, serverInfo.FullMethod, streamRPCType(serverInfo))
@@ -318,11 +320,12 @@ func StreamInterceptor(srv interface{}, stream grpc.ServerStream, serverInfo *gr
// Even though we don't yet have all information set up we already inject the tags here. This is done such that
// log messages will at least have the metadata set up correctly in case there is no first request.
- ctx = info.injectTags(ctx)
+ ctx = info.injectTags(ctx, tags)
err := handler(srv, &wrappedServerStream{
ServerStream: stream,
ctx: ctx,
info: info,
+ tags: tags,
initial: true,
})
info.reportPrometheusMetrics(err)
@@ -345,6 +348,7 @@ type wrappedServerStream struct {
grpc.ServerStream
ctx context.Context
info *RequestInfo
+ tags grpcmwtags.Tags
initial bool
}
@@ -363,7 +367,7 @@ func (w *wrappedServerStream) RecvMsg(req interface{}) error {
w.info.extractRequestInfo(req)
// Re-inject the tags a second time here.
- w.ctx = w.info.injectTags(w.ctx)
+ w.ctx = w.info.injectTags(w.ctx, w.tags)
}
return err
diff --git a/internal/grpc/middleware/requestinfohandler/requestinfohandler_test.go b/internal/grpc/middleware/requestinfohandler/requestinfohandler_test.go
index a51755430..a3571c4c0 100644
--- a/internal/grpc/middleware/requestinfohandler/requestinfohandler_test.go
+++ b/internal/grpc/middleware/requestinfohandler/requestinfohandler_test.go
@@ -257,8 +257,8 @@ func TestGRPCTags(t *testing.T) {
}
_, err := interceptor(ctx, nil, nil, func(ctx context.Context, _ interface{}) (interface{}, error) {
info := newRequestInfo(ctx, "/gitaly.RepositoryService/OptimizeRepository", "unary")
-
- ctx = info.injectTags(ctx)
+ tags := grpcmwtags.NewTags()
+ ctx = info.injectTags(ctx, tags)
require.Equal(t, &RequestInfo{
correlationID: correlationID,