feat(ratelimit): attribute rate limit decisions to a tool and caller - #6517
Open
premctl wants to merge 1 commit into
Open
feat(ratelimit): attribute rate limit decisions to a tool and caller#6517premctl wants to merge 1 commit into
premctl wants to merge 1 commit into
Conversation
Signed-off-by: Prem Kumar Sompura <prem_sompura@hotmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6517 +/- ##
==========================================
+ Coverage 78.25% 78.33% +0.08%
==========================================
Files 770 770
Lines 75521 75534 +13
==========================================
+ Hits 59100 59172 +72
+ Misses 16416 16357 -59
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
toolhive_rate_limit_decisions_totalrecordsscopeandoperation_type, but nothing that says which tool or which caller a decision belongs to. With more than one entry inrateLimiting.tools, every per-tool bucket collapses into a singleoperation_type="tool"series, so an operator watching rejections cannot tell which configured cap is firing, and has no way to see who is hitting it.limitChecknow carries the tool name, andrecordDecisionemits it astool_nameon tool-scoped decisions. The attribute is omitted (not emitted blank) for server-scoped decisions, so existing series keep their shape.Allowsetsrate_limit.tool_nameandrate_limit.user_idvia a newrecordRateLimitSpanAttribution.userIDis unbounded — as a metric attribute it would multiply the decisions counter by the size of the user base — but on a span it costs nothing and answers "who is being throttled", which the counter alone cannot.This keeps the metric answer bounded and puts the unbounded dimension where unbounded values belong.
On label cardinality (related to #6271)
#6271 is open on telemetry hardening, including tool/prompt cardinality and unbounded label value length, so it is worth being explicit that this attribute is safe on both counts.
tool_nameis only ever set inside a successful bucket-map lookup —if tb, ok := l.toolBuckets[toolName]; okandif s, ok := l.perUserTools[toolName]; ok. A tool name supplied by a caller that matches no configured bucket never reaches the attribute. The value set is therefore exactly the operator's configured tool names: bounded in count bylen(rateLimiting.tools), and bounded in length by the CRD the operator wrote.TestRateLimitMetrics_UnconfiguredToolCarriesNoAttributepins this by callingAllowwith a 4096-character tool name and asserting no datapoint gains atool_namekey.Span attributes are exported per-span rather than aggregated cumulatively, so
rate_limit.user_iddoes not carry the residency concern that motivates #6271. Happy to truncate or drop it if you would rather keep identity out of spans entirely.Type of change
Test plan
task test) —go test ./pkg/ratelimit/...passes. Two new tests:TestRateLimitMetrics_ToolAttributiondrives a per-user tool bucket to rejection and asserts the rejection carriestool_namewhile server-scoped decisions carry no such key;TestRateLimitMetrics_UnconfiguredToolCarriesNoAttributeasserts caller-supplied tool names never become label values.task lint-fix) —golangci-lint run pkg/ratelimit/...reports 0 issues;gofmtclean.API Compatibility
v1beta1API, OR theapi-break-allowedlabel is applied and the migration guidance is described above.Does this introduce a user-facing change?
Yes —
toolhive_rate_limit_decisions_totalgains atool_nameattribute on tool-scoped decisions, and rate-limit spans gainrate_limit.tool_name/rate_limit.user_id. Dashboards that aggregate the counter without grouping are unaffected; those that sum overoperation_type="tool"will now see one series per configured tool.