Filter ignored tables and triggers from schema inconsistency reports
What does this MR do and why?
The filter for known schema inconsistencies compared the inconsistency type with names such as extra_tables, but the type is the validator class name. So the ignored test_replication table and the lock-writes triggers (gitlab_schema_write_trigger_for_*) were always reported. The filter now matches the validator classes, and the ignore lists move from db.rake into the filter.
The schema_inconsistencies Service Ping metric now applies the filter before it keeps the first 150 inconsistencies, so these triggers no longer fill the metric. This changes the metric's value on instances with these triggers. The metric is for troubleshooting and has no performance indicator type, so it keeps its key.
References
- Split out of !258353 (merged)
- Related to #632819
Screenshots or screen recordings
No UI change. Filtered ExtraTriggers output for the step below:
| Before | After |
|---|---|
["gitlab_schema_write_trigger_for_users"] |
[] |
How to set up and validate locally
-
In a Rails console on GDK, add a lock-writes trigger to
usersand filter theExtraTriggersresult. The transaction rolls the trigger back:conn = ApplicationRecord.connection validation = Gitlab::Schema::Validation conn.transaction do conn.execute(<<~SQL) CREATE TRIGGER gitlab_schema_write_trigger_for_users BEFORE INSERT ON users FOR EACH STATEMENT EXECUTE FUNCTION gitlab_schema_prevent_write(); SQL database = validation::Sources::Database.new(conn) structure_sql = validation::Sources::StructureSql.new(Rails.root.join('db/structure.sql')) filter = Gitlab::Database::SchemaValidation::InconsistencyFilter.new(%w[test_replication], ['gitlab_schema_write_trigger_for_']) inconsistencies = validation::Runner.new(structure_sql, database, validators: [validation::Validators::ExtraTriggers]).execute puts inconsistencies.filter_map(&filter).map(&:object_name).inspect raise ActiveRecord::Rollback end -
It prints
[]. On master, it prints["gitlab_schema_write_trigger_for_users"].
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.