Skip to content
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

feat: add ethereum/beacon-metrics per spec #508

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1212,11 +1212,12 @@ export class GossipSub extends TypedEventEmitter<GossipsubEvents> implements Pub
* May forward to all peers in the mesh.
*/
private async handleReceivedMessage (from: PeerId, rpcMsg: RPC.Message): Promise<void> {
this.metrics?.onMsgRecvPreValidation(rpcMsg.topic)
const topic = this.metrics?.toTopic(rpcMsg.topic) ?? ''
const messageBytes = RPC.Message.getSize(rpcMsg)

this.metrics?.onMsgRecvPreValidation(topic, messageBytes)
const validationResult = await this.validateReceivedMessage(from, rpcMsg)

this.metrics?.onPrevalidationResult(rpcMsg.topic, validationResult.code)
this.metrics?.onPrevalidationResult(topic, messageBytes, validationResult.code)

const validationCode = validationResult.code
switch (validationCode) {
Expand Down Expand Up @@ -2294,7 +2295,7 @@ export class GossipSub extends TypedEventEmitter<GossipsubEvents> implements Pub
topic,
tosendCount,
tosend.size,
rawMsg.data != null ? rawMsg.data.length : 0,
RPC.Message.getSize(rawMsg),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed this, we were only counting the "data" portion but more than that gets sent over the wire in a RPC.message. I updated with this method but not sure if that is "correct" because I did not find anything in the spec speaking to this.

durationMs
)

Expand Down
9 changes: 9 additions & 0 deletions src/message/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,15 @@ export namespace RPC {
export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<Message>): Message => {
return decodeMessage(buf, Message.codec(), opts)
}

export const getSize = (msg: Message): number => {
return (msg.from?.length ?? 0) +
(msg.data?.length ?? 0) +
(msg.seqno?.length ?? 0) +
(msg.topic?.length ?? 0) +
(msg.signature?.length ?? 0) +
(msg.key?.length ?? 0)
}
}

export interface ControlMessage {
Expand Down
64 changes: 46 additions & 18 deletions src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,20 @@ export function getMetrics (
// publish message. Track peers sent to and bytes
/** Total count of msg published by topic */
msgPublishCount: register.gauge<{ topic: TopicLabel }>({
name: 'gossipsub_msg_publish_count_total',
// ethereum/beacon-metrics defined
// https://github.com/ethereum/beacon-metrics/pull/13
name: 'gossipsub_topic_msg_sent_counts_total',
help: 'Total count of msg published by topic',
labelNames: ['topic']
}),
/** Total count of msg publish data.length bytes */
msgPublishBytes: register.gauge<{ topic: TopicLabel }>({
// ethereum/beacon-metrics defined
// https://github.com/ethereum/beacon-metrics/pull/13
name: 'gossipsub_topic_msg_sent_bytes_total',
help: 'Total count of msg publish data.length bytes',
labelNames: ['topic']
}),
/** Total count of peers that we publish a msg to */
msgPublishPeersByTopic: register.gauge<{ topic: TopicLabel }>({
name: 'gossipsub_msg_publish_peers_total',
Expand Down Expand Up @@ -397,12 +407,6 @@ export function getMetrics (
help: 'Total fanout peers that we publish a msg to',
labelNames: ['topic']
}),
/** Total count of msg publish data.length bytes */
msgPublishBytes: register.gauge<{ topic: TopicLabel }>({
name: 'gossipsub_msg_publish_bytes_total',
help: 'Total count of msg publish data.length bytes',
labelNames: ['topic']
}),
/** Total time in seconds to publish a message */
msgPublishTime: register.histogram<{ topic: TopicLabel }>({
name: 'gossipsub_msg_publish_seconds',
Expand All @@ -424,9 +428,33 @@ export function getMetrics (
labelNames: ['topic']
}),

/** Total count of recv msgs before any validation */
msgReceivedPreValidation: register.gauge<{ topic: TopicLabel }>({
name: 'gossipsub_msg_received_prevalidation_total',
/** Total count of recv msgs before any validation (unfiltered) */
msgReceivedTotalUnfilteredCount: register.gauge<{ topic: TopicLabel }>({
// ethereum/beacon-metrics defined
// https://github.com/ethereum/beacon-metrics/pull/13
name: 'gossipsub_topic_msg_recv_counts_unfiltered_total',
help: 'Total count of recv msgs before any validation',
labelNames: ['topic']
}),
msgReceivedTotalBytesUnfilteredCount: register.gauge<{ topic: TopicLabel }>({
// ethereum/beacon-metrics defined
// https://github.com/ethereum/beacon-metrics/pull/13
name: 'gossipsub_topic_msg_recv_bytes_unfiltered_total',
help: 'Total count of recv msgs before any validation',
labelNames: ['topic']
}),
/** Total count/bytes of received messages after deduplication */
msgReceivedTotalCount: register.gauge<{ topic: TopicLabel }>({
// ethereum/beacon-metrics defined
// https://github.com/ethereum/beacon-metrics/pull/13
name: 'gossipsub_topic_msg_recv_counts_total',
help: 'Total count of recv msgs before any validation',
labelNames: ['topic']
}),
msgReceivedTotalBytesCount: register.gauge<{ topic: TopicLabel }>({
// ethereum/beacon-metrics defined
// https://github.com/ethereum/beacon-metrics/pull/13
name: 'gossipsub_topic_msg_recv_bytes_total',
help: 'Total count of recv msgs before any validation',
labelNames: ['topic']
}),
Expand Down Expand Up @@ -848,18 +876,17 @@ export function getMetrics (
this.msgPublishTime.observe({ topic }, ms / 1000)
},

onMsgRecvPreValidation (topicStr: TopicStr): void {
const topic = this.toTopic(topicStr)
this.msgReceivedPreValidation.inc({ topic }, 1)
},

onMsgRecvError (topicStr: TopicStr): void {
const topic = this.toTopic(topicStr)
this.msgReceivedError.inc({ topic }, 1)
},

onPrevalidationResult (topicStr: TopicStr, status: MessageStatus): void {
const topic = this.toTopic(topicStr)
onMsgRecvPreValidation (topic: string, msgSize: number): void {
this.msgReceivedTotalUnfilteredCount.inc({ topic }, 1)
this.msgReceivedTotalBytesUnfilteredCount.inc({ topic }, msgSize)
},

onPrevalidationResult (topic: string, msgSize: number, status: MessageStatus): void {
switch (status) {
case MessageStatus.duplicate:
this.prevalidationDuplicateTotal.inc({ topic })
Expand All @@ -868,7 +895,8 @@ export function getMetrics (
this.prevalidationInvalidTotal.inc({ topic })
break
case MessageStatus.valid:
this.prevalidationValidTotal.inc({ topic })
this.msgReceivedTotalCount.inc({ topic }, 1)
this.msgReceivedTotalBytesCount.inc({ topic }, msgSize)
break
default:
this.prevalidationUnknownTotal.inc({ topic })
Expand Down
Loading