From 5e2a748bb71f09cd662f10e5b3de6155c9c742ac Mon Sep 17 00:00:00 2001 From: Zeger-Jan van de Weg Date: Wed, 18 Oct 2017 13:26:00 +0200 Subject: [PATCH] Add Gitaly data to the Peek performance bar --- app/views/peek/views/_gitaly.html.haml | 7 +++++ changelogs/unreleased/zj-peek-gitaly.yml | 5 ++++ config/initializers/peek.rb | 1 + lib/gitlab/gitaly_client.rb | 9 +++++++ lib/peek/views/gitaly.rb | 34 ++++++++++++++++++++++++ 5 files changed, 56 insertions(+) create mode 100644 app/views/peek/views/_gitaly.html.haml create mode 100644 changelogs/unreleased/zj-peek-gitaly.yml create mode 100644 lib/peek/views/gitaly.rb diff --git a/app/views/peek/views/_gitaly.html.haml b/app/views/peek/views/_gitaly.html.haml new file mode 100644 index 00000000000..a7d040d6821 --- /dev/null +++ b/app/views/peek/views/_gitaly.html.haml @@ -0,0 +1,7 @@ +- local_assigns.fetch(:view) + +%strong + %span{ data: { defer_to: "#{view.defer_key}-duration" } } ... + \/ + %span{ data: { defer_to: "#{view.defer_key}-calls" } } ... + Gitaly diff --git a/changelogs/unreleased/zj-peek-gitaly.yml b/changelogs/unreleased/zj-peek-gitaly.yml new file mode 100644 index 00000000000..bd2f2a07540 --- /dev/null +++ b/changelogs/unreleased/zj-peek-gitaly.yml @@ -0,0 +1,5 @@ +--- +title: Add Gitaly metrics to the performance bar +merge_request: +author: +type: other diff --git a/config/initializers/peek.rb b/config/initializers/peek.rb index a54d53cbbe2..1cff355346c 100644 --- a/config/initializers/peek.rb +++ b/config/initializers/peek.rb @@ -16,6 +16,7 @@ Peek.into Peek::Views::Redis Peek.into Peek::Views::Sidekiq Peek.into Peek::Views::Rblineprof Peek.into Peek::Views::GC +Peek.into Peek::Views::Gitaly # rubocop:disable Style/ClassAndModuleCamelCase class PEEK_DB_CLIENT diff --git a/lib/gitlab/gitaly_client.rb b/lib/gitlab/gitaly_client.rb index 6c1ae19ff11..6868be26758 100644 --- a/lib/gitlab/gitaly_client.rb +++ b/lib/gitlab/gitaly_client.rb @@ -33,6 +33,12 @@ module Gitlab MUTEX = Mutex.new private_constant :MUTEX + class << self + attr_accessor :query_time + end + + self.query_time = 0 + def self.stub(name, storage) MUTEX.synchronize do @stubs ||= {} @@ -83,11 +89,14 @@ module Gitlab # end # def self.call(storage, service, rpc, request) + start = Process.clock_gettime(Process::CLOCK_MONOTONIC) enforce_gitaly_request_limits(:call) kwargs = request_kwargs(storage) kwargs = yield(kwargs) if block_given? stub(service, storage).__send__(rpc, request, kwargs) # rubocop:disable GitlabSecurity/PublicSend + ensure + self.query_time += Process.clock_gettime(Process::CLOCK_MONOTONIC) - start end def self.request_kwargs(storage) diff --git a/lib/peek/views/gitaly.rb b/lib/peek/views/gitaly.rb new file mode 100644 index 00000000000..d519d8e86fa --- /dev/null +++ b/lib/peek/views/gitaly.rb @@ -0,0 +1,34 @@ +module Peek + module Views + class Gitaly < View + def duration + ::Gitlab::GitalyClient.query_time + end + + def calls + ::Gitlab::GitalyClient.get_request_count + end + + def results + { duration: formatted_duration, calls: calls } + end + + private + + 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