From 89833915c7c5d66ab5952ca1daf85e99ca3ca14b Mon Sep 17 00:00:00 2001 From: John Cai Date: Fri, 18 Jul 2025 16:40:10 -0400 Subject: [PATCH] gitaly: Set the grpc-encoding header Set the grpc-encoding header to turn on grpc compression. Gate this by a feature flag so we can test the effects of turning this on. --- .../undefined/gitaly_use_gzip_compression.yml | 8 ++++++++ lib/gitlab/gitaly_client.rb | 7 ++++--- spec/lib/gitlab/gitaly_client_spec.rb | 9 ++++++++- 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 config/feature_flags/undefined/gitaly_use_gzip_compression.yml diff --git a/config/feature_flags/undefined/gitaly_use_gzip_compression.yml b/config/feature_flags/undefined/gitaly_use_gzip_compression.yml new file mode 100644 index 00000000000000..7b5ea12e347115 --- /dev/null +++ b/config/feature_flags/undefined/gitaly_use_gzip_compression.yml @@ -0,0 +1,8 @@ +--- +name: gitaly_use_gzip_compression +introduced_by_url: +rollout_issue_url: +milestone: +type: undefined +group: group::gitaly +default_enabled: false diff --git a/lib/gitlab/gitaly_client.rb b/lib/gitlab/gitaly_client.rb index 9593e1369b6a42..ed030ac618bcff 100644 --- a/lib/gitlab/gitaly_client.rb +++ b/lib/gitlab/gitaly_client.rb @@ -286,7 +286,7 @@ def self.execute(storage, service, rpc, request, remote_storage:, timeout:, gita Gitlab::RequestContext.instance.ensure_deadline_not_exceeded! raise_if_concurrent_ruby! - kwargs = request_kwargs(storage, timeout: timeout.to_f, remote_storage: remote_storage, gitaly_context: gitaly_context) + kwargs = request_kwargs(storage, timeout: timeout.to_f, remote_storage: remote_storage, gitaly_context: gitaly_context, rpc: rpc) kwargs = yield(kwargs) if block_given? stub(service, storage).__send__(rpc, request, kwargs) # rubocop:disable GitlabSecurity/PublicSend @@ -324,7 +324,7 @@ def self.authorization_token(storage) end private_class_method :authorization_token - def self.request_kwargs(storage, timeout:, remote_storage: nil, gitaly_context: {}) + def self.request_kwargs(storage, timeout:, remote_storage: nil, gitaly_context: {}, rpc: nil) metadata = { 'authorization' => "Bearer #{authorization_token(storage)}", 'client_name' => CLIENT_NAME @@ -349,8 +349,9 @@ def self.request_kwargs(storage, timeout:, remote_storage: nil, gitaly_context: metadata['remote_ip'] = context_data['meta.remote_ip'] if context_data&.fetch('meta.remote_ip', nil) metadata['relative-path-bin'] = relative_path if relative_path metadata['gitaly-client-context-bin'] = gitaly_context.to_json if gitaly_context.present? - + metadata['grpc-accept-encoding'] = 'gzip' if Feature::Gitaly.enabled_for_any?(:gitaly_use_gzip_compression) metadata.merge!(Feature::Gitaly.server_feature_flags(**feature_flag_actors)) + metadata.merge!(route_to_primary) deadline_info = request_deadline(timeout) diff --git a/spec/lib/gitlab/gitaly_client_spec.rb b/spec/lib/gitlab/gitaly_client_spec.rb index 856d1bb1e84cd9..71225d3dfa4cab 100644 --- a/spec/lib/gitlab/gitaly_client_spec.rb +++ b/spec/lib/gitlab/gitaly_client_spec.rb @@ -394,6 +394,12 @@ def stub_repos_storages(address) expect(results[:metadata]).to include('gitaly-session-id') end + it 'sets grpc-accept-encoding to gzip' do + kwargs = described_class.request_kwargs('default', timeout: 1) + + expect(kwargs[:metadata]['grpc-accept-encoding']).to eq('gzip') + end + context 'with gitaly_context' do let(:gitaly_context) { { key: :value } } @@ -1023,7 +1029,8 @@ def call_gitaly(count = 1) it 'passes the gitaly_context to .request_kwargs' do expect(described_class).to receive(:request_kwargs).with( - 'default', timeout: 10.seconds, remote_storage: nil, gitaly_context: gitaly_context + 'default', timeout: 10.seconds, remote_storage: nil, gitaly_context: gitaly_context, + rpc: :find_local_branches ).and_call_original execute -- GitLab