2019-07-26 09:03:00 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Peek
|
|
|
|
module Views
|
|
|
|
class ActiveRecord < DetailedView
|
2019-08-06 11:04:43 -04:00
|
|
|
DEFAULT_THRESHOLDS = {
|
|
|
|
calls: 100,
|
2019-09-03 08:13:36 -04:00
|
|
|
duration: 3000,
|
|
|
|
individual_call: 1000
|
2019-08-06 11:04:43 -04:00
|
|
|
}.freeze
|
|
|
|
|
|
|
|
THRESHOLDS = {
|
|
|
|
production: {
|
|
|
|
calls: 100,
|
2019-09-03 08:13:36 -04:00
|
|
|
duration: 15000,
|
|
|
|
individual_call: 5000
|
2019-08-06 11:04:43 -04:00
|
|
|
}
|
|
|
|
}.freeze
|
|
|
|
|
|
|
|
def self.thresholds
|
|
|
|
@thresholds ||= THRESHOLDS.fetch(Rails.env.to_sym, DEFAULT_THRESHOLDS)
|
|
|
|
end
|
|
|
|
|
2019-07-26 09:03:00 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def setup_subscribers
|
|
|
|
super
|
|
|
|
|
|
|
|
subscribe('sql.active_record') do |_, start, finish, _, data|
|
2019-08-27 07:40:44 -04:00
|
|
|
if Gitlab::PerformanceBar.enabled_for_request?
|
2019-07-26 09:03:00 -04:00
|
|
|
unless data[:cached]
|
|
|
|
detail_store << {
|
|
|
|
duration: finish - start,
|
|
|
|
sql: data[:sql].strip,
|
2019-12-27 10:08:16 -05:00
|
|
|
backtrace: Gitlab::BacktraceCleaner.clean_backtrace(caller)
|
2019-07-26 09:03:00 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|