mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-20 09:47:49 +02:00
added blocked metrics
This commit is contained in:
parent
9d0cae862b
commit
4a2d51d250
@ -130,9 +130,6 @@ func getRealIP(ctx context.Context) net.IP {
|
|||||||
// notifies the connected peer of any updates (e.g. new peers under the same account)
|
// notifies the connected peer of any updates (e.g. new peers under the same account)
|
||||||
func (s *GRPCServer) Sync(req *proto.EncryptedMessage, srv proto.ManagementService_SyncServer) error {
|
func (s *GRPCServer) Sync(req *proto.EncryptedMessage, srv proto.ManagementService_SyncServer) error {
|
||||||
reqStart := time.Now()
|
reqStart := time.Now()
|
||||||
if s.appMetrics != nil {
|
|
||||||
s.appMetrics.GRPCMetrics().CountSyncRequest()
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx := srv.Context()
|
ctx := srv.Context()
|
||||||
|
|
||||||
@ -146,9 +143,21 @@ func (s *GRPCServer) Sync(req *proto.EncryptedMessage, srv proto.ManagementServi
|
|||||||
peerMeta := extractPeerMeta(ctx, syncReq.GetMeta())
|
peerMeta := extractPeerMeta(ctx, syncReq.GetMeta())
|
||||||
metahashed := metaHash(peerMeta, sRealIP)
|
metahashed := metaHash(peerMeta, sRealIP)
|
||||||
if !s.accountManager.AllowSync(peerKey.String(), metahashed) {
|
if !s.accountManager.AllowSync(peerKey.String(), metahashed) {
|
||||||
|
if s.appMetrics != nil {
|
||||||
|
s.appMetrics.GRPCMetrics().CountSyncRequestBlocked()
|
||||||
|
}
|
||||||
return mapError(ctx, internalStatus.ErrPeerAlreadyLoggedIn)
|
return mapError(ctx, internalStatus.ErrPeerAlreadyLoggedIn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s.appMetrics != nil {
|
||||||
|
s.appMetrics.GRPCMetrics().CountSyncRequest()
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
if s.appMetrics != nil {
|
||||||
|
s.appMetrics.GRPCMetrics().CountSyncRequestDuration(time.Since(reqStart))
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
// nolint:staticcheck
|
// nolint:staticcheck
|
||||||
ctx = context.WithValue(ctx, nbContext.PeerIDKey, peerKey.String())
|
ctx = context.WithValue(ctx, nbContext.PeerIDKey, peerKey.String())
|
||||||
|
|
||||||
@ -197,10 +206,6 @@ func (s *GRPCServer) Sync(req *proto.EncryptedMessage, srv proto.ManagementServi
|
|||||||
|
|
||||||
s.secretsManager.SetupRefresh(ctx, accountID, peer.ID)
|
s.secretsManager.SetupRefresh(ctx, accountID, peer.ID)
|
||||||
|
|
||||||
if s.appMetrics != nil {
|
|
||||||
s.appMetrics.GRPCMetrics().CountSyncRequestDuration(time.Since(reqStart))
|
|
||||||
}
|
|
||||||
|
|
||||||
unlock()
|
unlock()
|
||||||
unlock = nil
|
unlock = nil
|
||||||
|
|
||||||
@ -439,14 +444,6 @@ func (s *GRPCServer) parseRequest(ctx context.Context, req *proto.EncryptedMessa
|
|||||||
// In case of the successful registration login is also successful
|
// In case of the successful registration login is also successful
|
||||||
func (s *GRPCServer) Login(ctx context.Context, req *proto.EncryptedMessage) (*proto.EncryptedMessage, error) {
|
func (s *GRPCServer) Login(ctx context.Context, req *proto.EncryptedMessage) (*proto.EncryptedMessage, error) {
|
||||||
reqStart := time.Now()
|
reqStart := time.Now()
|
||||||
defer func() {
|
|
||||||
if s.appMetrics != nil {
|
|
||||||
s.appMetrics.GRPCMetrics().CountLoginRequestDuration(time.Since(reqStart))
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
if s.appMetrics != nil {
|
|
||||||
s.appMetrics.GRPCMetrics().CountLoginRequest()
|
|
||||||
}
|
|
||||||
realIP := getRealIP(ctx)
|
realIP := getRealIP(ctx)
|
||||||
sRealIP := realIP.String()
|
sRealIP := realIP.String()
|
||||||
log.WithContext(ctx).Debugf("Login request from peer [%s] [%s]", req.WgPubKey, sRealIP)
|
log.WithContext(ctx).Debugf("Login request from peer [%s] [%s]", req.WgPubKey, sRealIP)
|
||||||
@ -460,9 +457,20 @@ func (s *GRPCServer) Login(ctx context.Context, req *proto.EncryptedMessage) (*p
|
|||||||
peerMeta := extractPeerMeta(ctx, loginReq.GetMeta())
|
peerMeta := extractPeerMeta(ctx, loginReq.GetMeta())
|
||||||
metahashed := metaHash(peerMeta, sRealIP)
|
metahashed := metaHash(peerMeta, sRealIP)
|
||||||
if !s.accountManager.AllowSync(peerKey.String(), metahashed) {
|
if !s.accountManager.AllowSync(peerKey.String(), metahashed) {
|
||||||
return nil, mapError(ctx, internalStatus.ErrPeerAlreadyLoggedIn)
|
if s.appMetrics != nil {
|
||||||
|
s.appMetrics.GRPCMetrics().CountLoginRequestBlocked()
|
||||||
|
}
|
||||||
|
return nil, internalStatus.ErrPeerAlreadyLoggedIn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if s.appMetrics != nil {
|
||||||
|
s.appMetrics.GRPCMetrics().CountLoginRequestDuration(time.Since(reqStart))
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
if s.appMetrics != nil {
|
||||||
|
s.appMetrics.GRPCMetrics().CountLoginRequest()
|
||||||
|
}
|
||||||
//nolint
|
//nolint
|
||||||
ctx = context.WithValue(ctx, nbContext.PeerIDKey, peerKey.String())
|
ctx = context.WithValue(ctx, nbContext.PeerIDKey, peerKey.String())
|
||||||
accountID, err := s.accountManager.GetAccountIDForPeerKey(ctx, peerKey.String())
|
accountID, err := s.accountManager.GetAccountIDForPeerKey(ctx, peerKey.String())
|
||||||
|
@ -43,7 +43,7 @@ const (
|
|||||||
type Type int32
|
type Type int32
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrExtraSettingsNotFound = fmt.Errorf("extra settings not found")
|
ErrExtraSettingsNotFound = errors.New("extra settings not found")
|
||||||
ErrPeerAlreadyLoggedIn = errors.New("peer with the same public key is already logged in")
|
ErrPeerAlreadyLoggedIn = errors.New("peer with the same public key is already logged in")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -11,7 +11,9 @@ import (
|
|||||||
type GRPCMetrics struct {
|
type GRPCMetrics struct {
|
||||||
meter metric.Meter
|
meter metric.Meter
|
||||||
syncRequestsCounter metric.Int64Counter
|
syncRequestsCounter metric.Int64Counter
|
||||||
|
syncRequestsBlockedCounter metric.Int64Counter
|
||||||
loginRequestsCounter metric.Int64Counter
|
loginRequestsCounter metric.Int64Counter
|
||||||
|
loginRequestsBlockedCounter metric.Int64Counter
|
||||||
getKeyRequestsCounter metric.Int64Counter
|
getKeyRequestsCounter metric.Int64Counter
|
||||||
activeStreamsGauge metric.Int64ObservableGauge
|
activeStreamsGauge metric.Int64ObservableGauge
|
||||||
syncRequestDuration metric.Int64Histogram
|
syncRequestDuration metric.Int64Histogram
|
||||||
@ -30,6 +32,14 @@ func NewGRPCMetrics(ctx context.Context, meter metric.Meter) (*GRPCMetrics, erro
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
syncRequestsBlockedCounter, err := meter.Int64Counter("management.grpc.sync.request.blocked.counter",
|
||||||
|
metric.WithUnit("1"),
|
||||||
|
metric.WithDescription("Number of sync gRPC requests from blocked peers"),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
loginRequestsCounter, err := meter.Int64Counter("management.grpc.login.request.counter",
|
loginRequestsCounter, err := meter.Int64Counter("management.grpc.login.request.counter",
|
||||||
metric.WithUnit("1"),
|
metric.WithUnit("1"),
|
||||||
metric.WithDescription("Number of login gRPC requests from the peers to authenticate and receive initial configuration and relay credentials"),
|
metric.WithDescription("Number of login gRPC requests from the peers to authenticate and receive initial configuration and relay credentials"),
|
||||||
@ -38,6 +48,14 @@ func NewGRPCMetrics(ctx context.Context, meter metric.Meter) (*GRPCMetrics, erro
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loginRequestsBlockedCounter, err := meter.Int64Counter("management.grpc.login.request.blocked.counter",
|
||||||
|
metric.WithUnit("1"),
|
||||||
|
metric.WithDescription("Number of login gRPC requests from blocked peers"),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
getKeyRequestsCounter, err := meter.Int64Counter("management.grpc.key.request.counter",
|
getKeyRequestsCounter, err := meter.Int64Counter("management.grpc.key.request.counter",
|
||||||
metric.WithUnit("1"),
|
metric.WithUnit("1"),
|
||||||
metric.WithDescription("Number of key gRPC requests from the peers to get the server's public WireGuard key"),
|
metric.WithDescription("Number of key gRPC requests from the peers to get the server's public WireGuard key"),
|
||||||
@ -85,7 +103,9 @@ func NewGRPCMetrics(ctx context.Context, meter metric.Meter) (*GRPCMetrics, erro
|
|||||||
return &GRPCMetrics{
|
return &GRPCMetrics{
|
||||||
meter: meter,
|
meter: meter,
|
||||||
syncRequestsCounter: syncRequestsCounter,
|
syncRequestsCounter: syncRequestsCounter,
|
||||||
|
syncRequestsBlockedCounter: syncRequestsBlockedCounter,
|
||||||
loginRequestsCounter: loginRequestsCounter,
|
loginRequestsCounter: loginRequestsCounter,
|
||||||
|
loginRequestsBlockedCounter: loginRequestsBlockedCounter,
|
||||||
getKeyRequestsCounter: getKeyRequestsCounter,
|
getKeyRequestsCounter: getKeyRequestsCounter,
|
||||||
activeStreamsGauge: activeStreamsGauge,
|
activeStreamsGauge: activeStreamsGauge,
|
||||||
syncRequestDuration: syncRequestDuration,
|
syncRequestDuration: syncRequestDuration,
|
||||||
@ -100,6 +120,11 @@ func (grpcMetrics *GRPCMetrics) CountSyncRequest() {
|
|||||||
grpcMetrics.syncRequestsCounter.Add(grpcMetrics.ctx, 1)
|
grpcMetrics.syncRequestsCounter.Add(grpcMetrics.ctx, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CountSyncRequestBlocked counts the number of gRPC sync requests from blocked peers
|
||||||
|
func (grpcMetrics *GRPCMetrics) CountSyncRequestBlocked() {
|
||||||
|
grpcMetrics.syncRequestsBlockedCounter.Add(grpcMetrics.ctx, 1)
|
||||||
|
}
|
||||||
|
|
||||||
// CountGetKeyRequest counts the number of gRPC get server key requests coming to the gRPC API
|
// CountGetKeyRequest counts the number of gRPC get server key requests coming to the gRPC API
|
||||||
func (grpcMetrics *GRPCMetrics) CountGetKeyRequest() {
|
func (grpcMetrics *GRPCMetrics) CountGetKeyRequest() {
|
||||||
grpcMetrics.getKeyRequestsCounter.Add(grpcMetrics.ctx, 1)
|
grpcMetrics.getKeyRequestsCounter.Add(grpcMetrics.ctx, 1)
|
||||||
@ -110,6 +135,11 @@ func (grpcMetrics *GRPCMetrics) CountLoginRequest() {
|
|||||||
grpcMetrics.loginRequestsCounter.Add(grpcMetrics.ctx, 1)
|
grpcMetrics.loginRequestsCounter.Add(grpcMetrics.ctx, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CountLoginRequestBlocked counts the number of gRPC login requests from blocked peers
|
||||||
|
func (grpcMetrics *GRPCMetrics) CountLoginRequestBlocked() {
|
||||||
|
grpcMetrics.loginRequestsBlockedCounter.Add(grpcMetrics.ctx, 1)
|
||||||
|
}
|
||||||
|
|
||||||
// CountLoginRequestDuration counts the duration of the login gRPC requests
|
// CountLoginRequestDuration counts the duration of the login gRPC requests
|
||||||
func (grpcMetrics *GRPCMetrics) CountLoginRequestDuration(duration time.Duration) {
|
func (grpcMetrics *GRPCMetrics) CountLoginRequestDuration(duration time.Duration) {
|
||||||
grpcMetrics.loginRequestDuration.Record(grpcMetrics.ctx, duration.Milliseconds())
|
grpcMetrics.loginRequestDuration.Record(grpcMetrics.ctx, duration.Milliseconds())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user