blob: a481f7a56825e79a488aadb06bf63e443458fa07 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# frozen_string_literal: true
module Gitlab
module Usage
module Metrics
module Instrumentations
class SchemaInconsistenciesMetric < GenericMetric
MAX_INCONSISTENCIES = 150 # Limit the number of inconsistencies reported to avoid large payloads
value do
runner = Gitlab::Schema::Validation::Runner.new(structure_sql, database, validators: validators)
inconsistencies = runner.execute
inconsistencies.take(MAX_INCONSISTENCIES).map do |inconsistency|
{
object_name: inconsistency.object_name,
inconsistency_type: inconsistency.type,
object_type: inconsistency.object_type
}
end
end
class << self
private
def validators
Gitlab::Schema::Validation::Validators::Base.all_validators
end
def database
database_model = Gitlab::Database.database_base_models[Gitlab::Database::MAIN_DATABASE_NAME]
Gitlab::Schema::Validation::Sources::Database.new(database_model.connection)
end
def structure_sql
stucture_sql_path = Rails.root.join('db/structure.sql')
Gitlab::Schema::Validation::Sources::StructureSql.new(stucture_sql_path)
end
end
end
end
end
end
end
|