Add daily credit caps to the Credit caps page

What does this MR do and why?

Adds per-user daily credit caps to the Credit caps page, behind the new credit_caps_daily_cap feature flag (beta, default off). Owners and administrators can set a default daily cap for every user, and daily caps on per-user overrides, next to the monthly ones.

The GraphQL fields shipped in !272095 (merged) and are fully rolled out on GitLab.com, so this MR is frontend only, plus the flag push in the three credit caps controllers. New query fields use @gl_introduced(version: "19.7.0").

With the flag off, the page works as before, with two changes from review that apply either way:

  • Renamed copy: the page says Default caps, Monthly cap, Monthly status and Enforce monthly cap instead of Flat per-user cap, Flat cap, Override cap, Status and Enforce cap. The status badges, the save toast and error, and the overrides-unavailable alert follow the same names. The renamed strings lose their existing translations until they are translated again.
  • Empty cap: Add override starts with an empty cap instead of 0.

Design. There are no designs yet (https://gitlab.com/groups/gitlab-org/-/work_items/23400#note_4180968788), so this follows the monthly cap model as closely as possible. @timnoah reviewed the layout and naming on this MR, and @brothwell1 is asked to review the UX here too, rather than us waiting on designs.

Design decisions and the CustomersDot rules behind them
  • Default caps: one Default caps card with a Monthly cap row and, with the flag on, a Daily cap row, and a single Save (!272630 (comment 4302478774)). This matches the overrides table, where each row has both periods. An emptied amount keeps the saved one, so enforcement can be turned off without retyping it.
  • Overrides appear per period only once that period has a flat cap value. CustomersDot rejects an override for a period whose flat cap has no value. So, with the flag on but no default daily cap saved, the overrides list is exactly as today. Once a default daily cap is saved, the table gets Daily cap and Daily status columns. The monthly columns are Monthly cap and Monthly status in every case.
  • Daily-only overrides show the monthly cap as "Not set", not 0. The API returns them as cap: 0, capEnabled: false, because the GitLab type coerces a missing amount to 0. An enabled period requires an amount, so switching the monthly toggle on cannot save a cap of 0, which would block the user at once.
  • Saving a row sends only the period that changed, so editing one never writes a default into the other. Without daily caps, the payload is exactly as before. Save all applies the same amount check as a single row save, because it bypasses the browser's required validation.
  • Accessible names: each row of the card has its own toggle, Enforce monthly cap and Enforce daily cap.
  • Add override: both amounts start empty, and at least one is required. This applies with the flag off too: the monthly cap no longer defaults to 0, which assumed the admin meant a cap that blocks the user at once (!272630 (comment 4284249866)).
  • Bulk update: rows can carry two optional columns, daily_cap,daily_enabled. Leaving a cap and its enabled value empty leaves that cap unchanged. Three-column rows work as today.
  • Semantics, from CustomersDot:
    • The day is a UTC calendar day.
    • A daily cap counts all usage, including included credits, because it is checked before the wallet balance (https://gitlab.com/gitlab-org/customers-gitlab-com/-/merge_requests/18072).
    • Turning off the default daily cap turns off all daily caps, overrides included.
    • A disabled daily override falls back to the default daily cap.
    • Caps are approximate because usage is recorded with a short delay.

Size. Danger flags this MR as too big. Most of it is specs. It stays one MR while @brothwell1 reviews the design, so design changes land in one place. The bulk CSV support is the natural piece to split into a stacked MR if reviewers prefer.

The one-word change in organizations/.../credit_caps_controller.rb (# @note) is needed because RuboCop's new Gitlab/MethodCommentYardOnly cop blocks committing any change to that file.

Known limitation. On a subscription with only a default daily cap, the bulk update still accepts monthly values. CustomersDot rejects those rows with an error, so nothing is saved incorrectly.

Rollout: enable credit_caps_daily_cap only after usage_billing_daily_budget_caps_enforcement is on in CustomersDot (https://gitlab.com/gitlab-org/customers-gitlab-com/-/work_items/18802). Until then, a daily cap can be saved but does nothing. No changelog entry, because the flag is off by default.

References

Screenshots or screen recordings

Storybook (app.stories.js), with mocked data.

Before (flag off) After: monthly and daily caps
default daily-caps
State Screenshot
Flag on, no default daily cap saved yet: the overrides list has only the monthly columns daily-cap-not-set
Only a default daily cap: overrides show only the daily columns daily-cap-only
No default cap of either kind daily-cap-no-flat-caps
Add override with daily caps available add-override-modal

How to set up and validate locally

The page reads its data from CustomersDot, so the quickest way to see every state is Storybook:

  1. Run yarn storybook:start.
  2. Open ee/usage_quotas/wallet_agnostic_credits_dashboard/credit_caps/components/app, and select the stories Daily Caps, Daily Cap Not Set, Daily Cap Only, and Daily Cap No Flat Caps.

To try it against a CustomersDot that has https://gitlab.com/gitlab-org/customers-gitlab-com/-/merge_requests/17986:

  1. In the Rails console, enable the flag:

    Feature.enable(:credit_caps_daily_cap)
  2. As an Owner of a top-level group with GitLab Credits, go to Settings > GitLab Credits > Credit caps.

  3. Save a default daily cap, then add an override with only a daily cap.

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 Sheldon Led

Merge request reports

Loading
Loading