summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-07-29 16:27:57 +0000
committerStan Hu <stanhu@gmail.com>2019-07-29 16:27:57 +0000
commit7064d48e2b74d5a92a16278085f3a0b46274911d (patch)
treec247a9decd0d06923d8051f0f408aa9b239aa3ad /lib
parent6686cd35039a84b123799b468dbf1b7b2e5f2a6e (diff)
parentad1c71663f7780838c7c90979419f3e3cf5ec580 (diff)
downloadgitlab-ce-7064d48e2b74d5a92a16278085f3a0b46274911d.tar.gz
Merge branch 'remove-peek-pg' into 'master'
Replace peek-pg with our own implementation Closes #44441 See merge request gitlab-org/gitlab-ce!31187
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/performance_bar/peek_query_tracker.rb45
-rw-r--r--lib/peek/views/active_record.rb25
-rw-r--r--lib/peek/views/detailed_view.rb12
-rw-r--r--lib/peek/views/gitaly.rb3
-rw-r--r--lib/peek/views/redis_detailed.rb19
-rw-r--r--lib/peek/views/rugged.rb3
6 files changed, 36 insertions, 71 deletions
diff --git a/lib/gitlab/performance_bar/peek_query_tracker.rb b/lib/gitlab/performance_bar/peek_query_tracker.rb
deleted file mode 100644
index 3a27e26eaba..00000000000
--- a/lib/gitlab/performance_bar/peek_query_tracker.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-# frozen_string_literal: true
-
-# Inspired by https://github.com/peek/peek-pg/blob/master/lib/peek/views/pg.rb
-# PEEK_DB_CLIENT is a constant set in config/initializers/peek.rb
-module Gitlab
- module PerformanceBar
- module PeekQueryTracker
- def sorted_queries
- PEEK_DB_CLIENT.query_details
- .sort { |a, b| b[:duration] <=> a[:duration] }
- end
-
- def results
- super.merge(queries: sorted_queries)
- end
-
- private
-
- def setup_subscribers
- super
-
- # Reset each counter when a new request starts
- before_request do
- PEEK_DB_CLIENT.query_details = []
- end
-
- subscribe('sql.active_record') do |_, start, finish, _, data|
- if Gitlab::SafeRequestStore.store[:peek_enabled]
- unless data[:cached]
- backtrace = Gitlab::Profiler.clean_backtrace(caller)
- track_query(data[:sql].strip, data[:binds], backtrace, start, finish)
- end
- end
- end
- end
-
- def track_query(raw_query, bindings, backtrace, start, finish)
- duration = (finish - start) * 1000.0
- query_info = { duration: duration.round(3), sql: raw_query, backtrace: backtrace }
-
- PEEK_DB_CLIENT.query_details << query_info
- end
- end
- end
-end
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)