From de13980f3795679958a65881a813723da37894f5 Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Fri, 14 May 2021 16:47:16 +0100 Subject: Fix opentracing setup for gitlab-sshd Previously, opentracing (if configured) was initialized late in the gitlab-shell process's lifespan, coming just before making a gRPC call to Gitaly. By moving the opentracing initialization to be at process startup, we make it available for the whole process lifecycle, which is very useful to gitlab-sshd, as it means we'll only call tracing.Initialize() once on process startup, rather than once per SSH connection. To get this working, we need to introduce a context to gitlab-sshd. This carries the client/service name, but also carries an initial correlation ID. The main outcome of this is that all calls to the authorized_keys endpoint from a given gitlab-sshd process will now share a correlation ID. I don't have a strong opinion about this either way. Changelog: fixed --- internal/command/command_test.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'internal/command/command_test.go') diff --git a/internal/command/command_test.go b/internal/command/command_test.go index a70ea84..3617d39 100644 --- a/internal/command/command_test.go +++ b/internal/command/command_test.go @@ -168,7 +168,7 @@ func TestFailingNew(t *testing.T) { } } -func TestContextWithCorrelationID(t *testing.T) { +func TestSetup(t *testing.T) { testCases := []struct { name string additionalEnv map[string]string @@ -190,16 +190,20 @@ func TestContextWithCorrelationID(t *testing.T) { resetEnvironment := addAdditionalEnv(tc.additionalEnv) defer resetEnvironment() - ctx, finished := ContextWithCorrelationID() + ctx, finished := Setup("foo", &config.Config{}) + defer finished() + require.NotNil(t, ctx, "ctx is nil") require.NotNil(t, finished, "finished is nil") + correlationID := correlation.ExtractFromContext(ctx) require.NotEmpty(t, correlationID) - if tc.expectedCorrelationID != "" { require.Equal(t, tc.expectedCorrelationID, correlationID) } - defer finished() + + clientName := correlation.ExtractClientNameFromContext(ctx) + require.Equal(t, "foo", clientName) }) } } -- cgit v1.2.1