Commit 7ed0806a authored by nmilojevic1's avatar nmilojevic1

Add cached queries to the performance bar

parent 2aaa1509
...@@ -36,7 +36,7 @@ export default { ...@@ -36,7 +36,7 @@ export default {
metric: 'active-record', metric: 'active-record',
title: 'pg', title: 'pg',
header: s__('PerformanceBar|SQL queries'), header: s__('PerformanceBar|SQL queries'),
keys: ['sql'], keys: ['sql', 'cached'],
}, },
{ {
metric: 'bullet', metric: 'bullet',
......
...@@ -5,6 +5,7 @@ module Peek ...@@ -5,6 +5,7 @@ module Peek
class ActiveRecord < DetailedView class ActiveRecord < DetailedView
DEFAULT_THRESHOLDS = { DEFAULT_THRESHOLDS = {
calls: 100, calls: 100,
cached_calls: 100,
duration: 3000, duration: 3000,
individual_call: 1000 individual_call: 1000
}.freeze }.freeze
...@@ -12,29 +13,53 @@ module Peek ...@@ -12,29 +13,53 @@ module Peek
THRESHOLDS = { THRESHOLDS = {
production: { production: {
calls: 100, calls: 100,
cached_calls: 100,
duration: 15000, duration: 15000,
individual_call: 5000 individual_call: 5000
} }
}.freeze }.freeze
def results
super.merge(calls: detailed_calls)
end
def self.thresholds def self.thresholds
@thresholds ||= THRESHOLDS.fetch(Rails.env.to_sym, DEFAULT_THRESHOLDS) @thresholds ||= THRESHOLDS.fetch(Rails.env.to_sym, DEFAULT_THRESHOLDS)
end end
private private
def detailed_calls
cached_calls? ? "#{calls} | #{cached_calls}" : calls
end
def calls
super - cached_calls
end
def cached_calls
detail_store.count { |item| item[:cached] == 'cached' }
end
def cached_calls?
detail_store.any? { |item| item[:cached] == 'cached' }
end
def warnings
(super + warning_for(cached_calls, self.class.thresholds[:cached_calls], label: "#{key} cached calls")).compact
end
def setup_subscribers def setup_subscribers
super super
subscribe('sql.active_record') do |_, start, finish, _, data| subscribe('sql.active_record') do |_, start, finish, _, data|
if Gitlab::PerformanceBar.enabled_for_request? if Gitlab::PerformanceBar.enabled_for_request?
unless data[:cached] detail_store << {
detail_store << { duration: finish - start,
duration: finish - start, sql: data[:sql].strip,
sql: data[:sql].strip, backtrace: Gitlab::BacktraceCleaner.clean_backtrace(caller),
backtrace: Gitlab::BacktraceCleaner.clean_backtrace(caller) cached: data[:cached] ? 'cached' : ''
} }
end
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment