Commit 8c8c706f authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'gitaly_feature_flag_metadata' into 'master'

Gitaly feature flag metadata

See merge request gitlab-org/gitlab-ce!14332
parents c7622606 1ba3c747
---
title: Add client and call site metadata to Gitaly calls for better traceability
merge_request: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/14332
author:
type: added
...@@ -28,6 +28,7 @@ module Gitlab ...@@ -28,6 +28,7 @@ module Gitlab
SERVER_VERSION_FILE = 'GITALY_SERVER_VERSION'.freeze SERVER_VERSION_FILE = 'GITALY_SERVER_VERSION'.freeze
MAXIMUM_GITALY_CALLS = 30 MAXIMUM_GITALY_CALLS = 30
CLIENT_NAME = (Sidekiq.server? ? 'gitlab-sidekiq' : 'gitlab-web').freeze
MUTEX = Mutex.new MUTEX = Mutex.new
private_constant :MUTEX private_constant :MUTEX
...@@ -79,7 +80,16 @@ module Gitlab ...@@ -79,7 +80,16 @@ module Gitlab
def self.request_metadata(storage) def self.request_metadata(storage)
encoded_token = Base64.strict_encode64(token(storage).to_s) encoded_token = Base64.strict_encode64(token(storage).to_s)
{ metadata: { 'authorization' => "Bearer #{encoded_token}" } } metadata = {
'authorization' => "Bearer #{encoded_token}",
'client_name' => CLIENT_NAME
}
feature_stack = Thread.current[:gitaly_feature_stack]
feature = feature_stack && feature_stack[0]
metadata['call_site'] = feature.to_s if feature
{ metadata: metadata }
end end
def self.token(storage) def self.token(storage)
...@@ -137,7 +147,14 @@ module Gitlab ...@@ -137,7 +147,14 @@ module Gitlab
Gitlab::Metrics.measure(metric_name) do Gitlab::Metrics.measure(metric_name) do
# Some migrate calls wrap other migrate calls # Some migrate calls wrap other migrate calls
allow_n_plus_1_calls do allow_n_plus_1_calls do
yield is_enabled feature_stack = Thread.current[:gitaly_feature_stack] ||= []
feature_stack.unshift(feature)
begin
yield is_enabled
ensure
feature_stack.shift
Thread.current[:gitaly_feature_stack] = nil if feature_stack.empty?
end
end end
end end
end end
......
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