[management] only count login request duration for successful logins#5545
[management] only count login request duration for successful logins#5545pascal-fischer merged 1 commit intomainfrom
Conversation
📝 WalkthroughWalkthroughThe PR relocates gRPC metrics timing in the server handler for Sync and Login operations. CountSyncRequestDuration moves post-unlock, while Login's deferred logging is replaced with immediate duration metrics recorded after response encryption. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
management/internals/shared/grpc/server.go (1)
794-797: Consider usingpeer.AccountIDfor more accurate metrics.At this point,
accountIDmay still be"UNKNOWN"ifGetAccountIDForPeerKeyfailed (lines 735-739) but the login succeeded via setup key registration. Thepeerobject returned fromLoginPeercontains the actual account ID.♻️ Suggested improvement
if s.appMetrics != nil { - s.appMetrics.GRPCMetrics().CountLoginRequestDuration(time.Since(reqStart), accountID) + s.appMetrics.GRPCMetrics().CountLoginRequestDuration(time.Since(reqStart), peer.AccountID) } log.WithContext(ctx).Debugf("Login took %s", time.Since(reqStart))🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@management/internals/shared/grpc/server.go` around lines 794 - 797, The metrics currently use the variable accountID which may remain "UNKNOWN" when GetAccountIDForPeerKey failed even though LoginPeer returned a valid peer with the real account ID; update the metrics call to use the account ID from the returned peer (peer.AccountID) when available (e.g., use peer.AccountID fallback before calling s.appMetrics.GRPCMetrics().CountLoginRequestDuration) and ensure the debug log likewise reports the peer.AccountID where appropriate; adjust references around LoginPeer, accountID, peer, and s.appMetrics.GRPCMetrics().CountLoginRequestDuration to prefer peer.AccountID when non-empty.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@management/internals/shared/grpc/server.go`:
- Around line 794-797: The metrics currently use the variable accountID which
may remain "UNKNOWN" when GetAccountIDForPeerKey failed even though LoginPeer
returned a valid peer with the real account ID; update the metrics call to use
the account ID from the returned peer (peer.AccountID) when available (e.g., use
peer.AccountID fallback before calling
s.appMetrics.GRPCMetrics().CountLoginRequestDuration) and ensure the debug log
likewise reports the peer.AccountID where appropriate; adjust references around
LoginPeer, accountID, peer, and
s.appMetrics.GRPCMetrics().CountLoginRequestDuration to prefer peer.AccountID
when non-empty.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a154d175-2c20-4fd8-96ab-1054a455f086
📒 Files selected for processing (1)
management/internals/shared/grpc/server.go



Describe your changes
Issue ticket number and link
Stack
Checklist
Documentation
Select exactly one:
Docs PR URL (required if "docs added" is checked)
Paste the PR link from https://github.com/netbirdio/docs here:
https://github.com/netbirdio/docs/pull/__
Summary by CodeRabbit