docs(conformance): pin count_distinct admission of counted values
What
Adds one bullet under "Pinned ahead of a scenario" in conformance/README.md that pins an opt-in mode for count_distinct rules: count only the values the rule admits.
labkit-ruby adds it next in gitlab-org/ruby/gems/labkit-ruby!404 (merged), so the contract lands here first.
Why
A plain count_distinct rule adds every checked value to the set, including the ones it blocks. Once a value is blocked, the count stays above the limit for the rest of the window, so values that were already counted are blocked too.
That's the right behavior for "block after N distinct values", but not for a cap on how many distinct values can be admitted per window, where a value that is already admitted should keep working. GitLab needs the second behavior to cap how many distinct new external email addresses a top-level namespace can add as Service Desk participants per day: an address added earlier in the day must still be addable to other tickets after the cap is reached. Context: gitlab-org/gitlab!268802 (merged) (draft, waiting on this).
The caller can't build this on top of the current API: it only sees the count, and a blocked value that was added to the set looks the same as one that was admitted.
What the bullet pins
- Opt-in per rule, only on
count_distinctrules. The default behavior doesn't change. - A value already in the set is allowed without changing the count, even when the set is full.
- A new value is added only while the count is below the limit. Otherwise the request is blocked and the value is not added, so a blocked value stays blocked on retry and the count does not grow past the limit.
- One Lua script does the membership check, the add, and the TTL. The window starts with the first added value.
- A blocked request reports the set's count and
RateLimit-Remaining: 0. The block comes from the script, not fromcount > limit, the same way a ban decides the block apart from the count. - If the limit is lowered during a window, values already in the set are still allowed, and new values are blocked until the window ends.
peekreports whatcheckwould decide when the identifier has thecount_distinctvalue, without writing: exceeded only when that value isn't counted and the count has reached the limit. Without the value,checkskips the rule, butpeekanswers for a value that isn't counted yet, so it reports exceeded once the count reaches the limit.- A
logrule does the same accounting and never blocks.costis ignored, as for a plaincount_distinctrule. - Same Redis key and stored values as a plain
count_distinctrule.
Not in this MR
- No scenario yet. It follows the labkit-ruby release and the Ruby server pin bump, like the block summary did in !50 (merged).
- No SDK implements the mode yet. labkit-ruby adds it first, as
admit_counted_values. Go and Rust follow later.
Checklist
- Teammate review
- Maintainer review