Add the usage-limit block to the Artifact Registry billing state driver (AR#2019 stack: 3/4)

What does this MR do and why?

This MR adds the usage-limit arm of the Artifact Registry billing state driver: on GitLab.com, the driver sets and lifts the registry's usage-limit block from the CustomersDot verdict. It follows S17 (billing state driver spec). It is part 3 of 4 of the stack and builds on the suspension arm, which is merged.

  • Usage-limit arm. On GitLab.com only, ArtifactRegistry::BillingStateDriverService asks CustomersDot (the Customers Portal) for a verdict through ArtifactRegistry::UsageLimitResolver from part 1, and calls limit_block or unlimit_block. Every suspension call of a run goes out before the first resolve call, so a slow CustomersDot never delays a suspension.
  • Lift sweep. The new sweep mode reads only the limit_blocked namespaces and lifts each block that CustomersDot allows again. Part 4 schedules it every 5 minutes.
  • Feature flag. The new wip flag artifact_registry_usage_limit_block, off by default and checked per organization, gates the arm. With the flag off, a run lifts every block, because only this driver sets the block.
  • Metrics. The driver emits artifact_registry_billing_driver_resolve_unknown_total (answers it cannot map to a verdict) and artifact_registry_billing_driver_runs_total (full runs, labeled faulted when a run had an answer that counts toward the fault alert). Both are documented in doc/administration/monitoring/prometheus/gitlab_metrics.md.

Points for the reviewer:

  • The diff adds the limit arm back to part 2. Part 2 merged the suspension-only version of the same class and spec, and this MR adds the limit arm back to them. It also restores four spec lines that part 2 reworded to make sense without the limit arm.
  • Alert rules are in a follow-up. This MR ships the series the alerts read. The two alert rules (S17 acceptance 38 and 40) are in the follow-up for the alert rules.
Readings taken where the spec says nothing
  • The lift sweep lifts a limit block while the usage-limit flag is off, because only this driver sets the block.
  • A 403 with usage_not_allowed is an unknown verdict, because S17 lists only a 402 as blocking.
  • The faulted label leaves out the three CustomersDot namespace verdicts (402 or 403 with no_billable_source_error, community_plan_error or amazon_q_plan_error), the same set as UsageLimitResolver::Verdict#namespace_verdict?.
S17 rows this MR covers
  • Acceptance 29 to 32: blocked, allowed, masked and unknown verdicts in a run.
  • Acceptance 35: an unknown verdict does not stop a suspension, and an unreadable plan does not stop the limit block.
  • Acceptance 36: the lift sweep.
  • Acceptance 39 and the series side of 40: the counted-fault series.
  • Acceptance 41: every suspension call before the first resolve call.
  • Acceptance 42 and 43: no resolve and no limit call on Self-Managed and in the renewal trigger.
  • Acceptance 44 to 46: the two flags, each on its own, and an unusable anchor with the usage-limit flag off.

The stack

  1. Activation checks and UsageLimitResolver.
  2. Billing state driver, suspension arm.
  3. This MR: the usage-limit arm.
  4. The scheduled workers and the renewal subscription.

References

Related to the issue

Screenshots or screen recordings

n/a: this MR changes no frontend code.

How to set up and validate locally

This MR has no user-facing change: the arm runs only behind a flag that is off by default, and nothing schedules it until part 4.

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.

  • Quality. The changed spec uses spec_helper and needs the test database, so CI is its first run. Locally, only RuboCop and the docs linters ran.
  • Database. No migration and no new query.
  • Performance and reliability. On GitLab.com a run makes one resolve call per namespace with a usable anchor, with a 2-second open timeout, a 5-second read timeout, and no retry. A failed call is logged and counted, the run continues, and the next run retries it.
  • Security. The resolve call presents the CustomersDot admin headers and never a user token.
  • Feature flags. artifact_registry_usage_limit_block is new, wip, and off by default.
Edited by Pawel Rozlach

Merge request reports

Loading
Loading