Record most used model in workflow session credits ingestion

What does this MR do and why?

  • GitLab periodically asks the subscription portal how many credits each Duo Agent Platform workflow session used, and stores that in a ClickHouse analytics table.
  • That table has a column for which model the session used, but it has always been left blank.
  • This MR fills in that column with the model the session used the most, so usage can be broken down by model. Sessions with no reported model still get their credits recorded, with an empty model value.

References

Screenshots or screen recordings

No UI changes.

How to set up and validate locally

  1. Make sure ClickHouse is running in GDK and enabled for analytics. In a Rails console:
    Gitlab::CurrentSettings.update!(use_clickhouse_for_analytics: true)
  2. Have at least one Duo Agent Platform workflow (Ai::DuoWorkflows::Workflow) record in a group namespace. Note its workflow id and its root namespace id.
  3. Run the ingestion in a Rails console:
    Ai::DuoWorkflows::SessionCredits::IngestService.new(namespace_id: <root namespace id>, workflow_ids: [<workflow id>]).execute
    Against a local GDK with no CustomersDot connection, stub the client response instead, or run the specs below.
  4. Check the resulting row in ClickHouse:
    SELECT workflow_id, credits_used, model_used FROM duo_workflow_session_enrichments FINAL
    Confirm model_used holds a model name, or an empty string when the session reported none.
  5. Run the specs:
    bundle exec rspec ee/spec/services/ai/duo_workflows/session_credits/ingest_service_spec.rb ee/spec/lib/gitlab/subscription_portal/subscription_usage_client_spec.rb

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.

Edited by Serhii Yarynovskyi

Merge request reports

Loading
Loading