Route billing events by the configured Customers Portal

What does this MR do and why?

A self-managed instance whose CUSTOMER_PORTAL_URL points at the staging Customers Portal is licensed, entitled and billed on staging. Gitlab::Tracking::Destinations::DestinationConfiguration selected the staging billing collector only for GitLab.com staging (Gitlab.staging?) and QA hosts ending in .test, so such an instance posted its billable_usage events to the production collector, where its instance UUID and subscription do not exist, and staging CustomersDot never saw its usage.

This MR treats an explicitly configured staging Customers Portal (CUSTOMER_PORTAL_URL equal to STAGING_CUSTOMER_PORTAL_URL or the default https://customers.staging.gitlab.com, trailing slash ignored) as a non-production environment in DestinationConfiguration.non_production_environment?.

  • Only an explicit CUSTOMER_PORTAL_URL counts. Development and test environments default to the staging portal through the route helper, not the variable, so their behaviour is unchanged.
  • The predicate is shared by billing_uri and snowplow_uri, so a staging-licensed instance also sends product usage events to events-stg.gitlab.net. That is consistent with its licence; if the group prefers billing only, the call moves into billing_uri.
  • The developer documentation for billing events gains one paragraph on where events go.

Resolves https://gitlab.com/gitlab-org/gitlab/-/work_items/629533 (confidential). Found during https://gitlab.com/gitlab-org/gitlab/-/work_items/628023 while tracing the first secrets_read billable event on a Cloud Native GitLab test instance licensed against CustomersDot staging.

Values read from a self-managed test instance licensed against CustomersDot staging (Cloud Native GitLab, chart 10.3.2 with master images):

Check Before this MR
DestinationConfiguration.billing_configuration.uri https://billing.prdsub.gitlab.net
DestinationConfiguration.non_production_environment? false
ENV['CUSTOMER_PORTAL_URL'] https://customers.staging.gitlab.com
Licence active against CustomersDot staging

Out of scope, tracked in the same issue: the billing_event_tracking flag is off by default on self-managed. Authentication needs no change: on self-managed the emitter presents the CustomersDot-issued Cloud Connector token, whose issuer and audience belong to the same environment as the Customers Portal, which is one more reason the collector must follow it.

How to set up and validate locally

  1. bin/rspec spec/lib/gitlab/tracking/destinations/destination_configuration_spec.rb (45 examples). With the library change stashed, the four new staging expectations fail, so the specs prove the behaviour.

  2. In a Rails console with CUSTOMER_PORTAL_URL=https://customers.staging.gitlab.com exported and GITLAB_LICENSE_MODE=test:

    Gitlab::Tracking::Destinations::DestinationConfiguration.billing_configuration.uri.to_s
    # => "https://billing.stgsub.gitlab.net"

    Without the variable, or with https://customers.gitlab.com, the result stays https://billing.prdsub.gitlab.net.

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.

🤖 Generated with Claude Code

Edited by Dmytro Biryukov

Merge request reports

Loading
Loading