Skip to content
代码片段 群组 项目
提交 947987cb 编辑于 作者: Matt Kasa's avatar Matt Kasa 提交者: Michael Kozono
浏览文件

Record auto_explain for all merge request pipelines

上级 ebb7139d
No related branches found
No related tags found
无相关合并请求
......@@ -573,11 +573,8 @@ rspec:merge-auto-explain-logs:
- .rails:rules:rspec-merge-auto-explain-logs
stage: post-test
needs: !reference ["rspec:coverage", "needs"]
before_script:
- source scripts/utils.sh
- source scripts/rspec_helpers.sh
script:
- merge_auto_explain_logs
- scripts/merge-auto-explain-logs
artifacts:
name: auto-explain-logs
expire_in: 31d
......
......@@ -95,9 +95,6 @@
.if-merge-request-labels-skip-undercoverage: &if-merge-request-labels-skip-undercoverage
if: '$CI_MERGE_REQUEST_LABELS =~ /pipeline:skip-undercoverage/'
.if-merge-request-labels-record-queries: &if-merge-request-labels-record-queries
if: '$CI_MERGE_REQUEST_LABELS =~ /pipeline:record-queries/'
.if-merge-request-labels-jh-contribution: &if-merge-request-labels-jh-contribution
if: '$CI_MERGE_REQUEST_LABELS =~ /JiHu contribution/'
......@@ -2290,7 +2287,8 @@
- <<: *if-merge-request-labels-pipeline-expedite
when: never
- <<: *if-merge-request-labels-run-all-rspec
- <<: *if-merge-request-labels-record-queries
- <<: *if-merge-request
changes: *code-backstage-patterns
- <<: *if-default-branch-refs
changes: *code-patterns
......
#!/usr/bin/env ruby
# frozen_string_literal: true
require "set"
require "json"
require 'json'
require 'set'
require 'zlib'
source = ENV['CI_MERGE_REQUEST_SOURCE_BRANCH_SHA']
target = ENV['CI_MERGE_REQUEST_TARGET_BRANCH_SHA']
log_path = ENV['RSPEC_AUTO_EXPLAIN_LOG_PATH']
logs_path = File.dirname(log_path)
exit(0) unless Dir.exist?(logs_path)
fingerprints = Set.new
jobs = Set.new
JOB_NAME = %r{^(.*)\.\d+\.[^.]+\.ndjson\.gz$}
Zlib::GzipWriter.open(log_path) do |log|
Dir[File.join(logs_path, '*.gz')].reject { |p| p == log_path }.each do |file|
job_name = File.basename(file)[JOB_NAME, 1]
Zlib::GzipReader.open(file) do |gz|
gz.each_line do |line|
json = JSON.parse(line)
fingerprint = json['fingerprint']
next unless fingerprints.add?(fingerprint)
jobs << job_name
json['job_name'] = job_name
log.puts(json.to_s)
end
end
ARGF.each_line do |line|
fingerprint = JSON.parse(line)['fingerprint']
$stdout.puts(line) && $stdout.flush if fingerprints.add?(fingerprint)
File.delete(file)
end
end
warn("auto_explain log contains #{fingerprints.size} entries")
warn("auto_explain log contains #{fingerprints.size} entries from: #{jobs.to_a.sort.join(', ')}")
warn("auto_explain comparison of #{target} to #{source}") if source && target
......@@ -486,13 +486,3 @@ function is_rspec_last_run_results_file_missing() {
return 1
fi
}
function merge_auto_explain_logs() {
local auto_explain_logs_path="$(dirname "${RSPEC_AUTO_EXPLAIN_LOG_PATH}")/"
for file in ${auto_explain_logs_path}*.gz; do
(gunzip -c "${file}" && rm -f "${file}" || true)
done | \
scripts/merge-auto-explain-logs | \
gzip -c > "${RSPEC_AUTO_EXPLAIN_LOG_PATH}"
}
......@@ -120,8 +120,8 @@ def record_auto_explain?(connection)
return false if connection.database_version.to_s[0..1].to_i < 14
return false if connection.select_one('SHOW is_superuser')['is_superuser'] != 'on'
# This condition matches the pipeline rules for if-merge-request-labels-record-queries
return true if ENV['CI_MERGE_REQUEST_LABELS']&.include?('pipeline:record-queries')
# This condition matches the pipeline rules for if-merge-request
return true if %w[detached merged_result].include?(ENV['CI_MERGE_REQUEST_EVENT_TYPE'])
# This condition matches the pipeline rules for if-default-branch-refs
ENV['CI_COMMIT_REF_NAME'] == ENV['CI_DEFAULT_BRANCH'] && !ENV['CI_MERGE_REQUEST_IID']
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册