Skip to content

Commit

Permalink
Submit new telemetry for block seen (#1005)
Browse files Browse the repository at this point in the history
This submits a new telemetry if the block has been successfully added.
I decided to only submit this telemtry so if invalid blocks are sent,
they aren't added to our data points. We also add data points for forks
and not forks, so that we can measure properly.
  • Loading branch information
NullSoldier committed Feb 15, 2022
1 parent 3ed8630 commit 6ceebdc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
9 changes: 9 additions & 0 deletions ironfish/src/syncer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class Syncer {
readonly chain: Blockchain
readonly strategy: Strategy
readonly metrics: MetricsMonitor
readonly telemetry: Telemetry
readonly logger: Logger
readonly speed: Meter

Expand All @@ -57,6 +58,8 @@ export class Syncer {
this.chain = options.chain
this.strategy = options.strategy
this.logger = logger.withTag('syncer')
this.telemetry = options.telemetry

this.metrics =
options.metrics ||
new MetricsMonitor({ telemetry: options.telemetry, logger: this.logger })
Expand Down Expand Up @@ -484,6 +487,8 @@ export class Syncer {
return false
}

const seenAt = new Date()

const { added, block } = await this.addBlock(peer, newBlock)

if (!peer.sequence || block.header.sequence > peer.sequence) {
Expand All @@ -492,6 +497,10 @@ export class Syncer {

this.onGossip.emit(block)

if (added) {
this.telemetry.submitNewBlockSeen(block, seenAt)
}

return added
}

Expand Down
2 changes: 1 addition & 1 deletion ironfish/src/telemetry/interfaces/metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface Metric {
* A description for the container that the fields measure. Defaults to
* 'node' because all metrics are submitted from an Iron Fish node.
*/
measurement: 'node'
measurement: string

/**
* The name of whatever is being measured.
Expand Down
26 changes: 26 additions & 0 deletions ironfish/src/telemetry/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,30 @@ export class Telemetry {
],
})
}

submitNewBlockSeen(block: Block, seenAt: Date): void {
this.submit({
measurement: 'propagation',
name: 'propagation',
timestamp: seenAt,
tags: [
{
name: 'block_hash',
value: block.header.hash.toString('hex'),
},
],
fields: [
{
name: 'block_timestamp',
type: 'integer',
value: block.header.timestamp.valueOf(),
},
{
name: 'block_sequence',
type: 'integer',
value: block.header.sequence,
},
],
})
}
}

0 comments on commit 6ceebdc

Please sign in to comment.