Skip to content

Commit

Permalink
chore: add idontwants cacheSize metric
Browse files Browse the repository at this point in the history
  • Loading branch information
wemeetagain committed Sep 12, 2024
1 parent ff3c8e5 commit 425b6c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,9 @@ export class GossipSub extends TypedEventEmitter<GossipsubEvents> implements Pub

/**
* Tracks IDONTWANT messages received by peers and the heartbeat they were received in
*
* idontwants are stored for `mcacheLength` heartbeats before being pruned,
* so this map is bounded by peerCount * idontwantMaxMessages * mcacheLength
*/
private readonly idontwants = new Map<PeerIdStr, Map<MsgIdStr, number>>()

Expand Down Expand Up @@ -3176,6 +3179,12 @@ export class GossipSub extends TypedEventEmitter<GossipsubEvents> implements Pub
}
metrics.cacheSize.set({ cache: 'backoff' }, backoffSize)

let idontwantsCount = 0
for (const idontwant of this.idontwants.values()) {
idontwantsCount += idontwant.size
}
metrics.cacheSize.set({ cache: 'idontwants' }, idontwantsCount)

// Peer counts

for (const [topicStr, peers] of this.topics) {
Expand Down
4 changes: 2 additions & 2 deletions src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -598,10 +598,10 @@ export function getMetrics (
name: 'gossipsub_idontwant_rcv_msgids_total',
help: 'Total received IDONTWANT messages'
}),
/** Total requested messageIDs that we don't have */
/** Total received IDONTWANT messageIDs that we don't have */
idontwantRcvDonthaveMsgids: register.gauge({
name: 'gossipsub_idontwant_rcv_dont_have_msgids_total',
help: 'Total requested IDONTWANT messageIDs that we do not have in mcache'
help: 'Total received IDONTWANT messageIDs that we do not have in mcache'
}),
iwantPromiseStarted: register.gauge({
name: 'gossipsub_iwant_promise_sent_total',
Expand Down

0 comments on commit 425b6c3

Please sign in to comment.