Support daily credit caps in the budget caps GraphQL API

What does this MR do and why?

Do not merge before CustomersDot production serves the daily cap fields. They were added in https://gitlab.com/gitlab-org/customers-gitlab-com/-/merge_requests/17986, which is merged but not yet deployed. Until then, the budget caps query this MR extends fails on CustomersDot, which would break the existing credit caps page.

CustomersDot now stores a per-user daily credit cap next to the monthly one. GitLab.com reads and writes caps through a GraphQL proxy to CustomersDot, so nothing can set or read the daily cap from GitLab until this proxy carries the fields. This MR is the backend half; the credit caps UI follows in https://gitlab.com/gitlab-org/gitlab/-/work_items/639092.

Read

  • GitlabSubscriptionBudgetCaps.dailyCap / dailyCapEnabled: the subscription-wide daily cap.
  • GitlabSubscriptionBudgetCapUserOverride.dailyCap / dailyCapEnabled: a user's daily override, independent of their monthly one.
  • GitlabSubscriptionUsageBlockedCapType gains DAILY_FLAT_USER_CAP and DAILY_USER_OVERRIDE_CAP. CustomersDot only returns them once its usage_billing_daily_budget_caps_enforcement flag is on. Until GitLab knows these values, the proxy cannot serialize them, so this MR must ship before that flag is enabled (https://gitlab.com/gitlab-org/customers-gitlab-com/-/work_items/18802).

Write

  • upsertFlatUserCap takes dailyCap / dailyCapEnabled. Its flatUserCap / flatUserCapEnabled become optional, with at least one of the four required, and only the caps passed are sent, so setting the daily cap never overwrites the monthly one.
  • BudgetCapUserOverrideInput takes dailyCap / dailyEnabled. cap and enabled become optional (enabled defaults to true, like dailyEnabled), with at least one of cap or dailyCap required. Each cap is sent to CustomersDot together with its toggle, and only when the cap is given, so updating one dimension of an existing override leaves the other unchanged.

Compatibility

  • Making arguments optional is not a breaking change. Existing callers, including the credit caps UI, send both monthly fields and behave exactly as before.
  • New fields, arguments and enum values are experiments (experiment: { milestone: '19.7' }) until daily enforcement is enabled in CustomersDot. 19.6 is already cut, so this ships in 19.7.
  • GitlabSubscriptionBudgetCapUserOverride.cap stays non-nullable. CustomersDot stores no monthly amount for a daily-only override, and changing the field to nullable would be a breaking change. The proxy returns 0 for it instead. That override is always disabled (capEnabled: false), and a disabled override falls back to the flat cap whatever its amount, so 0 behaves identically. RailsAdmin already stores daily-only overrides as cap: 0.
  • Query cost: CustomersDot returns at most 20 overrides per page but computes cost from the requested page size. The two extra fields per row would push a large userOverrides(first: …) request past its limit, after which the list silently comes back empty. GitLab now caps first/last at 20 before calling CustomersDot. Results are identical, because CustomersDot never returned more than 20 rows, and the cost stays bounded (177 against a limit of 200 for self-managed). subscription_usage_client_complexity_spec.rb checks the UI's page size.

After this merges

  • The CustomersDot daily cap fields become a fixed contract: every budget caps read and both upserts select them, so rolling them back in CustomersDot would break GitLab.
  • GitLab 19.6 and earlier don't know the DAILY_* cap types, and still declare cap as non-null. So CustomersDot must not enable usage_billing_daily_budget_caps_enforcement before GitLab.com runs this change, and support should not set daily caps for self-managed subscriptions on GitLab 19.6 or earlier. Tracked in https://gitlab.com/gitlab-org/customers-gitlab-com/-/work_items/18802.

References

Screenshots or screen recordings

Not applicable: no UI change.

How to set up and validate locally

Needs a local CustomersDot on main that includes https://gitlab.com/gitlab-org/customers-gitlab-com/-/merge_requests/17986, connected to your GDK, and a group with a GitLab Credits subscription you own.

  1. In GraphiQL, set a daily cap only, and check that the flat cap is unchanged:
    mutation {
      upsertFlatUserCap(input: { namespacePath: "<group>", dailyCap: 5, dailyCapEnabled: true }) {
        flatUserCap flatUserCapEnabled dailyCap dailyCapEnabled errors
      }
    }
  2. Add a daily-only override for a member:
    mutation {
      upsertUserBudgetCapOverrides(input: {
        namespacePath: "<group>", overrides: [{ username: "<member>", dailyCap: 2 }]
      }) {
        userOverrides { user { username } cap capEnabled dailyCap dailyCapEnabled } errors
      }
    }
    Expect cap: 0, capEnabled: false, dailyCap: 2, dailyCapEnabled: true.
  3. Update the same member with cap: 50 only: cap becomes 50 and the daily fields stay 2 / true.
  4. Send an override with neither cap nor dailyCap: the mutation fails with At least one of [cap, dailyCap] arguments is required.
  5. Query subscriptionUsage(namespacePath: "<group>") { budgetCaps { dailyCap dailyCapEnabled userOverrides { nodes { cap dailyCap } } } } and check that it returns the values above.

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.

Merge request reports

Loading
Loading