Skip to content

Add test for Service Ping generated queries for Snowflake

What does this MR do and why?

Related to #347545 (closed)

This adds a guard test for Gitlab::Usage::ServicePingReport that protects SQL metrics from any arbitrary changes by comparing them with an existing fixture file containing all SQL metric 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 a tighter control and review.

The fixture file can be regenerated using a rake task.

Timestamps are frozen, and a fixed set of Devise omniauth providers is used, in order to make queries that rely on them deterministic and not change every time the fixture file is regenerated. Some metrics will change with every generation, like alert bot user primary key ID, hostname and uuid, but they are ignored and changes to them won't change the outcome of the guard test.

Screenshots or screen recordings

These are strongly recommended to assist reviewers and reduce the time to merge your change.

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 example added in this MR should fail.

  2. Regenerate the fixture file with this rake task:

bundle exec rake gitlab:usage_data:generate_sql_metrics_fixture
  1. The affected query should now be updated in the fixture file. The new spec example should pass.

MR acceptance checklist

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

Edited by Piotr Skorupa

Merge request reports