Skip to content

Commit b60cfd6

Browse files
committed
replace and fix timeout messages with a field
1 parent 658ab16 commit b60cfd6

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

protocols/gossipsub/src/behaviour.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3078,30 +3078,28 @@ where
30783078
}
30793079

30803080
// Keep track of expired messages for the application layer.
3081+
let failed_messages = self.failed_messages.entry(propagation_source).or_default();
3082+
failed_messages.timeout += 1;
30813083
match rpc {
30823084
RpcOut::Publish { .. } => {
3083-
self.failed_messages
3084-
.entry(propagation_source)
3085-
.or_default()
3086-
.publish += 1;
3085+
failed_messages.publish += 1;
30873086
}
30883087
RpcOut::Forward { .. } => {
3089-
self.failed_messages
3090-
.entry(propagation_source)
3091-
.or_default()
3092-
.forward += 1;
3088+
failed_messages.forward += 1;
30933089
}
3094-
_ => {} //
3090+
_ => {}
30953091
}
30963092

30973093
// Record metrics on the failure.
30983094
if let Some(metrics) = self.metrics.as_mut() {
30993095
match rpc {
31003096
RpcOut::Publish { message, .. } => {
31013097
metrics.publish_msg_dropped(&message.topic);
3098+
metrics.timeout_msg_dropped(&message.topic);
31023099
}
31033100
RpcOut::Forward { message, .. } => {
31043101
metrics.forward_msg_dropped(&message.topic);
3102+
metrics.timeout_msg_dropped(&message.topic);
31053103
}
31063104
_ => {}
31073105
}

protocols/gossipsub/src/metrics.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ pub(crate) struct Metrics {
131131
publish_messages_dropped: Family<TopicHash, Counter>,
132132
/// The number of forward messages dropped by the sender.
133133
forward_messages_dropped: Family<TopicHash, Counter>,
134+
/// The number of messages that timed out and could not be sent.
135+
timedout_messages_dropped: Family<TopicHash, Counter>,
134136

135137
/* Metrics regarding mesh state */
136138
/// Number of peers in our mesh. This metric should be updated with the count of peers for a
@@ -241,6 +243,11 @@ impl Metrics {
241243
"Number of forward messages dropped per topic"
242244
);
243245

246+
let timeout_messages_dropped = register_family!(
247+
"timeout_messages_dropped_per_topic",
248+
"Number of timedout messages dropped per topic"
249+
);
250+
244251
let mesh_peer_counts = register_family!(
245252
"mesh_peer_counts",
246253
"Number of peers in each topic in our mesh"
@@ -347,6 +354,7 @@ impl Metrics {
347354
rejected_messages,
348355
publish_messages_dropped,
349356
forward_messages_dropped,
357+
timedout_messages_dropped: timeout_messages_dropped,
350358
mesh_peer_counts,
351359
mesh_peer_inclusion_events,
352360
mesh_peer_churn_events,
@@ -508,6 +516,13 @@ impl Metrics {
508516
}
509517
}
510518

519+
/// Register dropping a message that timedout over a topic.
520+
pub(crate) fn timeout_msg_dropped(&mut self, topic: &TopicHash) {
521+
if self.register_topic(topic).is_ok() {
522+
self.timedout_messages_dropped.get_or_create(topic).inc();
523+
}
524+
}
525+
511526
/// Register that a message was received (and was not a duplicate).
512527
pub(crate) fn msg_recvd(&mut self, topic: &TopicHash) {
513528
if self.register_topic(topic).is_ok() {

protocols/gossipsub/src/types.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use crate::rpc_proto::proto;
3333
#[cfg(feature = "serde")]
3434
use serde::{Deserialize, Serialize};
3535

36-
/// The type of messages that have expired while attempting to send to a peer.
36+
/// Messages that have expired while attempting to be sent to a peer.
3737
#[derive(Clone, Debug, Default)]
3838
pub struct FailedMessages {
3939
/// The number of publish messages that failed to be published in a heartbeat.
@@ -44,14 +44,11 @@ pub struct FailedMessages {
4444
pub priority: usize,
4545
/// The number of messages that were failed to be sent to the non-priority queue as it was full.
4646
pub non_priority: usize,
47+
/// The number of messages that timed out and could not be sent.
48+
pub timeout: usize,
4749
}
4850

4951
impl FailedMessages {
50-
/// The total number of messages that expired due a timeout.
51-
pub fn total_timeout(&self) -> usize {
52-
self.publish + self.forward
53-
}
54-
5552
/// The total number of messages that failed due to the queue being full.
5653
pub fn total_queue_full(&self) -> usize {
5754
self.priority + self.non_priority

0 commit comments

Comments
 (0)