Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-02-18 13:34:06 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-02-18 13:34:06 +0300
commit859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch)
treed7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /lib/gitlab/performance_bar/stats.rb
parent446d496a6d000c73a304be52587cd9bbc7493136 (diff)
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'lib/gitlab/performance_bar/stats.rb')
-rw-r--r--lib/gitlab/performance_bar/stats.rb29
1 files changed, 21 insertions, 8 deletions
diff --git a/lib/gitlab/performance_bar/stats.rb b/lib/gitlab/performance_bar/stats.rb
index d1504d88315..380340b80be 100644
--- a/lib/gitlab/performance_bar/stats.rb
+++ b/lib/gitlab/performance_bar/stats.rb
@@ -27,27 +27,40 @@ module Gitlab
end
def log_sql_queries(id, data)
- return [] unless queries = data.dig('data', 'active-record', 'details')
-
- queries.each do |query|
- next unless location = parse_backtrace(query['backtrace'])
+ queries_by_location(data).each do |location, queries|
+ next unless location
- log_info = location.merge(
+ duration = queries.sum { |query| query['duration'].to_f }
+ log_info = {
+ method_path: "#{location[:filename]}:#{location[:method]}",
+ filename: location[:filename],
type: :sql,
request_id: id,
- duration_ms: query['duration'].to_f
- )
+ count: queries.count,
+ duration_ms: duration
+ }
logger.info(log_info)
end
end
+ def queries_by_location(data)
+ return [] unless queries = data.dig('data', 'active-record', 'details')
+
+ queries.group_by do |query|
+ parse_backtrace(query['backtrace'])
+ end
+ end
+
def parse_backtrace(backtrace)
return unless match = /(?<filename>.*):(?<filenum>\d+):in `(?<method>.*)'/.match(backtrace.first)
{
filename: match[:filename],
- filenum: match[:filenum].to_i,
+ # filenum may change quite frequently with every change in the file,
+ # because the intention is to aggregate these queries, we group
+ # them rather by method name which should not change so frequently
+ # filenum: match[:filenum].to_i,
method: match[:method]
}
end