Skip to content

Commit 0320bb7

Browse files
[management] Report sync duration and login duration by accountID (#4406)
1 parent f063866 commit 0320bb7

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

management/server/grpcserver.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func (s *GRPCServer) Sync(req *proto.EncryptedMessage, srv proto.ManagementServi
198198
s.secretsManager.SetupRefresh(ctx, accountID, peer.ID)
199199

200200
if s.appMetrics != nil {
201-
s.appMetrics.GRPCMetrics().CountSyncRequestDuration(time.Since(reqStart))
201+
s.appMetrics.GRPCMetrics().CountSyncRequestDuration(time.Since(reqStart), accountID)
202202
}
203203

204204
unlock()
@@ -436,11 +436,7 @@ func (s *GRPCServer) parseRequest(ctx context.Context, req *proto.EncryptedMessa
436436
// In case of the successful registration login is also successful
437437
func (s *GRPCServer) Login(ctx context.Context, req *proto.EncryptedMessage) (*proto.EncryptedMessage, error) {
438438
reqStart := time.Now()
439-
defer func() {
440-
if s.appMetrics != nil {
441-
s.appMetrics.GRPCMetrics().CountLoginRequestDuration(time.Since(reqStart))
442-
}
443-
}()
439+
444440
if s.appMetrics != nil {
445441
s.appMetrics.GRPCMetrics().CountLoginRequest()
446442
}
@@ -463,6 +459,12 @@ func (s *GRPCServer) Login(ctx context.Context, req *proto.EncryptedMessage) (*p
463459
//nolint
464460
ctx = context.WithValue(ctx, nbContext.AccountIDKey, accountID)
465461

462+
defer func() {
463+
if s.appMetrics != nil {
464+
s.appMetrics.GRPCMetrics().CountLoginRequestDuration(time.Since(reqStart), accountID)
465+
}
466+
}()
467+
466468
if loginReq.GetMeta() == nil {
467469
msg := status.Errorf(codes.FailedPrecondition,
468470
"peer system meta has to be provided to log in. Peer %s, remote addr %s", peerKey.String(), realIP)

management/server/telemetry/grpc_metrics.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import (
44
"context"
55
"time"
66

7+
"go.opentelemetry.io/otel/attribute"
78
"go.opentelemetry.io/otel/metric"
89
)
910

11+
const AccountIDLabel = "account_id"
12+
1013
// GRPCMetrics are gRPC server metrics
1114
type GRPCMetrics struct {
1215
meter metric.Meter
@@ -111,13 +114,13 @@ func (grpcMetrics *GRPCMetrics) CountLoginRequest() {
111114
}
112115

113116
// CountLoginRequestDuration counts the duration of the login gRPC requests
114-
func (grpcMetrics *GRPCMetrics) CountLoginRequestDuration(duration time.Duration) {
115-
grpcMetrics.loginRequestDuration.Record(grpcMetrics.ctx, duration.Milliseconds())
117+
func (grpcMetrics *GRPCMetrics) CountLoginRequestDuration(duration time.Duration, accountID string) {
118+
grpcMetrics.loginRequestDuration.Record(grpcMetrics.ctx, duration.Milliseconds(), metric.WithAttributes(attribute.String(AccountIDLabel, accountID)))
116119
}
117120

118121
// CountSyncRequestDuration counts the duration of the sync gRPC requests
119-
func (grpcMetrics *GRPCMetrics) CountSyncRequestDuration(duration time.Duration) {
120-
grpcMetrics.syncRequestDuration.Record(grpcMetrics.ctx, duration.Milliseconds())
122+
func (grpcMetrics *GRPCMetrics) CountSyncRequestDuration(duration time.Duration, accountID string) {
123+
grpcMetrics.syncRequestDuration.Record(grpcMetrics.ctx, duration.Milliseconds(), metric.WithAttributes(attribute.String(AccountIDLabel, accountID)))
121124
}
122125

123126
// RegisterConnectedStreams registers a function that collects number of active streams and feeds it to the metrics gauge.

0 commit comments

Comments
 (0)