From 425b6c370b3889c27fe77c80fa2a3312a9cc07d6 Mon Sep 17 00:00:00 2001 From: Cayman Date: Thu, 12 Sep 2024 16:58:05 -0400 Subject: [PATCH] chore: add idontwants cacheSize metric --- src/index.ts | 9 +++++++++ src/metrics.ts | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 1302ec99..d9b0445b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -430,6 +430,9 @@ export class GossipSub extends TypedEventEmitter 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>() @@ -3176,6 +3179,12 @@ export class GossipSub extends TypedEventEmitter 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) { diff --git a/src/metrics.ts b/src/metrics.ts index 4353b516..d6040755 100644 --- a/src/metrics.ts +++ b/src/metrics.ts @@ -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',