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.GitlabSubscriptionUsageBlockedCapTypegainsDAILY_FLAT_USER_CAPandDAILY_USER_OVERRIDE_CAP. CustomersDot only returns them once itsusage_billing_daily_budget_caps_enforcementflag 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
upsertFlatUserCaptakesdailyCap/dailyCapEnabled. ItsflatUserCap/flatUserCapEnabledbecome 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.BudgetCapUserOverrideInputtakesdailyCap/dailyEnabled.capandenabledbecome optional (enableddefaults totrue, likedailyEnabled), with at least one ofcapordailyCaprequired. 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.capstays 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 returns0for it instead. That override is always disabled (capEnabled: false), and a disabled override falls back to the flat cap whatever its amount, so0behaves identically. RailsAdmin already stores daily-only overrides ascap: 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 capsfirst/lastat 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.rbchecks 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 declarecapas non-null. So CustomersDot must not enableusage_billing_daily_budget_caps_enforcementbefore 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
- https://gitlab.com/gitlab-org/gitlab/-/work_items/639091
- Epic: https://gitlab.com/groups/gitlab-org/-/work_items/23400
- CustomersDot contract: https://gitlab.com/gitlab-org/customers-gitlab-com/-/merge_requests/17986, https://gitlab.com/gitlab-org/customers-gitlab-com/-/work_items/18801
- CustomersDot daily enforcement: https://gitlab.com/gitlab-org/customers-gitlab-com/-/merge_requests/18072
- UI, to stack on this MR: https://gitlab.com/gitlab-org/gitlab/-/work_items/639092
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.
- 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 } } - Add a daily-only override for a member:
Expect
mutation { upsertUserBudgetCapOverrides(input: { namespacePath: "<group>", overrides: [{ username: "<member>", dailyCap: 2 }] }) { userOverrides { user { username } cap capEnabled dailyCap dailyCapEnabled } errors } }cap: 0, capEnabled: false, dailyCap: 2, dailyCapEnabled: true. - Update the same member with
cap: 50only:capbecomes50and the daily fields stay2/true. - Send an override with neither
capnordailyCap: the mutation fails withAt least one of [cap, dailyCap] arguments is required. - 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.