Track code suggestions billing for self-hosted

What does this MR do and why?

This MR implements billing tracking for code suggestions on self-hosted instances by sending billing events to the cloud Duo Workflow Service before each code suggestions request.

Key changes:

  • New SelfHostedBillingTracker service (ee/lib/ai/code_suggestions/self_hosted_billing_tracker.rb): Handles billing event tracking for self-hosted instances. Returns success responses when billing is not applicable (cloud instances, feature flag off, etc.) so callers can treat it as a no-op.

  • Extended DuoWorkflowService::Client (ee/lib/ai/duo_workflow/duo_workflow_service/client.rb): Added track_self_hosted_client_event method to send billing events via gRPC streaming. The client now accepts an optional token parameter to support explicit cloud connector tokens.

  • Integrated billing into code suggestions API (ee/lib/api/code_suggestions.rb): Tracks billing events before proxying requests to the AI Gateway. Returns a 503 error if billing tracking fails.

  • Updated Duo Workflow Service client gem to version 0.7 with the new gRPC contract for self-hosted billing events.

This mirrors the existing billing path that Workhorse handles for Duo Workflow, but is called directly from Rails for the stateless completions endpoint.

Testing

  • Make sure that self-hosted billing is enabled
    • Apply a cloud license
    • make sure to set this rails env var SELF_HOSTED_DAP_BILLING_ENABLED to true
  • Perform a code suggestion request
  • Verify that the event has been tracked

In case there's a DNS error locally, export GRPC_DNS_RESOLVER=native may help.

Edited by Patrick Cyiza

Merge request reports

Loading