Add a sub_libp2p_notifications_queues_size Prometheus metric (#5503)

* Add a sub_libp2p_notifications_queues_size Prometheus metric

* Fix network tests

* Address review
This commit is contained in:
Pierre Krieger
2020-04-03 08:43:55 +02:00
committed by GitHub
parent 7983a8184b
commit e8dfb37aaf
8 changed files with 81 additions and 13 deletions
@@ -38,7 +38,7 @@ use futures::{prelude::*, ready};
use futures_codec::Framed;
use libp2p::core::{UpgradeInfo, InboundUpgrade, OutboundUpgrade, upgrade};
use log::error;
use std::{borrow::Cow, collections::VecDeque, io, iter, mem, pin::Pin, task::{Context, Poll}};
use std::{borrow::Cow, collections::VecDeque, convert::TryFrom as _, io, iter, mem, pin::Pin, task::{Context, Poll}};
use unsigned_varint::codec::UviBytes;
/// Maximum allowed size of the two handshake messages, in bytes.
@@ -280,6 +280,13 @@ where TSubstream: AsyncRead + AsyncWrite + Unpin + Send + 'static,
}
}
impl<TSubstream> NotificationsOutSubstream<TSubstream> {
/// Returns the number of items in the queue, capped to `u32::max_value()`.
pub fn queue_len(&self) -> u32 {
u32::try_from(self.messages_queue.len()).unwrap_or(u32::max_value())
}
}
impl<TSubstream> Sink<Vec<u8>> for NotificationsOutSubstream<TSubstream>
where TSubstream: AsyncRead + AsyncWrite + Unpin,
{