fix: cap distinct user-agents per endpoint in GrpcUsageTracker - #26778
Merged
Conversation
Signed-off-by: Alex Kehayov <aleks.kehayov@limechain.tech>
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
swirlds-automation
dismissed
joshmarinacci’s stale review
August 11, 2026 13:49
2 file(s) changed in commit b7a4df6
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #26778 +/- ##
=========================================
Coverage 70.49% 70.49%
Complexity 11670 11670
=========================================
Files 2583 2583
Lines 108300 108305 +5
Branches 12110 12111 +1
=========================================
+ Hits 76346 76351 +5
Misses 27977 27977
Partials 3977 3977
🚀 New features to boost your workflow:
|
timfn-hg
reviewed
Aug 12, 2026
Signed-off-by: Alex Kehayov <aleks.kehayov@limechain.tech>
✅ All tests passed ✅🏷️ Commit: eb695f6 Learn more about TestLens at testlens.app. |
timfn-hg
approved these changes
Aug 13, 2026
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.
Description
GrpcUsageTrackeraggregates per-interval request counts in a map keyed by (endpoint, user-agent). A known SDK's version is a client-supplied component of the user-agent (any valid SemVer value is kept as-is), so within a single logging interval a caller could send many distinct valid user-agents and grow the per-endpoint map with no upper bound, using heap in proportion to the number of distinct values.This caps the number of distinct user-agents tracked per endpoint at
MAX_AGENTS_PER_ENDPOINT(1000). Once the cap is reached, further distinct user-agents are folded into the existingUNKNOWNuser-agent instead of adding new entries, so per-endpoint request totals stay exact while the number of map entries (and log lines emitted at flush) is bounded.Behavior
getpath).size()check is a best-effort bound and may be exceeded slightly under concurrency, which is acceptable for a safety limit.Testing
GrpcUsageTrackerTest.testRecordInteractionCapsDistinctUserAgentsPerEndpoint: records cap+500 distinct user-agents for one endpoint and asserts the map holds cap+1 entries (the cap plus the singleUNKNOWNoverflow bucket), the 500 overflow interactions are folded intoUNKNOWN, and the total across all keys equals the number recorded (nothing lost)../gradlew :app:test --tests "...GrpcUsageTrackerTest"— 10 tests pass.