diff options
Diffstat (limited to 'scripts/merge-auto-explain-logs')
-rwxr-xr-x | scripts/merge-auto-explain-logs | 47 |
1 files changed, 41 insertions, 6 deletions
diff --git a/scripts/merge-auto-explain-logs b/scripts/merge-auto-explain-logs index 0dff4fb33f8..114afc580d0 100755 --- a/scripts/merge-auto-explain-logs +++ b/scripts/merge-auto-explain-logs @@ -1,14 +1,49 @@ #!/usr/bin/env ruby # frozen_string_literal: true -require "set" -require "json" +require 'json' +require 'set' +require 'zlib' + +# Load query analyzers +require_relative File.expand_path('database/query_analyzers.rb', __dir__) + +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 +query_analyzers = Database::QueryAnalyzers.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| + query = JSON.parse(line) + fingerprint = query['fingerprint'] -ARGF.each_line do |line| - fingerprint = JSON.parse(line)['fingerprint'] - $stdout.puts(line) && $stdout.flush if fingerprints.add?(fingerprint) + next unless fingerprints.add?(fingerprint) + + query_analyzers.analyze(query) + + jobs << job_name + query['job_name'] = job_name + log.puts(JSON.generate(query)) + end + end + + File.delete(file) + end end -warn("auto_explain log contains #{fingerprints.size} entries") +query_analyzers.save! + +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 |