Add retention user metrics to DuoWorkflows aggregation engine
What does this MR do and why?
Adds four retention window metrics to the DuoWorkflows aggregation engine. All four are keyed on user_id and windowed over the created_at date bucket:
returning_users(retained_count) — unique users who also ran a flow in the previous periodjoined_users(acquired_count) — unique users who ran a flow in this period but not the previous onechurned_users(churned_count) — unique users who ran a flow in the previous period but not this oneprevious_period_users(lagged_count) — unique users in the previous period
Wiring these up surfaced a bug in two of the metric types. LaggedCount#to_inner_arel and RetainedCount#to_inner_arel returned nil, and their outer queries referenced the raw column name. That relies on the inner query carrying the column through its primary-key projection, which only holds when the primary key includes that column. On duo_workflows_workflows_enriched the primary key is (traversal_path, created_at, id), so user_id was never projected and the metric could not resolve it. Both now project the expression column explicitly in to_inner_arel and reference the generated local alias in to_outer_arel. AcquiredCount and ChurnedCount already projected the column explicitly and only get comment changes.
doc/api/graphql/reference/_index.md and public/-/graphql/introspection_result.json are regenerated, not hand-edited.
References
- Issue: Add retention user metrics to the DuoWorkflows aggregation engine
- Two review threads asked for the comments above
to_inner_arelto describe the current state rather than the previous implementation. Commit 809b0ea1 addresses them across all four metric types.
Screenshots or screen recordings
No UI changes — backend and GraphQL schema only.
How to set up and validate locally
-
Make sure ClickHouse is running in your GDK and the
duo_workflows_workflows_enrichedtable has data. -
Run the specs. The
--tag click_houseflag is required:bundle exec rspec ee/spec/models/analytics/aggregation_engines/duo_workflows_spec.rb --tag click_house bundle exec rspec ee/spec/requests/api/graphql/analytics/duo_workflows_spec.rb --tag click_house -
Query the new fields in GraphiQL at
/-/graphql-explorer, swappinggitlab-duofor a group that has Duo flow data locally:query { group(fullPath: "gitlab-duo") { analytics { duoWorkflows { aggregated { nodes { dimensions { createdAt(granularity: "monthly") } returningUsersCount joinedUsersCount churnedUsersCount previousPeriodUsersCount } } } } } }
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Related to #627696