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 period
  • joined_users (acquired_count) — unique users who ran a flow in this period but not the previous one
  • churned_users (churned_count) — unique users who ran a flow in the previous period but not this one
  • previous_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

Screenshots or screen recordings

No UI changes — backend and GraphQL schema only.

How to set up and validate locally

  1. Make sure ClickHouse is running in your GDK and the duo_workflows_workflows_enriched table has data.

  2. Run the specs. The --tag click_house flag 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
  3. Query the new fields in GraphiQL at /-/graphql-explorer, swapping gitlab-duo for 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

Edited by Serhii Yarynovskyi

Merge request reports

Loading
Loading