mirror of
https://gitlab.com/gitlab-org/gitlab-foss.git
synced 2025-08-06 10:19:48 +00:00
Add latest changes from gitlab-org/gitlab@master
This commit is contained in:
@ -1,11 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'yaml'
|
||||
|
||||
class Database
|
||||
class QueryAnalyzers
|
||||
attr_reader :analyzers
|
||||
|
||||
def initialize
|
||||
@analyzers = ObjectSpace.each_object(::Class).select { |c| c < Base }.map(&:new)
|
||||
config = YAML.safe_load_file(File.expand_path('query_analyzers.yml', __dir__))
|
||||
@analyzers = self.class.all.map do |subclass|
|
||||
subclass_name = subclass.to_s.split('::').last
|
||||
subclass.new(config[subclass_name])
|
||||
end
|
||||
end
|
||||
|
||||
def analyze(query)
|
||||
@ -15,6 +21,12 @@ class Database
|
||||
def save!
|
||||
analyzers.each(&:save!)
|
||||
end
|
||||
|
||||
class << self
|
||||
def all
|
||||
ObjectSpace.each_object(::Class).select { |c| c < Base }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
11
scripts/database/query_analyzers.yml
Normal file
11
scripts/database/query_analyzers.yml
Normal file
@ -0,0 +1,11 @@
|
||||
MultiplePartitionScanDetector:
|
||||
tables:
|
||||
- p_ci_builds
|
||||
- p_ci_builds_metadata
|
||||
- p_ci_job_annotations
|
||||
- p_ci_runner_machine_builds
|
||||
todos:
|
||||
# List query fingerprints which should be ignored until they are fixed.
|
||||
# These fingerprints can be found in the auto_explain pipeline artifacts.
|
||||
# Example:
|
||||
# - c2cfe803a497101b
|
@ -7,9 +7,11 @@ class Database
|
||||
class QueryAnalyzers
|
||||
class Base
|
||||
attr_accessor :output
|
||||
attr_reader :config
|
||||
|
||||
def initialize
|
||||
def initialize(config)
|
||||
@output = {}
|
||||
@config = config
|
||||
end
|
||||
|
||||
def filename
|
||||
|
@ -5,14 +5,12 @@ require_relative 'base'
|
||||
class Database
|
||||
class QueryAnalyzers
|
||||
class MultiplePartitionScanDetector < Database::QueryAnalyzers::Base
|
||||
TABLES = %w[
|
||||
p_ci_builds p_ci_builds_metadata p_ci_job_annotations p_ci_runner_machine_builds
|
||||
].freeze
|
||||
|
||||
def analyze(query)
|
||||
super
|
||||
|
||||
TABLES.each do |table_name|
|
||||
return if config['todos']&.include?(query['fingerprint'])
|
||||
|
||||
config['tables'].each do |table_name|
|
||||
if query['query'].include?(table_name) && query['plan'].to_s.include?('"Subplans Removed"=>0')
|
||||
(output[table_name] ||= []) << query
|
||||
end
|
||||
@ -20,7 +18,7 @@ class Database
|
||||
end
|
||||
|
||||
def save!
|
||||
TABLES.each do |table_name|
|
||||
config['tables'].each do |table_name|
|
||||
next unless output[table_name]
|
||||
|
||||
Zlib::GzipWriter.open(output_path("#{table_name}_multiple_partition_scans.ndjson")) do |file|
|
||||
|
Reference in New Issue
Block a user