-
Notifications
You must be signed in to change notification settings - Fork 805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add metric 'Number of bytes received from each topic (deduplicated)' #6431
base: unstable
Are you sure you want to change the base?
Changes from 6 commits
20b5a58
f6b0a8f
4c75584
05e900f
11db2eb
a1d4da8
5003236
5b8bb1f
3be0a27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,10 @@ impl TopicHash { | |
pub fn as_str(&self) -> &str { | ||
&self.hash | ||
} | ||
|
||
pub fn hash_byte_len(&self) -> usize { | ||
self.hash.as_bytes().len() | ||
} | ||
Comment on lines
+86
to
+88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: we are only using this once and it's a one liner, no need for a function to abstract the one liner |
||
} | ||
|
||
/// A gossipsub topic. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ use hashlink::LinkedHashMap; | |
use libp2p::identity::PeerId; | ||
use libp2p::swarm::ConnectionId; | ||
use prometheus_client::encoding::EncodeLabelValue; | ||
use quick_protobuf::sizeofs::*; | ||
use quick_protobuf::MessageWrite; | ||
use std::collections::BTreeSet; | ||
use std::fmt::Debug; | ||
|
@@ -237,6 +238,21 @@ impl fmt::Debug for Message { | |
} | ||
} | ||
|
||
/// The byte size of a message | ||
impl Message { | ||
pub(crate) fn get_size(&self) -> usize { | ||
self.source | ||
.as_ref() | ||
.map_or(0, |m| 1 + sizeof_len(m.to_bytes().len())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The PeerID has a fixed length by definition, we could just precompute it |
||
+ sizeof_len(self.data.len()) | ||
+ self | ||
.sequence_number | ||
.as_ref() | ||
.map_or(0, |m| 1 + sizeof_varint(*(m))) | ||
+ sizeof_len(self.topic.hash_byte_len()) | ||
} | ||
} | ||
|
||
/// A subscription received by the gossipsub system. | ||
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
pub struct Subscription { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you use
get_size()
and above we useraw_protobuf_len
what motivates the difference?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use
raw_protobuf_len
to obtain the byte length of received message.Message
is transformed data fromRawMessage
and is missing some fields compared toRawMessage
, somessage.get_size()
returns a smaller byte size than the actually received bytes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah the
get_size
function is unrequired we can just useraw_protobuf_len