Skip to content

Commit c137d57

Browse files
authored
feat(gossipsub): record the bytes received from last gossip message
Add extra metrics for recording bytes sent and received on each topic. This will be helpful for a future PR implementing the [partial messages spec](libp2p/specs#685) Pull-Request: #6192.
1 parent 3591add commit c137d57

3 files changed

Lines changed: 59 additions & 6 deletions

File tree

protocols/gossipsub/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## 0.50.0
22

3+
- Add extra metrics for bytes received and sent, filtered and unfiltered for each topic.
4+
See [PR 6192](https://github.com/libp2p/rust-libp2p/pull/6192)
5+
36
- Reduce log size by implementing custom Debug for RawMessage that logs data length instead of full byte arrays.
47
See [PR 6263](https://github.com/libp2p/rust-libp2p/pull/6263)
58

protocols/gossipsub/src/behaviour.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1808,7 +1808,7 @@ where
18081808
// Record the received message with the metrics
18091809
#[cfg(feature = "metrics")]
18101810
if let Some(metrics) = self.metrics.as_mut() {
1811-
metrics.msg_recvd(&message.topic);
1811+
metrics.msg_recvd(&message.topic, raw_message.raw_protobuf_len());
18121812
}
18131813

18141814
// Tells score that message arrived (but is maybe not fully validated yet).

protocols/gossipsub/src/metrics.rs

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,23 @@ pub(crate) struct Metrics {
148148
topic_msg_sent_counts: Family<TopicHash, Counter>,
149149
/// Bytes from gossip messages sent to each topic.
150150
topic_msg_sent_bytes: Family<TopicHash, Counter>,
151+
/// Bytes from the last gossip messages sent to each topic.
152+
topic_msg_last_sent_bytes: Family<TopicHash, Gauge>,
151153
/// Number of gossipsub messages published to each topic.
152154
topic_msg_published: Family<TopicHash, Counter>,
153155

154156
/// Number of gossipsub messages received on each topic (without filtering duplicates).
155157
topic_msg_recv_counts_unfiltered: Family<TopicHash, Counter>,
156158
/// Number of gossipsub messages received on each topic (after filtering duplicates).
157159
topic_msg_recv_counts: Family<TopicHash, Counter>,
158-
/// Bytes received from gossip messages for each topic.
160+
/// Bytes received from gossip messages for each topic (after filtering duplicates).
159161
topic_msg_recv_bytes: Family<TopicHash, Counter>,
162+
/// Bytes received from last gossip message for each topic (after filtering duplicates).
163+
topic_msg_last_recv_bytes: Family<TopicHash, Gauge>,
164+
/// Bytes received from gossip messages for each topic (without filtering duplicates).
165+
topic_msg_recv_bytes_unfiltered: Family<TopicHash, Counter>,
166+
/// Bytes received from last gossip message for each topic (without filtering duplicates).
167+
topic_msg_last_recv_bytes_unfiltered: Family<TopicHash, Gauge>,
160168

161169
// Metrics related to scoring
162170
/// Histogram of the scores for each mesh topic.
@@ -248,25 +256,35 @@ impl Metrics {
248256
"mesh_peer_counts",
249257
"Number of peers in each topic in our mesh"
250258
);
259+
251260
let mesh_peer_inclusion_events = register_family!(
252261
"mesh_peer_inclusion_events",
253262
"Number of times a peer gets added to our mesh for different reasons"
254263
);
264+
255265
let mesh_peer_churn_events = register_family!(
256266
"mesh_peer_churn_events",
257267
"Number of times a peer gets removed from our mesh for different reasons"
258268
);
269+
259270
let topic_msg_sent_counts = register_family!(
260271
"topic_msg_sent_counts",
261272
"Number of gossip messages sent to each topic"
262273
);
274+
263275
let topic_msg_published = register_family!(
264276
"topic_msg_published",
265277
"Number of gossip messages published to each topic"
266278
);
279+
267280
let topic_msg_sent_bytes = register_family!(
268281
"topic_msg_sent_bytes",
269-
"Bytes from gossip messages sent to each topic"
282+
"bytes from gossip messages sent to each topic (after duplicates being filtered)"
283+
);
284+
285+
let topic_msg_last_sent_bytes = register_family!(
286+
"topic_msg_sent_bytes",
287+
"bytes from the last gossip message sent to each topic (after duplicates being filtered)"
270288
);
271289

272290
let topic_msg_recv_counts_unfiltered = register_family!(
@@ -278,9 +296,25 @@ impl Metrics {
278296
"topic_msg_recv_counts",
279297
"Number of gossip messages received on each topic (after duplicates have been filtered)"
280298
);
299+
281300
let topic_msg_recv_bytes = register_family!(
282301
"topic_msg_recv_bytes",
283-
"Bytes received from gossip messages for each topic"
302+
"Bytes received from gossip messages for each topic (after duplicates being filtered)"
303+
);
304+
305+
let topic_msg_last_recv_bytes = register_family!(
306+
"topic_msg_last_recv_bytes",
307+
"Bytes received from last gossip message for each topic (after duplicates being filtered)"
308+
);
309+
310+
let topic_msg_recv_bytes_unfiltered = register_family!(
311+
"topic_msg_recv_bytes_unfiltered",
312+
"Bytes received from gossip messages for each topic (without duplicates being filtered)"
313+
);
314+
315+
let topic_msg_last_recv_bytes_unfiltered = register_family!(
316+
"topic_msg_last_recv_bytes_unfiltered",
317+
"Bytes received from last gossip message for each topic (without duplicates being filtered)"
284318
);
285319

286320
let hist_builder = HistBuilder {
@@ -390,10 +424,14 @@ impl Metrics {
390424
mesh_peer_churn_events,
391425
topic_msg_sent_counts,
392426
topic_msg_sent_bytes,
427+
topic_msg_last_sent_bytes,
393428
topic_msg_published,
394429
topic_msg_recv_counts_unfiltered,
395430
topic_msg_recv_counts,
396431
topic_msg_recv_bytes,
432+
topic_msg_last_recv_bytes,
433+
topic_msg_recv_bytes_unfiltered,
434+
topic_msg_last_recv_bytes_unfiltered,
397435
score_per_mesh,
398436
scoring_penalties,
399437
peers_per_protocol,
@@ -532,13 +570,22 @@ impl Metrics {
532570
self.topic_msg_sent_bytes
533571
.get_or_create(topic)
534572
.inc_by(bytes as u64);
573+
self.topic_msg_last_sent_bytes
574+
.get_or_create(topic)
575+
.set(bytes as i64);
535576
}
536577
}
537578

538579
/// Register that a message was received (and was not a duplicate).
539-
pub(crate) fn msg_recvd(&mut self, topic: &TopicHash) {
580+
pub(crate) fn msg_recvd(&mut self, topic: &TopicHash, bytes: usize) {
540581
if self.register_topic(topic).is_ok() {
541582
self.topic_msg_recv_counts.get_or_create(topic).inc();
583+
self.topic_msg_recv_bytes
584+
.get_or_create(topic)
585+
.inc_by(bytes as u64);
586+
self.topic_msg_last_recv_bytes
587+
.get_or_create(topic)
588+
.set(bytes as i64);
542589
}
543590
}
544591

@@ -548,9 +595,12 @@ impl Metrics {
548595
self.topic_msg_recv_counts_unfiltered
549596
.get_or_create(topic)
550597
.inc();
551-
self.topic_msg_recv_bytes
598+
self.topic_msg_recv_bytes_unfiltered
552599
.get_or_create(topic)
553600
.inc_by(bytes as u64);
601+
self.topic_msg_last_recv_bytes_unfiltered
602+
.get_or_create(topic)
603+
.set(bytes as i64);
554604
}
555605
}
556606

0 commit comments

Comments
 (0)