2018-10-08 10:50:39 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-10-18 07:26:00 -04:00
|
|
|
module Peek
|
|
|
|
module Views
|
|
|
|
class Gitaly < View
|
|
|
|
def duration
|
|
|
|
::Gitlab::GitalyClient.query_time
|
|
|
|
end
|
|
|
|
|
|
|
|
def calls
|
|
|
|
::Gitlab::GitalyClient.get_request_count
|
|
|
|
end
|
|
|
|
|
|
|
|
def results
|
2018-03-06 09:02:18 -05:00
|
|
|
{
|
|
|
|
duration: formatted_duration,
|
|
|
|
calls: calls,
|
|
|
|
details: details
|
|
|
|
}
|
2017-10-18 07:26:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-03-06 09:02:18 -05:00
|
|
|
def details
|
2018-03-08 07:10:59 -05:00
|
|
|
::Gitlab::GitalyClient.list_call_details
|
2018-03-06 09:02:18 -05:00
|
|
|
.sort { |a, b| b[:duration] <=> a[:duration] }
|
|
|
|
.map(&method(:format_call_details))
|
|
|
|
end
|
|
|
|
|
|
|
|
def format_call_details(call)
|
2018-03-08 07:10:59 -05:00
|
|
|
pretty_request = call[:request]&.reject { |k, v| v.blank? }.to_h.pretty_inspect
|
2018-03-06 09:02:18 -05:00
|
|
|
|
|
|
|
call.merge(duration: (call[:duration] * 1000).round(3),
|
2018-03-08 07:10:59 -05:00
|
|
|
request: pretty_request || {})
|
2018-03-06 09:02:18 -05:00
|
|
|
end
|
|
|
|
|
2017-10-18 07:26:00 -04:00
|
|
|
def formatted_duration
|
|
|
|
ms = duration * 1000
|
|
|
|
if ms >= 1000
|
|
|
|
"%.2fms" % ms
|
|
|
|
else
|
|
|
|
"%.0fms" % ms
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def setup_subscribers
|
|
|
|
subscribe 'start_processing.action_controller' do
|
|
|
|
::Gitlab::GitalyClient.query_time = 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|