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 0000000000000000000000000000000000000000..7b5ea12e347115c4caf6e179d5ad4371bb0d3f36 --- /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 9593e1369b6a42a4403e827ba5dd4af1e18446fd..ed030ac618bcffa43edb53d0e87449b8a03c086b 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 856d1bb1e84cd977259ab921bebc87b4df4ed587..71225d3dfa4cab17aede289dc809d9812dd94d57 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