summaryrefslogtreecommitdiff
path: root/internal/command/uploadpack
diff options
context:
space:
mode:
authorIgor Drozdov <idrozdov@gitlab.com>2022-02-18 13:10:38 +0300
committerIgor Drozdov <idrozdov@gitlab.com>2022-03-07 16:54:15 +0300
commite1ddbdd161a28ff53ca4d3b3f0fc4fa19687d80b (patch)
tree9427a8f7add05d0eece7df0c48638209bea88d8d /internal/command/uploadpack
parentede95ae77b591fdffab6ea1f7b1c01e4402af2e1 (diff)
downloadgitlab-shell-e1ddbdd161a28ff53ca4d3b3f0fc4fa19687d80b.tar.gz
Reuse Gitaly conns and Sidechannel
When gitlab-sshd has been introduced we've started running our own SSH server. In this case we're able to cache and reuse Gitaly connections and Registry. It helps to reduce memory usage.
Diffstat (limited to 'internal/command/uploadpack')
-rw-r--r--internal/command/uploadpack/gitalycall.go18
-rw-r--r--internal/command/uploadpack/gitalycall_test.go11
2 files changed, 13 insertions, 16 deletions
diff --git a/internal/command/uploadpack/gitalycall.go b/internal/command/uploadpack/gitalycall.go
index 43ae4f8..96dd823 100644
--- a/internal/command/uploadpack/gitalycall.go
+++ b/internal/command/uploadpack/gitalycall.go
@@ -13,26 +13,20 @@ import (
)
func (c *Command) performGitalyCall(ctx context.Context, response *accessverifier.Response) error {
- gc := &handler.GitalyCommand{
- Config: c.Config,
- ServiceName: string(commandargs.UploadPack),
- Address: response.Gitaly.Address,
- Token: response.Gitaly.Token,
- Features: response.Gitaly.Features,
- }
+ gc := handler.NewGitalyCommand(c.Config, string(commandargs.UploadPack), response)
if response.Gitaly.UseSidechannel {
- gc.DialSidechannel = true
request := &pb.SSHUploadPackWithSidechannelRequest{
Repository: &response.Gitaly.Repo,
GitProtocol: c.Args.Env.GitProtocolVersion,
GitConfigOptions: response.GitConfigOptions,
}
- return gc.RunGitalyCommand(ctx, func(ctx context.Context, conn *grpc.ClientConn, registry *client.SidechannelRegistry) (int32, error) {
- ctx, cancel := gc.PrepareContext(ctx, request.Repository, response, c.Args.Env)
+ return gc.RunGitalyCommand(ctx, func(ctx context.Context, conn *grpc.ClientConn) (int32, error) {
+ ctx, cancel := gc.PrepareContext(ctx, request.Repository, c.Args.Env)
defer cancel()
+ registry := c.Config.GitalyClient.SidechannelRegistry
rw := c.ReadWriter
return client.UploadPackWithSidechannel(ctx, conn, registry, rw.In, rw.Out, rw.ErrOut, request)
})
@@ -44,8 +38,8 @@ func (c *Command) performGitalyCall(ctx context.Context, response *accessverifie
GitConfigOptions: response.GitConfigOptions,
}
- return gc.RunGitalyCommand(ctx, func(ctx context.Context, conn *grpc.ClientConn, registry *client.SidechannelRegistry) (int32, error) {
- ctx, cancel := gc.PrepareContext(ctx, request.Repository, response, c.Args.Env)
+ return gc.RunGitalyCommand(ctx, func(ctx context.Context, conn *grpc.ClientConn) (int32, error) {
+ ctx, cancel := gc.PrepareContext(ctx, request.Repository, c.Args.Env)
defer cancel()
rw := c.ReadWriter
diff --git a/internal/command/uploadpack/gitalycall_test.go b/internal/command/uploadpack/gitalycall_test.go
index 213b6f9..e0a15ee 100644
--- a/internal/command/uploadpack/gitalycall_test.go
+++ b/internal/command/uploadpack/gitalycall_test.go
@@ -97,15 +97,18 @@ func TestUploadPack_withSidechannel(t *testing.T) {
Env: env,
}
+ ctx := correlation.ContextWithCorrelation(context.Background(), "a-correlation-id")
+ ctx = correlation.ContextWithClientName(ctx, "gitlab-shell-tests")
+
+ cfg := &config.Config{GitlabUrl: url}
+ cfg.GitalyClient.InitSidechannelRegistry(ctx)
+
cmd := &Command{
- Config: &config.Config{GitlabUrl: url},
+ Config: cfg,
Args: args,
ReadWriter: &readwriter.ReadWriter{ErrOut: output, Out: output, In: input},
}
- ctx := correlation.ContextWithCorrelation(context.Background(), "a-correlation-id")
- ctx = correlation.ContextWithClientName(ctx, "gitlab-shell-tests")
-
err := cmd.Execute(ctx)
require.NoError(t, err)