diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 11:18:50 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 11:18:50 +0000 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /lib/peek | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) | |
download | gitlab-ce-8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781.tar.gz |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'lib/peek')
-rw-r--r-- | lib/peek/views/bullet_detailed.rb | 47 | ||||
-rw-r--r-- | lib/peek/views/elasticsearch.rb | 47 | ||||
-rw-r--r-- | lib/peek/views/gitaly.rb | 6 | ||||
-rw-r--r-- | lib/peek/views/redis_detailed.rb | 7 |
4 files changed, 100 insertions, 7 deletions
diff --git a/lib/peek/views/bullet_detailed.rb b/lib/peek/views/bullet_detailed.rb new file mode 100644 index 00000000000..8e6f72f565e --- /dev/null +++ b/lib/peek/views/bullet_detailed.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +module Peek + module Views + class BulletDetailed < DetailedView + WARNING_MESSAGE = "Unoptimized queries detected" + + def key + 'bullet' + end + + def results + return {} unless ::Bullet.enable? + return {} unless calls > 0 + + { + calls: calls, + details: details, + warnings: [WARNING_MESSAGE] + } + end + + private + + def details + notifications.map do |notification| + # there is no public method which returns pure backtace: + # https://github.com/flyerhzm/bullet/blob/9cda9c224a46786ecfa894480c4dd4d304db2adb/lib/bullet/notification/n_plus_one_query.rb + backtrace = notification.body_with_caller + + { + notification: "#{notification.title}: #{notification.body}", + backtrace: backtrace + } + end + end + + def calls + notifications.size + end + + def notifications + ::Bullet.notification_collector&.collection || [] + end + end + end +end diff --git a/lib/peek/views/elasticsearch.rb b/lib/peek/views/elasticsearch.rb new file mode 100644 index 00000000000..626a6fb1316 --- /dev/null +++ b/lib/peek/views/elasticsearch.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +module Peek + module Views + class Elasticsearch < DetailedView + DEFAULT_THRESHOLDS = { + calls: 5, + duration: 1000, + individual_call: 1000 + }.freeze + + THRESHOLDS = { + production: { + calls: 5, + duration: 1000, + individual_call: 1000 + } + }.freeze + + def key + 'es' + end + + def self.thresholds + @thresholds ||= THRESHOLDS.fetch(Rails.env.to_sym, DEFAULT_THRESHOLDS) + end + + private + + def duration + ::Gitlab::Instrumentation::ElasticsearchTransport.query_time * 1000 + end + + def calls + ::Gitlab::Instrumentation::ElasticsearchTransport.get_request_count + end + + def call_details + ::Gitlab::Instrumentation::ElasticsearchTransport.detail_store + end + + def format_call_details(call) + super.merge(request: "#{call[:method]} #{call[:path]}") + end + end + end +end diff --git a/lib/peek/views/gitaly.rb b/lib/peek/views/gitaly.rb index 7dc00b16cc0..566ca4496c4 100644 --- a/lib/peek/views/gitaly.rb +++ b/lib/peek/views/gitaly.rb @@ -40,12 +40,6 @@ module Peek super.merge(request: pretty_request || {}) end - - def setup_subscribers - subscribe 'start_processing.action_controller' do - ::Gitlab::GitalyClient.query_time = 0 - end - end end end end diff --git a/lib/peek/views/redis_detailed.rb b/lib/peek/views/redis_detailed.rb index 79845044d75..44ec0ec0f68 100644 --- a/lib/peek/views/redis_detailed.rb +++ b/lib/peek/views/redis_detailed.rb @@ -9,10 +9,15 @@ module Peek 'redis' end + def detail_store + ::Gitlab::Instrumentation::Redis.detail_store + end + private def format_call_details(call) - super.merge(cmd: format_command(call[:cmd])) + super.merge(cmd: format_command(call[:cmd]), + instance: call[:storage]) end def format_command(cmd) |