Skip to content

Resolve "Add test to check the query change"

Carlo Catimbang requested to merge 372201-add-test-to-check-query-change into master

What does this MR do and why?

This MR tests the Gitlab::Usage::ServicePingReport to guard against any changes to the queries.

This means that every time a metric is added or changed, the fixture file must be regenerated to acknowledge the changes to the SQL queries, which allows for tighter control and review.

How to set up and validate locally

  1. Make a change in a database metric that changes the underlying SQL query, for example:
diff --git a/lib/gitlab/usage_data.rb b/lib/gitlab/usage_data.rb
index 951ec5ea5c3..62e3fe818a3 100644
--- a/lib/gitlab/usage_data.rb
+++ b/lib/gitlab/usage_data.rb
@@ -129,7 +129,7 @@ def system_usage_data
             packages: count(::Packages::Package),
             pages_domains: count(PagesDomain),
             pool_repositories: count(PoolRepository),
-            projects: count(Project),
+            projects: count(Project.limit(1)),
             projects_creating_incidents: distinct_count(Issue.incident, :project_id),
             projects_imported_from_github: count(Project.where(import_type: 'github')),
             projects_with_repositories_enabled: count(ProjectFeature.where('repository_access_level > ?', ProjectFeature::DISABLED)),
  1. The spec should fail unless the fixture file is regenerated to acknowledge the changes

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Part of #372201

Edited by Carlo Catimbang

Merge request reports