Skip to content

Resolve "Fix broken Service Ping metric queries"

What does this MR do and why?

Describe in detail what your merge request does and why.

Resolves #353559 (closed)

summary: During work around !81002 (merged) it was identified that some of generated by https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/usage/service_ping_report.rb#L39 SQL queries used at https://docs.gitlab.com/ee/api/usage_data.html#export-service-ping-sql-queries have invalid SQL syntax

The syntax errors were due to the following issues

  1. Invalid syntax due to order_by
    • counts.labels is the only one in this category
    • Labels model has a default_scope order(title: :asc) which interferes with the count sql statement
    • Resolution: Adding unscope(:order) to handle this
  2. Incorrect value datatype (nil vs 0)
    • When service ping report is generated for all_metrics_values, it calls .send(:count) which type casts values to int
    • eg. counts.jira_imports_total_imported_issues_count returns nil when executed as query, but expects 0
    • Resolution: Type casting the values to handle this
  3. Joins with select column on joined table

Screenshots or screen recordings

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

  1. run the test with bin/rspec spec/lib/gitlab/usage/service_ping_report_spec.rb:94 to verify

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 Tarun Vellishetty

Merge request reports

Loading