Validate existing monitor metrics
The metrics in usage_data.rb
(CE, EE) often use a time period query, with the intention that we can see the value of those metric queries between a given time period.
For example, my interpretation of intention of distinct_count(::Project.with_enabled_error_tracking.where(time_period), :creator_id)
is: "Count the distinct projects, where the error tracking setting was enabled between the time period".
However, when this runs the SQL query actually looks like:
SELECT COUNT(DISTINCT "projects"."creator_id")
FROM "projects"
INNER JOIN "project_error_tracking_settings" ON "project_error_tracking_settings"."project_id" = "projects"."id"
WHERE "project_error_tracking_settings"."enabled" = true
AND "projects"."created_at" BETWEEN "2020-09-14 19:59:15.179470"
AND "2020-10-12 19:59:15.179636"
AND "projects"."creator_id" BETWEEN 0
AND 100000
The important part is AND "projects"."created_at" BETWEEN "2020-09-14 19:59:15.179470" AND "2020-10-12 19:59:15.179636"
.
We are actually scoping by when the Project was created, not when the error tracking setting was added or enabled.
This is the case for a lot of our metrics, including:
projects_with_tracing_enabled: distinct_count(::Project.with_tracing_enabled.where(time_period), :creator_id)
projects_prometheus_active: distinct_count(::Project.with_active_prometheus_service.where(time_period), :creator_id)
projects_with_error_tracking_enabled: distinct_count(::Project.with_enabled_error_tracking.where(time_period), :creator_id)
Edited by Sean Arnold