Loading
Allow selecting database diagnostics checks
What
Allow running database diagnostics checks individually instead of only all at once.
Why
Reviewer suggestion on !251254 (merged): !251254 (comment 3729162360)
Changes
Gitlab::Database::Diagnostics::Console::VIEWSis now a hash keyed by check name ('search_path' => Views::SchemaResolution,'autovacuum_settings' => Views::AutovacuumSettings) instead of an array.Console.runacceptscheck_names:and selects views from the registry. Nil or empty runs all checks, repeated names run once, names may be strings or symbols, and an unknown name raisesConsole::UnknownCheckErrorwith the valid list.- Per-check rake tasks are generated from a slug list in the rake file, e.g.
gitlab:db:diagnostics:search_path[database_names]andgitlab:db:diagnostics:autovacuum_settings[database_names]. The slug list is duplicated in the rake file because Zeitwerk autoloading is unavailable at rake load time. A spec fails if the rake list and the registry drift. - Shared task body moved to
Gitlab::Database::Diagnostics::RakeTask, since RuboCop (Rake/TopLevelMethodDefinition) forbids top-level methods in rake files. Console::Runnerrequiresviews:. Its old default of every view was unreachable, sinceConsole.runalways passes the selection.
Behavior is unchanged when no checks are requested: same output, same 0/1 exit code contract.
Usage
# all checks
bundle exec rake gitlab:db:diagnostics
# one check
bundle exec rake "gitlab:db:diagnostics:search_path[main]"
# autovacuum settings check
bundle exec rake "gitlab:db:diagnostics:autovacuum_settings[main]"How to verify
bundle exec rspec spec/lib/gitlab/database/diagnostics spec/tasks/gitlab/db/diagnostics_rake_spec.rb97 examples, all passing. Also verified with a live run of the per-check rake task.
Edited by Niko Belokolodov