mirror of
https://github.com/netbirdio/netbird.git
synced 2025-02-16 10:20:09 +01:00
Add get_registration_delay_milliseconds metric (#2275)
This commit is contained in:
parent
f9c59a7131
commit
7c595e8493
@ -90,6 +90,9 @@ The Signal Server exposes the following metrics in Prometheus format:
|
|||||||
- **registration_delay_milliseconds**: A Histogram metric that measures the time
|
- **registration_delay_milliseconds**: A Histogram metric that measures the time
|
||||||
it took to register a peer in
|
it took to register a peer in
|
||||||
milliseconds.
|
milliseconds.
|
||||||
|
- **get_registration_delay_milliseconds**: A Histogram metric that measures the time
|
||||||
|
it took to get a peer registration in
|
||||||
|
milliseconds.
|
||||||
- **messages_forwarded_total**: A Counter metric that counts the total number of
|
- **messages_forwarded_total**: A Counter metric that counts the total number of
|
||||||
messages forwarded between peers.
|
messages forwarded between peers.
|
||||||
- **message_forward_failures_total**: A Counter metric that counts the total
|
- **message_forward_failures_total**: A Counter metric that counts the total
|
||||||
|
@ -15,6 +15,7 @@ type AppMetrics struct {
|
|||||||
Deregistrations metric.Int64Counter
|
Deregistrations metric.Int64Counter
|
||||||
RegistrationFailures metric.Int64Counter
|
RegistrationFailures metric.Int64Counter
|
||||||
RegistrationDelay metric.Float64Histogram
|
RegistrationDelay metric.Float64Histogram
|
||||||
|
GetRegistrationDelay metric.Float64Histogram
|
||||||
|
|
||||||
MessagesForwarded metric.Int64Counter
|
MessagesForwarded metric.Int64Counter
|
||||||
MessageForwardFailures metric.Int64Counter
|
MessageForwardFailures metric.Int64Counter
|
||||||
@ -54,6 +55,12 @@ func NewAppMetrics(meter metric.Meter) (*AppMetrics, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getRegistrationDelay, err := meter.Float64Histogram("get_registration_delay_milliseconds",
|
||||||
|
metric.WithExplicitBucketBoundaries(getStandardBucketBoundaries()...))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
messagesForwarded, err := meter.Int64Counter("messages_forwarded_total")
|
messagesForwarded, err := meter.Int64Counter("messages_forwarded_total")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -80,6 +87,7 @@ func NewAppMetrics(meter metric.Meter) (*AppMetrics, error) {
|
|||||||
Deregistrations: deregistrations,
|
Deregistrations: deregistrations,
|
||||||
RegistrationFailures: registrationFailures,
|
RegistrationFailures: registrationFailures,
|
||||||
RegistrationDelay: registrationDelay,
|
RegistrationDelay: registrationDelay,
|
||||||
|
GetRegistrationDelay: getRegistrationDelay,
|
||||||
|
|
||||||
MessagesForwarded: messagesForwarded,
|
MessagesForwarded: messagesForwarded,
|
||||||
MessageForwardFailures: messageForwardFailures,
|
MessageForwardFailures: messageForwardFailures,
|
||||||
|
@ -30,6 +30,10 @@ const (
|
|||||||
labelErrorMissingId = "missing_id"
|
labelErrorMissingId = "missing_id"
|
||||||
labelErrorMissingMeta = "missing_meta"
|
labelErrorMissingMeta = "missing_meta"
|
||||||
labelErrorFailedHeader = "failed_header"
|
labelErrorFailedHeader = "failed_header"
|
||||||
|
|
||||||
|
labelRegistrionStatus = "status"
|
||||||
|
labelRegistrationFound = "found"
|
||||||
|
labelRegistrationNotFound = "not_found"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server an instance of a Signal server
|
// Server an instance of a Signal server
|
||||||
@ -63,7 +67,10 @@ func (s *Server) Send(ctx context.Context, msg *proto.EncryptedMessage) (*proto.
|
|||||||
return nil, fmt.Errorf("peer %s is not registered", msg.Key)
|
return nil, fmt.Errorf("peer %s is not registered", msg.Key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getRegistrationStart := time.Now()
|
||||||
|
|
||||||
if dstPeer, found := s.registry.Get(msg.RemoteKey); found {
|
if dstPeer, found := s.registry.Get(msg.RemoteKey); found {
|
||||||
|
s.metrics.GetRegistrationDelay.Record(ctx, float64(time.Since(getRegistrationStart).Nanoseconds())/1e6, metric.WithAttributes(attribute.String(labelType, labelTypeMessage), attribute.String(labelRegistrionStatus, labelRegistrationFound)))
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
//forward the message to the target peer
|
//forward the message to the target peer
|
||||||
if err := dstPeer.Stream.Send(msg); err != nil {
|
if err := dstPeer.Stream.Send(msg); err != nil {
|
||||||
@ -76,6 +83,7 @@ func (s *Server) Send(ctx context.Context, msg *proto.EncryptedMessage) (*proto.
|
|||||||
s.metrics.MessagesForwarded.Add(context.Background(), 1)
|
s.metrics.MessagesForwarded.Add(context.Background(), 1)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
s.metrics.GetRegistrationDelay.Record(ctx, float64(time.Since(getRegistrationStart).Nanoseconds())/1e6, metric.WithAttributes(attribute.String(labelType, labelTypeMessage), attribute.String(labelRegistrionStatus, labelRegistrationNotFound)))
|
||||||
log.Debugf("message from peer [%s] can't be forwarded to peer [%s] because destination peer is not connected", msg.Key, msg.RemoteKey)
|
log.Debugf("message from peer [%s] can't be forwarded to peer [%s] because destination peer is not connected", msg.Key, msg.RemoteKey)
|
||||||
//todo respond to the sender?
|
//todo respond to the sender?
|
||||||
|
|
||||||
@ -125,8 +133,11 @@ func (s *Server) ConnectStream(stream proto.SignalExchange_ConnectStreamServer)
|
|||||||
|
|
||||||
log.Debugf("received a new message from peer [%s] to peer [%s]", p.Id, msg.RemoteKey)
|
log.Debugf("received a new message from peer [%s] to peer [%s]", p.Id, msg.RemoteKey)
|
||||||
|
|
||||||
|
getRegistrationStart := time.Now()
|
||||||
|
|
||||||
// lookup the target peer where the message is going to
|
// lookup the target peer where the message is going to
|
||||||
if dstPeer, found := s.registry.Get(msg.RemoteKey); found {
|
if dstPeer, found := s.registry.Get(msg.RemoteKey); found {
|
||||||
|
s.metrics.GetRegistrationDelay.Record(stream.Context(), float64(time.Since(getRegistrationStart).Nanoseconds())/1e6, metric.WithAttributes(attribute.String(labelType, labelTypeStream), attribute.String(labelRegistrionStatus, labelRegistrationFound)))
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
//forward the message to the target peer
|
//forward the message to the target peer
|
||||||
if err := dstPeer.Stream.Send(msg); err != nil {
|
if err := dstPeer.Stream.Send(msg); err != nil {
|
||||||
@ -139,10 +150,10 @@ func (s *Server) ConnectStream(stream proto.SignalExchange_ConnectStreamServer)
|
|||||||
s.metrics.MessagesForwarded.Add(stream.Context(), 1)
|
s.metrics.MessagesForwarded.Add(stream.Context(), 1)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
s.metrics.GetRegistrationDelay.Record(stream.Context(), float64(time.Since(getRegistrationStart).Nanoseconds())/1e6, metric.WithAttributes(attribute.String(labelType, labelTypeStream), attribute.String(labelRegistrionStatus, labelRegistrationNotFound)))
|
||||||
|
s.metrics.MessageForwardFailures.Add(stream.Context(), 1, metric.WithAttributes(attribute.String(labelType, labelTypeNotConnected)))
|
||||||
log.Debugf("message from peer [%s] can't be forwarded to peer [%s] because destination peer is not connected", p.Id, msg.RemoteKey)
|
log.Debugf("message from peer [%s] can't be forwarded to peer [%s] because destination peer is not connected", p.Id, msg.RemoteKey)
|
||||||
//todo respond to the sender?
|
//todo respond to the sender?
|
||||||
|
|
||||||
s.metrics.MessageForwardFailures.Add(stream.Context(), 1, metric.WithAttributes(attribute.String(labelType, labelTypeNotConnected)))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
<-stream.Context().Done()
|
<-stream.Context().Done()
|
||||||
|
Loading…
Reference in New Issue
Block a user