Commit 2f22dbe4 authored by John Cai's avatar John Cai

Add gitaly session id

parent 46044203
Pipeline #58484755 (#1181137) passed with stages
in 65 minutes and 26 seconds
---
title: Add gitaly session id & catfile-cache feature flag
merge_request: 27472
author:
type: performance
......@@ -219,6 +219,7 @@ module Gitlab
metadata['call_site'] = feature.to_s if feature
metadata['gitaly-servers'] = address_metadata(remote_storage) if remote_storage
metadata['x-gitlab-correlation-id'] = Labkit::Correlation::CorrelationId.current_id if Labkit::Correlation::CorrelationId.current_id
metadata['gitaly-session-id'] = session_id if feature_enabled?('catfile-cache')
metadata.merge!(server_feature_flags)
......@@ -235,7 +236,11 @@ module Gitlab
result
end
SERVER_FEATURE_FLAGS = %w[].freeze
def self.session_id
Gitlab::SafeRequestStore[:gitaly_session_id] ||= SecureRandom.uuid
end
SERVER_FEATURE_FLAGS = %w[catfile-cache].freeze
def self.server_feature_flags
SERVER_FEATURE_FLAGS.map do |f|
......
......@@ -142,6 +142,46 @@ describe Gitlab::GitalyClient do
end
end
describe '.request_kwargs' do
context 'when catfile-batch feature flag is on' do
before do
stub_feature_flags({ 'gitaly_catfile-cache': true })
end
it 'sets the gitaly-session-id in the metadata' do
results = described_class.request_kwargs('default', nil)
expect(results[:metadata]).to include('gitaly-session-id')
end
it 'sets a different gitaly-session-id per request when request store is not enabled' do
gitaly_session_id = described_class.request_kwargs('default', nil)[:metadata]['gitaly-session-id']
expect(described_class.request_kwargs('default', nil)[:metadata]['gitaly-session-id']).not_to eq(gitaly_session_id)
end
context 'when RequestStore is enabled', :request_store do
it 'sets the same gitaly-session-id on every outgoing request metadata' do
gitaly_session_id = described_class.request_kwargs('default', nil)[:metadata]['gitaly-session-id']
10.times do
expect(described_class.request_kwargs('default', nil)[:metadata]['gitaly-session-id']).to eq(gitaly_session_id)
end
end
end
end
context 'when catfile-batch feature flag is off' do
before do
stub_feature_flags({ 'gitaly_catfile-cache': false })
end
it 'does not set the gitaly-session-id in the metadata' do
results = described_class.request_kwargs('default', nil)
expect(results[:metadata]).not_to include('gitaly-session-id')
end
end
end
describe 'enforce_gitaly_request_limits?' do
def call_gitaly(count = 1)
(1..count).each do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment