Log nested counted_by values as strings
What does this MR do and why?
The Rate_Limit_Block line in auth_json.log has a counted_by field with the values that the blocking rule counts by.
The product analytics collector rule counts by aid, which is the aid query param.
Rack 2.2.24 parses the param in three ways:
| Query | counted_by.aid before |
counted_by.aid after (Ruby 3.4) |
|---|---|---|
?aid=abc |
"abc" |
"abc" |
?aid[x]=1 |
{"x" => "1"} (object) |
"{\"x\" => \"1\"}" |
?aid[]=1&aid[]=2 |
["1", "2"] (array) |
"[\"1\", \"2\"]" |
Elasticsearch drops a line whose field shape does not match the index mapping.
!266584 (merged) removed applies_to from the line for the same reason.
This MR logs each counted_by value with to_s, only in the log line.
LabKit builds the counter key with to_s too (Evaluator#resolve_char_value in labkit 5.9.0), so the logged value is the bucket that LabKit counted.
The counters and the rule matching do not change.
All other characteristic values (ip, requester_type, requester_id, runner_id, path, expired_oauth_token_id) are already strings, so to_s does not change them.
The problem was found in the review of the 19.4 backport. After this MR merges, I will backport it to 19.5 and 19.4, the same as !266578 (merged) and !266577 (merged).
References
- Issue: #634755
- Review thread: !266577 (comment 4209923566)
- Same problem for
applies_to: !266584 (merged)
Screenshots or screen recordings
Not applicable. This MR changes a log field and has no UI change.
How to set up and validate locally
Not applicable. To see the line, a request must be blocked by the collector rule, which needs its LabKit cohort enforced and the limit reached. The new spec examples call the middleware with the three query shapes above.
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.