Skip to content

fix: cap distinct user-agents per endpoint in GrpcUsageTracker - #26778

Merged
AlexKehayov merged 3 commits into
mainfrom
issue-252
Aug 14, 2026
Merged

fix: cap distinct user-agents per endpoint in GrpcUsageTracker#26778
AlexKehayov merged 3 commits into
mainfrom
issue-252

Conversation

@AlexKehayov

Copy link
Copy Markdown
Contributor

Description

GrpcUsageTracker aggregates 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 existing UNKNOWN user-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

  • No change to normal telemetry. Real deployments see far fewer than 1000 distinct (SDK, version) pairs per endpoint per interval, so the cap is never reached and existing entries are unaffected.
  • Counting for an already-tracked user-agent is unchanged (fast get path).
  • The map is already swapped out every logging interval, so this only bounds growth within one interval; it does not change that reset.
  • The size() check is a best-effort bound and may be exceeded slightly under concurrency, which is acceptable for a safety limit.

Testing

  • Added GrpcUsageTrackerTest.testRecordInteractionCapsDistinctUserAgentsPerEndpoint: records cap+500 distinct user-agents for one endpoint and asserts the map holds cap+1 entries (the cap plus the single UNKNOWN overflow bucket), the 500 overflow interactions are folded into UNKNOWN, and the total across all keys equals the number recorded (nothing lost).
  • ./gradlew :app:test --tests "...GrpcUsageTrackerTest" — 10 tests pass.

Signed-off-by: Alex Kehayov <aleks.kehayov@limechain.tech>
@AlexKehayov AlexKehayov self-assigned this Aug 11, 2026
@AlexKehayov
AlexKehayov requested a review from a team as a code owner August 11, 2026 09:35
@lfdt-bot

lfdt-bot commented Aug 11, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@AlexKehayov AlexKehayov added this to the v0.79 milestone Aug 11, 2026
joshmarinacci
joshmarinacci previously approved these changes Aug 11, 2026

@joshmarinacci joshmarinacci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm 👍

@swirlds-automation
swirlds-automation dismissed joshmarinacci’s stale review August 11, 2026 13:49

2 file(s) changed in commit b7a4df6

@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@            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           
Files with missing lines Coverage Δ Complexity Δ
...era/node/app/grpc/impl/usage/GrpcUsageTracker.java 98.70% <100.00%> (+0.05%) 0.00 <0.00> (ø)
...com/hedera/node/app/grpc/impl/usage/UserAgent.java 93.02% <100.00%> (+0.16%) 0.00 <0.00> (ø)
...hedera/node/app/grpc/impl/usage/UserAgentType.java 97.14% <100.00%> (+0.08%) 0.00 <0.00> (ø)

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Signed-off-by: Alex Kehayov <aleks.kehayov@limechain.tech>
@testlens-app

testlens-app Bot commented Aug 13, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: eb695f6
▶️ Tests: 21803 executed
⚪️ Checks: 48/48 completed


Learn more about TestLens at testlens.app.

@AlexKehayov
AlexKehayov merged commit 77fdb8c into main Aug 14, 2026
57 checks passed
@AlexKehayov
AlexKehayov deleted the issue-252 branch August 14, 2026 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants