diff options
author | Sean McGivern <sean@gitlab.com> | 2019-07-26 14:03:00 +0100 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2019-07-26 14:37:26 +0100 |
commit | ad1c71663f7780838c7c90979419f3e3cf5ec580 (patch) | |
tree | 59443b9ea0f860511610acf181e1eadbc8c88d34 /lib/peek/views | |
parent | 55f99e930e1c147ec191a234ff4881ea7e70ea61 (diff) | |
download | gitlab-ce-ad1c71663f7780838c7c90979419f3e3cf5ec580.tar.gz |
Replace peek-pg with our own implementationremove-peek-pg
This uses an ActiveRecord subscriber to get queries and calculate the
total query time from that. This means that the total will always be
consistent with the queries in the table. It does however mean that we
could potentially miss some queries that don't go through ActiveRecord.
Making this change also allows us to unify the response JSON a little
bit, making the frontend slightly simpler as a result.
Diffstat (limited to 'lib/peek/views')
-rw-r--r-- | lib/peek/views/active_record.rb | 25 | ||||
-rw-r--r-- | lib/peek/views/detailed_view.rb | 12 | ||||
-rw-r--r-- | lib/peek/views/gitaly.rb | 3 | ||||
-rw-r--r-- | lib/peek/views/redis_detailed.rb | 19 | ||||
-rw-r--r-- | lib/peek/views/rugged.rb | 3 |
5 files changed, 36 insertions, 26 deletions
diff --git a/lib/peek/views/active_record.rb b/lib/peek/views/active_record.rb new file mode 100644 index 00000000000..2d78818630d --- /dev/null +++ b/lib/peek/views/active_record.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +module Peek + module Views + class ActiveRecord < DetailedView + private + + def setup_subscribers + super + + subscribe('sql.active_record') do |_, start, finish, _, data| + if Gitlab::SafeRequestStore.store[:peek_enabled] + unless data[:cached] + detail_store << { + duration: finish - start, + sql: data[:sql].strip, + backtrace: Gitlab::Profiler.clean_backtrace(caller) + } + end + end + end + end + end + end +end diff --git a/lib/peek/views/detailed_view.rb b/lib/peek/views/detailed_view.rb index ebaf46478df..f4ca1cb5075 100644 --- a/lib/peek/views/detailed_view.rb +++ b/lib/peek/views/detailed_view.rb @@ -11,22 +11,26 @@ module Peek } end + def detail_store + ::Gitlab::SafeRequestStore["#{key}_call_details"] ||= [] + end + private def duration - raise NotImplementedError + detail_store.map { |entry| entry[:duration] }.sum # rubocop:disable CodeReuse/ActiveRecord end def calls - raise NotImplementedError + detail_store.count end def call_details - raise NotImplementedError + detail_store end def format_call_details(call) - raise NotImplementedError + call.merge(duration: (call[:duration] * 1000).round(3)) end def details diff --git a/lib/peek/views/gitaly.rb b/lib/peek/views/gitaly.rb index 067aaf31fbc..6ad6ddfd89d 100644 --- a/lib/peek/views/gitaly.rb +++ b/lib/peek/views/gitaly.rb @@ -20,8 +20,7 @@ module Peek def format_call_details(call) pretty_request = call[:request]&.reject { |k, v| v.blank? }.to_h.pretty_inspect - call.merge(duration: (call[:duration] * 1000).round(3), - request: pretty_request || {}) + super.merge(request: pretty_request || {}) end def setup_subscribers diff --git a/lib/peek/views/redis_detailed.rb b/lib/peek/views/redis_detailed.rb index c61a1e91282..a64ea672895 100644 --- a/lib/peek/views/redis_detailed.rb +++ b/lib/peek/views/redis_detailed.rb @@ -42,27 +42,10 @@ module Peek 'redis' end - def detail_store - ::Gitlab::SafeRequestStore['redis_call_details'] ||= [] - end - private - def duration - detail_store.map { |entry| entry[:duration] }.sum # rubocop:disable CodeReuse/ActiveRecord - end - - def calls - detail_store.count - end - - def call_details - detail_store - end - def format_call_details(call) - call.merge(cmd: format_command(call[:cmd]), - duration: (call[:duration] * 1000).round(3)) + super.merge(cmd: format_command(call[:cmd])) end def format_command(cmd) diff --git a/lib/peek/views/rugged.rb b/lib/peek/views/rugged.rb index f0cd520fb8b..6b9d3e7b1a3 100644 --- a/lib/peek/views/rugged.rb +++ b/lib/peek/views/rugged.rb @@ -24,8 +24,7 @@ module Peek end def format_call_details(call) - call.merge(duration: (call[:duration] * 1000).round(3), - args: format_args(call[:args])) + super.merge(args: format_args(call[:args])) end def format_args(args) |