Querying deployment count from GraphQL times out on analytics dashboards
There are intermittent timeouts when querying deployment frequency from GraphQL. Sample query: ``` query { group(fullPath: "gitlab-org") { flowMetrics { deploymentCount(from: "2025-01-01", to: "2025-01-30") { unit value } } } } ``` Logs of failures * https://log.gprd.gitlab.net/app/r/s/imfa2 Relevant backtrace snippet ``` "ee/app/graphql/ee/resolvers/analytics/cycle_analytics/deployment_count_resolver.rb:25:in `count'", "app/graphql/resolvers/analytics/cycle_analytics/deployment_count_resolver.rb:9:in `resolve'", "graphql (2.5.11) lib/graphql/schema/resolver.rb:118:in `public_send'", "graphql (2.5.11) lib/graphql/schema/resolver.rb:118:in `call_resolve'", "graphql (2.5.11) lib/graphql/schema/resolver.rb:105:in `block (3 levels) in resolve_with_support'", "graphql (2.5.11) lib/graphql/schema.rb:1647:in `after_lazy'", "graphql (2.5.11) lib/graphql/query.rb:30:in `after_lazy'", ``` ## Root cause The query load is proportional to how many environments are present in a group hierarchy. The timeout happens when we filter by production environments when fetching records from `daily_dora_metrics` table. ## Suggested fix We only create records on `daily_dora_metrics` for production environments at the [aggregation service](https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/lib/analytics/dora_metrics_aggregator.rb#L8), which makes this filter redundant. 1. Remove the filter by production env 2. Use `all_project_ids` scope when filtering by projects ``` diff --- a/ee/app/graphql/ee/resolvers/analytics/cycle_analytics/deployment_count_resolver.rb +++ b/ee/app/graphql/ee/resolvers/analytics/cycle_analytics/deployment_count_resolver.rb @@ -14,13 +14,11 @@ def count(args) # Only licensed customers can get the aggregated DORA data (premium, ultimate) return super unless ::Gitlab::Analytics::CycleAnalytics.licensed?(object) - projects_query = object.is_a?(Group) ? object.all_projects : object.project + projects_query = object.is_a?(Group) ? object.all_project_ids : object.project projects_query = projects_query.id_in(args[:project_ids]) if args[:project_ids] - environments = ::Environment.for_project(projects_query).for_tier(:production) - ::Dora::DailyMetrics - .for_environments(environments) + .for_projects(projects_query) #Introduce this new scope .in_range_of(args[:from].to_date, args[:to].to_date) .sum(:deployment_frequency) end ```
issue