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:
authorStan Hu <stanhu@gmail.com>2020-10-16 07:24:35 +0300
committerStan Hu <stanhu@gmail.com>2020-10-16 16:38:28 +0300
commit85ea048ee2084d960312d9a2401f421ec4f15a39 (patch)
treea538a38cbfbfd21dc19a6e1e82604384f29a1e8d
parent3bdd23173595a931aac476ad0c07c702c30f4391 (diff)
Send CORRELATION_ID to gitaly-lfs-smudge filter
This will make it possible to trace the internal API requests with the original user request. Note this doesn't solve the tracing problem entirely because Workhorse is currently ignoring `X-Request-Id` headers due to https://gitlab.com/gitlab-org/gitlab-workhorse/-/issues/309, but this is a prerequisite.
-rw-r--r--changelogs/unreleased/sh-correlation-id-lfs-smudge.yml5
-rw-r--r--internal/gitaly/service/repository/archive.go2
-rw-r--r--internal/gitaly/service/repository/archive_test.go7
-rw-r--r--internal/gitaly/service/repository/testhelper_test.go2
4 files changed, 14 insertions, 2 deletions
diff --git a/changelogs/unreleased/sh-correlation-id-lfs-smudge.yml b/changelogs/unreleased/sh-correlation-id-lfs-smudge.yml
new file mode 100644
index 000000000..8395e52fb
--- /dev/null
+++ b/changelogs/unreleased/sh-correlation-id-lfs-smudge.yml
@@ -0,0 +1,5 @@
+---
+title: Send CORRELATION_ID to gitaly-lfs-smudge filter
+merge_request: 2662
+author:
+type: changed
diff --git a/internal/gitaly/service/repository/archive.go b/internal/gitaly/service/repository/archive.go
index 79f4eb9ec..fb2fc7b5b 100644
--- a/internal/gitaly/service/repository/archive.go
+++ b/internal/gitaly/service/repository/archive.go
@@ -18,6 +18,7 @@ import (
"gitlab.com/gitlab-org/gitaly/internal/storage"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/streamio"
+ "gitlab.com/gitlab-org/labkit/correlation"
)
func (s *server) GetArchive(in *gitalypb.GetArchiveRequest, stream gitalypb.RepositoryService_GetArchiveServer) error {
@@ -162,6 +163,7 @@ func handleArchive(ctx context.Context, writer io.Writer, in *gitalypb.GetArchiv
fmt.Sprintf("GL_REPOSITORY=%s", in.GetRepository().GetGlRepository()),
fmt.Sprintf("GL_PROJECT_PATH=%s", in.GetRepository().GetGlProjectPath()),
fmt.Sprintf("GL_INTERNAL_CONFIG=%s", internalCfg),
+ fmt.Sprintf("CORRELATION_ID=%s", correlation.ExtractFromContext(ctx)),
}
var globals []git.Option
diff --git a/internal/gitaly/service/repository/archive_test.go b/internal/gitaly/service/repository/archive_test.go
index 63f717b90..1620b686f 100644
--- a/internal/gitaly/service/repository/archive_test.go
+++ b/internal/gitaly/service/repository/archive_test.go
@@ -16,6 +16,7 @@ import (
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/streamio"
+ "gitlab.com/gitlab-org/labkit/correlation"
"google.golang.org/grpc/codes"
)
@@ -504,6 +505,9 @@ func TestGetArchiveEnv(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
+ correlationID, _ := correlation.RandomID()
+ ctx = correlation.ContextWithCorrelation(ctx, correlationID)
+
req := &gitalypb.GetArchiveRequest{
Repository: testRepo,
CommitId: commitID,
@@ -517,7 +521,7 @@ func TestGetArchiveEnv(t *testing.T) {
require.NoError(t, err)
tmpFile.Write([]byte(`#!/bin/sh
-env | grep ^GL_`))
+env | grep -E "^GL_|CORRELATION"`))
tmpFile.Close()
oldBinPath := config.Config.Git.BinPath
@@ -535,6 +539,7 @@ env | grep ^GL_`))
require.Contains(t, string(data), "GL_REPOSITORY="+testhelper.GlRepository)
require.Contains(t, string(data), "GL_PROJECT_PATH="+testhelper.GlProjectPath)
require.Contains(t, string(data), "GL_INTERNAL_CONFIG="+string(cfgData))
+ require.Contains(t, string(data), "CORRELATION_ID="+correlationID)
}
func compressedFileContents(t *testing.T, format gitalypb.GetArchiveRequest_Format, name string) []byte {
diff --git a/internal/gitaly/service/repository/testhelper_test.go b/internal/gitaly/service/repository/testhelper_test.go
index 8a7582e38..c32431271 100644
--- a/internal/gitaly/service/repository/testhelper_test.go
+++ b/internal/gitaly/service/repository/testhelper_test.go
@@ -39,7 +39,7 @@ func newRepositoryClient(t *testing.T, serverSocketPath string) (gitalypb.Reposi
grpc.WithInsecure(),
grpc.WithPerRPCCredentials(gitalyauth.RPCCredentialsV2(config.Config.Auth.Token)),
}
- conn, err := grpc.Dial(serverSocketPath, connOpts...)
+ conn, err := client.Dial(serverSocketPath, connOpts)
if err != nil {
t.Fatal(err)
}