mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-25 01:23:22 +01:00
[signal] Fix signal active peers metrics (#2591)
This commit is contained in:
parent
82739e2832
commit
730dd1733e
@ -82,8 +82,11 @@ func (registry *Registry) Register(peer *Peer) {
|
|||||||
log.Warnf("peer [%s] is already registered [new streamID %d, previous StreamID %d]. Will override stream.",
|
log.Warnf("peer [%s] is already registered [new streamID %d, previous StreamID %d]. Will override stream.",
|
||||||
peer.Id, peer.StreamID, pp.StreamID)
|
peer.Id, peer.StreamID, pp.StreamID)
|
||||||
registry.Peers.Store(peer.Id, peer)
|
registry.Peers.Store(peer.Id, peer)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("peer registered [%s]", peer.Id)
|
log.Debugf("peer registered [%s]", peer.Id)
|
||||||
|
registry.metrics.ActivePeers.Add(context.Background(), 1)
|
||||||
|
|
||||||
// record time as milliseconds
|
// record time as milliseconds
|
||||||
registry.metrics.RegistrationDelay.Record(context.Background(), float64(time.Since(start).Nanoseconds())/1e6)
|
registry.metrics.RegistrationDelay.Record(context.Background(), float64(time.Since(start).Nanoseconds())/1e6)
|
||||||
@ -105,8 +108,8 @@ func (registry *Registry) Deregister(peer *Peer) {
|
|||||||
peer.Id, pp.StreamID, peer.StreamID)
|
peer.Id, pp.StreamID, peer.StreamID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
registry.metrics.ActivePeers.Add(context.Background(), -1)
|
||||||
log.Debugf("peer deregistered [%s]", peer.Id)
|
log.Debugf("peer deregistered [%s]", peer.Id)
|
||||||
|
|
||||||
registry.metrics.Deregistrations.Add(context.Background(), 1)
|
registry.metrics.Deregistrations.Add(context.Background(), 1)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -133,8 +133,6 @@ func (s *Server) RegisterPeer(stream proto.SignalExchange_ConnectStreamServer) (
|
|||||||
s.registry.Register(p)
|
s.registry.Register(p)
|
||||||
s.dispatcher.ListenForMessages(stream.Context(), p.Id, s.forwardMessageToPeer)
|
s.dispatcher.ListenForMessages(stream.Context(), p.Id, s.forwardMessageToPeer)
|
||||||
|
|
||||||
s.metrics.ActivePeers.Add(stream.Context(), 1)
|
|
||||||
|
|
||||||
return p, nil
|
return p, nil
|
||||||
} else {
|
} else {
|
||||||
s.metrics.RegistrationFailures.Add(stream.Context(), 1, metric.WithAttributes(attribute.String(labelError, labelErrorMissingId)))
|
s.metrics.RegistrationFailures.Add(stream.Context(), 1, metric.WithAttributes(attribute.String(labelError, labelErrorMissingId)))
|
||||||
@ -151,7 +149,6 @@ func (s *Server) DeregisterPeer(p *peer.Peer) {
|
|||||||
s.registry.Deregister(p)
|
s.registry.Deregister(p)
|
||||||
|
|
||||||
s.metrics.PeerConnectionDuration.Record(p.Stream.Context(), int64(time.Since(p.RegisteredAt).Seconds()))
|
s.metrics.PeerConnectionDuration.Record(p.Stream.Context(), int64(time.Since(p.RegisteredAt).Seconds()))
|
||||||
s.metrics.ActivePeers.Add(context.Background(), -1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) forwardMessageToPeer(ctx context.Context, msg *proto.EncryptedMessage) {
|
func (s *Server) forwardMessageToPeer(ctx context.Context, msg *proto.EncryptedMessage) {
|
||||||
|
Loading…
Reference in New Issue
Block a user