Schedule the Artifact Registry billing state driver and subscribe it to renewals (AR#2019 stack: 4/5)
What does this MR do and why?
This MR schedules the Artifact Registry billing state driver and subscribes it to subscription renewals. It follows S17 (billing state driver spec). It is part 4 of 4 of the stack and sits on the usage-limit arm.
- Schedule.
ArtifactRegistry::BillingStateRunWorkerruns both arms every 30 minutes, andArtifactRegistry::UsageLimitLiftSweepWorkerlifts limit blocks every 5 minutes. Each is deduplicated on itself (2-hour and 30-minute TTL), and the cron entries are inee/config/schedule.yml. - Cron gates. Both cron workers return before the driver runs when the new ops flag
artifact_registry_billing_state_cronsis off. The run worker also returns whileartifact_registry_billing_state_driverandartifact_registry_usage_limit_blockare both off for every organization. The sweep worker also returns whileartifact_registry_usage_limit_blockis off for every organization. The sweep acts only on organizations with that flag on. - Renewal.
ArtifactRegistry::BillingRenewalWorkersubscribes toGitlabSubscriptions::RenewedEventandGitlabSubscriptions::RenewedCloudEventand runs the suspension arm at once for the billing organization of the renewed namespace. The billing organization is the organization of the namespace, or, for a group in the default organization, the organization that links the group. The subscription fires only whenartifact_registry_billing_state_driveris on for that billing organization. - Counts. Each worker logs the driver counts with
log_hash_metadata_on_donewhen the job finishes.
Points for the reviewer:
- One new ops flag.
artifact_registry_billing_state_cronsis a kill switch for both crons, and it is on by default. The rollout flags are the ones from part 2 and part 3, so with both of them off the crons call nothing and read nothing. - Driver service changes. The lift sweep now skips an organization with
artifact_registry_usage_limit_blockoff, because the run lifts the blocks of that organization. The driver reads both flags withOrganizations::Organization.actor_from_id, so it no longer loads each organization, and this MR removesNamespaceMapping.each_with_organization. - Inline RuboCop disables. Each disable carries its reason on the line:
Scalability/CronWorkerContexton both cron workers: each job spans every organization and has no single context.Gitlab/AvoidFeatureGeton both cron workers: the gate only reads whether a rollout flag is on for any organization.CodeReuse/ActiveRecordonfind_eachin the driver service: a false positive on the block argument.Gitlab/RSpec/AvoidCreateDefaultOrganizationin two specs: a linked group must come from the default organization.
- The 60-minute alert. The alert rule that selects
ArtifactRegistry::BillingStateRunWorkeris in the follow-up for the alert rules.
S17 rows this MR covers
- Acceptance 3: a renewal unsuspends without waiting for a run (the worker side; the driver side is in part 2).
- Acceptance 37: the run and the sweep are each deduplicated on themselves, and not on each other.
The stack
- Activation checks and
UsageLimitResolver. - Billing state driver, suspension arm.
- Billing state driver, usage-limit arm.
- This MR: the scheduled workers and the renewal subscription.
References
- S17 (billing state driver spec)
- Follow-up: alert rules.
Related to the issue
Screenshots or screen recordings
n/a: this MR changes no frontend code.
How to set up and validate locally
These steps need a GDK with the Artifact Registry service configured. They were not run for this MR.
-
In the Rails console, turn on the driver for one organization:
Feature.enable(:artifact_registry_billing_state_driver, Organizations::Organization.find(<id>)) -
Move the payer group to a plan without the registry, with a lapse date more than 14 days ago, then run
ArtifactRegistry::BillingStateRunWorker.new.perform. Expect abilling state driver: condition calllog line withaction: :suspend, and the namespace statussuspendedin the registry. -
Renew the subscription of the group. Expect
ArtifactRegistry::BillingRenewalWorkerto run and callunsuspend.
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. All new and changed specs use
spec_helperand need the test database, so CI is their first run. Locally, only RuboCop ran. - Database. No migration.
For a group in the default organization, the renewal worker and its subscription read
organization_linked_groupswith the existingOrganizations::LinkedGroup.organization_id_linked_to. The other queries are the ones that part 2 adds. - Performance and reliability. All three workers defer on the database health signal for
artifact_registry_namespace_mappings. The run and the sweep are deduplicated until executed, so a job that outlasts its interval drops the next tick. - Security. The workers act for no user.
- Feature flags. One new ops flag,
artifact_registry_billing_state_crons, on by default.