Skip to content

Commit

Permalink
feat: track pruned messages in tracer (#384)
Browse files Browse the repository at this point in the history
* feat: track pruned messages in tracer

* chore: rename to iwantMessagePruned
  • Loading branch information
twoeths authored Dec 14, 2022
1 parent 23d49be commit dbeb879
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,10 @@ export function getMetrics(
name: 'gossipsub_iwant_promise_broken',
help: 'Total count of broken IWANT promises'
}),
iwantMessagePruned: register.gauge({
name: 'gossipsub_iwant_message_pruned',
help: 'Total count of pruned IWANT messages'
}),
/** Histogram of delivery time of resolved IWANT promises */
iwantPromiseDeliveryTime: register.histogram({
name: 'gossipsub_iwant_promise_delivery_seconds',
Expand Down
4 changes: 4 additions & 0 deletions src/tracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,21 @@ export class IWantTracer {

prune(): void {
const maxMs = Date.now() - this.requestMsByMsgExpire
let count = 0

for (const [k, v] of this.requestMsByMsg.entries()) {
if (v < maxMs) {
// messages that stay too long in the requestMsByMsg map, delete
this.requestMsByMsg.delete(k)
count++
} else {
// recent messages, keep them
// sort by insertion order
break
}
}

this.metrics?.iwantMessagePruned.inc(count)
}

private trackMessage(msgIdStr: MsgIdStr): void {
Expand Down

0 comments on commit dbeb879

Please sign in to comment.