fixed panic, added different metrics for nil peer and suppressed msgs

This commit is contained in:
crn4
2025-09-16 23:21:56 +02:00
parent 00278a472f
commit a1fa0d79e5
2 changed files with 19 additions and 11 deletions

View File

@@ -119,5 +119,8 @@ func (registry *Registry) Deregister(peer *Peer) {
} }
func (peer *Peer) SendMessageAllowed(destination string, size int, arrivedTime time.Time) bool { func (peer *Peer) SendMessageAllowed(destination string, size int, arrivedTime time.Time) bool {
if peer == nil || peer.suppressor == nil {
return false
}
return peer.suppressor.PackageReceived(suppressor.PeerID(destination), size, arrivedTime) return peer.suppressor.PackageReceived(suppressor.PeerID(destination), size, arrivedTime)
} }

View File

@@ -23,16 +23,17 @@ import (
) )
const ( const (
labelType = "type" labelType = "type"
labelTypeError = "error" labelTypeError = "error"
labelTypeNotConnected = "not_connected" labelTypeNotConnected = "not_connected"
labelTypeNotRegistered = "not_registered" labelTypeNotRegistered = "not_registered"
labelTypeSenderNotRegistered = "sender_not_registered" labelTypeSenderNotRegistered = "sender_not_registered"
labelTypeMessageSuppressed = "message_suppressed" labelTypeMessageSuppressed = "message_suppressed"
labelTypeStream = "stream" labelTypeMessageSuppressedDisconnected = "message_suppressed_disconnected"
labelTypeMessage = "message" labelTypeStream = "stream"
labelTypeTimeout = "timeout" labelTypeMessage = "message"
labelTypeDisconnected = "disconnected" labelTypeTimeout = "timeout"
labelTypeDisconnected = "disconnected"
labelError = "error" labelError = "error"
labelErrorMissingId = "missing_id" labelErrorMissingId = "missing_id"
@@ -105,7 +106,11 @@ func (s *Server) Send(ctx context.Context, msg *proto.EncryptedMessage) (*proto.
} }
if !peer.SendMessageAllowed(msg.RemoteKey, len(msg.Body), time.Now()) { if !peer.SendMessageAllowed(msg.RemoteKey, len(msg.Body), time.Now()) {
s.metrics.MessageForwardFailures.Add(ctx, 1, metric.WithAttributes(attribute.String(labelType, labelTypeMessageSuppressed))) if peer == nil {
s.metrics.MessageForwardFailures.Add(ctx, 1, metric.WithAttributes(attribute.String(labelType, labelTypeMessageSuppressedDisconnected)))
} else {
s.metrics.MessageForwardFailures.Add(ctx, 1, metric.WithAttributes(attribute.String(labelType, labelTypeMessageSuppressed)))
}
s.metrics.MessageSize.Record(ctx, int64(len(msg.Body)), metric.WithAttributes(attribute.String(labelType, labelTypeMessageSuppressed))) s.metrics.MessageSize.Record(ctx, int64(len(msg.Body)), metric.WithAttributes(attribute.String(labelType, labelTypeMessageSuppressed)))
log.Tracef("message from peer [%s] to peer [%s] suppressed due to repetition", msg.Key, msg.RemoteKey) log.Tracef("message from peer [%s] to peer [%s] suppressed due to repetition", msg.Key, msg.RemoteKey)
} }