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:
authorQuang-Minh Nguyen <qmnguyen@gitlab.com>2023-02-27 05:42:53 +0300
committerQuang-Minh Nguyen <qmnguyen@gitlab.com>2023-02-27 05:42:53 +0300
commit96c93cc6264f0fb73ae586766999452cb2f22f7e (patch)
treebea2383477c6c64c1e41be4b2fed8376bd601445
parentfb7ac6faa5b8e8cad4a66e597665eb12d398b84d (diff)
Fix gitaly-hooks not exporting tracesqmnguyen0711/fix-git-hook-tracing
-rw-r--r--cmd/gitaly-hooks/hooks.go15
-rw-r--r--internal/git/hooks_options.go6
2 files changed, 16 insertions, 5 deletions
diff --git a/cmd/gitaly-hooks/hooks.go b/cmd/gitaly-hooks/hooks.go
index 11601d29a..b29554e1b 100644
--- a/cmd/gitaly-hooks/hooks.go
+++ b/cmd/gitaly-hooks/hooks.go
@@ -4,11 +4,6 @@ import (
"context"
"errors"
"fmt"
- "io"
- "net"
- "os"
- "path/filepath"
-
gitalyauth "gitlab.com/gitlab-org/gitaly/v15/auth"
"gitlab.com/gitlab-org/gitaly/v15/client"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
@@ -20,8 +15,13 @@ import (
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v15/streamio"
"gitlab.com/gitlab-org/labkit/tracing"
+ grpctracing "gitlab.com/gitlab-org/labkit/tracing/grpc"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
+ "io"
+ "net"
+ "os"
+ "path/filepath"
)
type hookError struct {
@@ -85,6 +85,7 @@ func run(args []string) error {
switch subCmd {
case "git":
+ tracing.Initialize(tracing.WithServiceName("gitaly-hooks-git"))
return executeHook(hookCommand{
exec: packObjectsHook,
hookType: git.PackObjectsHook,
@@ -99,6 +100,7 @@ func run(args []string) error {
return fmt.Errorf("subcommand name invalid: %q", hookName)
}
+ tracing.Initialize(tracing.WithServiceName(fmt.Sprintf("gitaly-hooks-%s", hookName)))
return executeHook(hookCommand, args[1:])
}
}
@@ -151,6 +153,9 @@ func dialGitaly(payload git.HooksPayload) (*grpc.ClientConn, error) {
dialOpts = append(dialOpts, grpc.WithPerRPCCredentials(gitalyauth.RPCCredentialsV2(payload.InternalSocketToken)))
}
+ dialOpts = append(dialOpts, grpc.WithUnaryInterceptor(grpctracing.UnaryClientTracingInterceptor()))
+ dialOpts = append(dialOpts, grpc.WithStreamInterceptor(grpctracing.StreamClientTracingInterceptor()))
+
conn, err := client.Dial("unix://"+payload.InternalSocket, dialOpts)
if err != nil {
return nil, fmt.Errorf("error when dialing: %w", err)
diff --git a/internal/git/hooks_options.go b/internal/git/hooks_options.go
index c99f87f92..54c40a37b 100644
--- a/internal/git/hooks_options.go
+++ b/internal/git/hooks_options.go
@@ -12,8 +12,13 @@ import (
"gitlab.com/gitlab-org/gitaly/v15/internal/metadata/featureflag"
"gitlab.com/gitlab-org/gitaly/v15/internal/transaction/txinfo"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
+ labkittracing "gitlab.com/gitlab-org/labkit/tracing"
)
+// envInjector is responsible for injecting environment variables required for tracing into
+// the child process.
+var envInjector = labkittracing.NewEnvInjector()
+
// WithDisabledHooks returns an option that satisfies the requirement to set up
// hooks, but won't in fact set up hook execution.
func WithDisabledHooks() CmdOpt {
@@ -124,6 +129,7 @@ func (cc *cmdCfg) configureHooks(
payload,
fmt.Sprintf("%s=%s", log.GitalyLogDirEnvKey, cfg.Logging.Dir),
)
+ cc.env = envInjector(ctx, cc.env)
cc.globals = append(cc.globals, ConfigPair{Key: "core.hooksPath", Value: gitCmdFactory.HooksPath(ctx)})
cc.hooksConfigured = true