feat(config): rate_limit configuration block (S05-B plan: 4/4)
Summary
Step 4 of the S05-B plan: the
rate_limit configuration block from
S05-B's Configuration. The
proto gains the RateLimit, RateLimitOverride, and RateLimitConfig
messages and Config.rate_limit (field 24); internal/config/ratelimit.go
converts the block into the config-owned runtime types (Mode defaulting to
observe, the one-second period floor, UUID-keyed overrides); and
config.example.yaml and docs/dev/configuration-reference.md document the
block as-is.
No consumer reads the block: the mount on the six pull arms lands with #1181's plan, so a declared limit refuses no request, adds no header, and is counted nowhere until then.
Where the spec's proto snippet says "shared by every arm", the shipped proto and example comments read "which every arm will share": writing-discipline requires future tense for relationships to parts that have not landed, so the code comments carry it and the spec's own wording stays with its author.
Governing ADRs
ADR-004 (Rate Limits): rate-limit configuration lives in the service's own
config, applied at the next rollout; per-namespace overrides are a first-class
config property; observe, warn, and enforce match the rollout strategy; and
the namespace class is first, matching the closed namespace-only key set. The
known deviation from ADR-004's IP-first rollout sentence (namespace-first key
order) is already escalated in handbook MR !21345. Checked against the ADR
index; no other ADR touches this change.
Plan and spec amendments
Step 4's Tests entry named only internal/config/ratelimit_test.go. It now
also names internal/config/ratelimit_internal_test.go, the in-package test
reaching the override-key parse arm that protovalidate's map-key rule makes
unreachable through Load.
S05-B's Error Cases table was silent on two spellings of one namespace UUID in
namespace_overrides. The proto's map-key rule accepts either case, so both
spellings load as distinct keys that uuid.Parse folds onto one, where the
second write would replace the first; the loader now rejects the pair, and the
table gains the row.
S05-B's Configuration section claimed a limits typo "cannot silently disable a
limit". The loader is non-strict, so only a misspelled limiter name fails
startup; a misspelled section or field name is dropped silently. The sentence now
says which typo fails, and the configuration reference documents the dropped
keys.
All three corrections ride this MR rather than a separate amendment MR per review-driven plan corrections: they correct the step's own text and the spec clauses governing its code, and change no step boundary.
Testing
Unit tests in internal/config/ratelimit_test.go (external package, through
config.Load) and internal/config/ratelimit_internal_test.go (in-package,
reaching the override-key parse arm Load cannot).
Spec coverage: S05-B acceptance criterion 14 and the configuration rows of S05-B's Error Cases.
| Case | Tests |
|---|---|
| AC-14: omitted mode converts to observe | TestLoad_RateLimit_Mode |
| AC-14: period below one second rejected | TestLoad_RateLimit_PeriodBelowOneSecondRejected, TestLoad_RateLimit_PeriodUnparseable, TestLoad_RateLimit_EmptyPeriodRejected |
Closed limits key set |
TestLoad_RateLimit_LimitsKeyOutsideClosedSetRejected |
| Override key not a UUID | TestLoad_RateLimit_OverrideKeyNotUUIDRejected, TestRateLimitOverridesFromProto_RejectsMalformedKey |
| Two spellings of one namespace UUID | TestLoad_RateLimit_OverrideDuplicateNamespaceRejected, TestRateLimitOverridesFromProto_RejectsCaseFoldedDuplicate |
Mode outside the proto in set rejected |
TestLoad_RateLimit_ModeOutsideSetRejected |
| Non-positive rate or burst, base and override | TestLoad_RateLimit_NonPositiveRateOrBurstRejected, TestLoad_RateLimit_OverrideNonPositiveRateOrBurstRejected |
| Omitted or empty block wires no limits | TestLoad_RateLimit_OmittedOrEmptyBlockWiresNoLimits |
| Every field round-trips | TestLoad_RateLimit_HappyPath, TestLoad_RateLimit_Period |
| Exported zero values | TestRateLimit_ZeroValue |
| Example block pinned and parsed | TestLoad_RateLimit_ConfigExampleDefault |
TestRateLimit_ZeroValue pins the exported zero-value contract
(internal/AGENTS.md): RateLimitConfig{} wires no limiter, and
RateLimit{} carries Mode "", not observe — only a loaded config selects
observe. TestRateLimitOverridesFromProto_RejectsMalformedKey drives the
second-layer override-key parse directly, the only way to reach the arm:
through Load, the proto's map-key UUID rule rejects the key first.
e2e scenario impact: none. This step mounts no consumer, so no externally observable behavior changes; the e2e rows for a served 429 belong to #1181's mount plan.
docs/user impact: none. Every surface this step ships is inert until the
mount: no request is refused, warned, or headered, and the one published
sentence touching rate limits (docs/user/_index.md) already states the
enforcement posture this step leaves unchanged. The user-facing rate-limit
page lands with the mount's plan.
Size
The diff is 806 reviewable lines (added plus removed, excluding the
regenerated config.pb.go), above the 500-line guideline:
| File group | Lines |
|---|---|
Loader: internal/config/ratelimit.go, internal/config/config.go |
182 |
Tests: internal/config/ratelimit_test.go, internal/config/ratelimit_internal_test.go |
493 |
Plan: docs/plans/2026-10-05-s05b-rate-limiting.md |
8 |
Schema: proto/artifactregistry/config/v1/config.proto |
68 |
Operator docs: config.example.yaml, docs/dev/configuration-reference.md |
55 |
A split would not help review: the schema, the loader that enforces it, and the tests that pin its rejection arms are one reviewable unit from one spec section, and splitting the test file from the loader it pins would spread one review across two MRs without shrinking either.
Related to #1181