Commit 582447d9 authored by Sean McGivern's avatar Sean McGivern

Capture Gitaly calls that don't go through `migrate`

parent 5bfa93e3
...@@ -119,7 +119,8 @@ module Gitlab ...@@ -119,7 +119,8 @@ module Gitlab
# #
def self.call(storage, service, rpc, request, remote_storage: nil, timeout: nil) def self.call(storage, service, rpc, request, remote_storage: nil, timeout: nil)
start = Gitlab::Metrics::System.monotonic_time start = Gitlab::Metrics::System.monotonic_time
@last_request = request.is_a?(Google::Protobuf::MessageExts) ? request.to_h : nil request_hash = request.is_a?(Google::Protobuf::MessageExts) ? request.to_h : {}
@current_call_id ||= SecureRandom.uuid
enforce_gitaly_request_limits(:call) enforce_gitaly_request_limits(:call)
...@@ -137,6 +138,10 @@ module Gitlab ...@@ -137,6 +138,10 @@ module Gitlab
gitaly_controller_action_duration_seconds.observe( gitaly_controller_action_duration_seconds.observe(
current_transaction_labels.merge(gitaly_service: service.to_s, rpc: rpc.to_s), current_transaction_labels.merge(gitaly_service: service.to_s, rpc: rpc.to_s),
duration) duration)
add_call_details(id: @current_call_id, feature: service, duration: duration, request: request_hash)
@current_call_id = nil
end end
def self.handle_grpc_unavailable!(ex) def self.handle_grpc_unavailable!(ex)
...@@ -254,15 +259,16 @@ module Gitlab ...@@ -254,15 +259,16 @@ module Gitlab
feature_stack.unshift(feature) feature_stack.unshift(feature)
begin begin
start = Gitlab::Metrics::System.monotonic_time start = Gitlab::Metrics::System.monotonic_time
@current_call_id = SecureRandom.uuid
call_details = { id: @current_call_id }
yield is_enabled yield is_enabled
ensure ensure
total_time = Gitlab::Metrics::System.monotonic_time - start total_time = Gitlab::Metrics::System.monotonic_time - start
gitaly_migrate_call_duration_seconds.observe({ gitaly_enabled: is_enabled, feature: feature }, total_time) gitaly_migrate_call_duration_seconds.observe({ gitaly_enabled: is_enabled, feature: feature }, total_time)
feature_stack.shift feature_stack.shift
Thread.current[:gitaly_feature_stack] = nil if feature_stack.empty? Thread.current[:gitaly_feature_stack] = nil if feature_stack.empty?
add_call_details(feature: feature,
duration: total_time, add_call_details(call_details.merge(feature: feature, duration: total_time))
request: is_enabled ? @last_request : {})
end end
end end
end end
...@@ -350,16 +356,19 @@ module Gitlab ...@@ -350,16 +356,19 @@ module Gitlab
end end
def self.add_call_details(details) def self.add_call_details(details)
return unless RequestStore.active? && RequestStore.store[:peek_enabled] id = details.delete(:id)
return unless id && RequestStore.active? && RequestStore.store[:peek_enabled]
RequestStore.store['gitaly_call_details'] ||= [] RequestStore.store['gitaly_call_details'] ||= {}
RequestStore.store['gitaly_call_details'] << details RequestStore.store['gitaly_call_details'][id] ||= {}
RequestStore.store['gitaly_call_details'][id].merge!(details)
end end
def self.call_details def self.list_call_details
return [] unless RequestStore.active? && RequestStore.store[:peek_enabled] return {} unless RequestStore.active? && RequestStore.store[:peek_enabled]
RequestStore.store['gitaly_call_details'] || [] RequestStore.store['gitaly_call_details'] || {}
end end
def self.expected_server_version def self.expected_server_version
......
...@@ -20,16 +20,17 @@ module Peek ...@@ -20,16 +20,17 @@ module Peek
private private
def details def details
::Gitlab::GitalyClient.call_details ::Gitlab::GitalyClient.list_call_details
.values
.sort { |a, b| b[:duration] <=> a[:duration] } .sort { |a, b| b[:duration] <=> a[:duration] }
.map(&method(:format_call_details)) .map(&method(:format_call_details))
end end
def format_call_details(call) def format_call_details(call)
pretty_request = call[:request].reject { |k, v| v.blank? }.to_h.pretty_inspect pretty_request = call[:request]&.reject { |k, v| v.blank? }.to_h.pretty_inspect
call.merge(duration: (call[:duration] * 1000).round(3), call.merge(duration: (call[:duration] * 1000).round(3),
request: pretty_request) request: pretty_request || {})
end end
def formatted_duration def formatted_duration
......
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