Skip to content

Commit

Permalink
refactor(metrics): move Arweave client metrics into metrics.ts PE-4401
Browse files Browse the repository at this point in the history
  • Loading branch information
djwhitt committed Aug 18, 2023
1 parent 7c4cddb commit 257f3f8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
25 changes: 3 additions & 22 deletions src/arweave/composite-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import type { queueAsPromised } from 'fastq';
import { default as fastq } from 'fastq';
import { default as NodeCache } from 'node-cache';
import { Readable } from 'node:stream';
import * as promClient from 'prom-client';
import * as rax from 'retry-axios';
import { default as wait } from 'wait';
import * as winston from 'winston';
Expand All @@ -34,6 +33,7 @@ import {
sanityCheckTx,
validateChunk,
} from '../lib/validation.js';
import * as metrics from '../metrics.js';
import {
ChainSource,
Chunk,
Expand Down Expand Up @@ -117,13 +117,8 @@ export class ArweaveCompositeClient
private blockTxPrefetchCount;
private maxPrefetchHeight = -1;

// Metrics
private arweavePeerInfoErrorCounter: promClient.Counter<string>;
private arweavePeerRefreshErrorCounter: promClient.Counter<string>;

constructor({
log,
metricsRegistry,
arweave,
trustedNodeUrl,
blockStore,
Expand All @@ -139,7 +134,6 @@ export class ArweaveCompositeClient
skipCache = false,
}: {
log: winston.Logger;
metricsRegistry: promClient.Registry;
arweave: Arweave;
trustedNodeUrl: string;
blockStore: PartialJsonBlockStore;
Expand Down Expand Up @@ -201,19 +195,6 @@ export class ArweaveCompositeClient
// Initialize prefetch settings
this.blockPrefetchCount = blockPrefetchCount;
this.blockTxPrefetchCount = blockTxPrefetchCount;

// Metrics
this.arweavePeerInfoErrorCounter = new promClient.Counter({
name: 'arweave_peer_info_errors_total',
help: 'Count of failed Arweave peer info requests',
});
metricsRegistry.registerMetric(this.arweavePeerInfoErrorCounter);

this.arweavePeerRefreshErrorCounter = new promClient.Counter({
name: 'arweave_peer_referesh_errors_total',
help: 'Count of errors refreshing the Arweave peers list',
});
metricsRegistry.registerMetric(this.arweavePeerRefreshErrorCounter);
}

async refreshPeers(): Promise<void> {
Expand Down Expand Up @@ -242,13 +223,13 @@ export class ArweaveCompositeClient
this.preferredPeers.add(this.peers[peerHost]);
}
} catch (error) {
this.arweavePeerInfoErrorCounter.inc();
metrics.arweavePeerInfoErrorCounter.inc();
}
return;
}),
);
} catch (error) {
this.arweavePeerRefreshErrorCounter.inc();
metrics.arweavePeerRefreshErrorCounter.inc();
}
}

Expand Down
14 changes: 14 additions & 0 deletions src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,17 @@ export const uncaughtExceptionCounter = new promClient.Counter({
name: 'uncaught_exceptions_total',
help: 'Count of uncaught exceptions',
});

//
// Arweave client metrics
//

export const arweavePeerInfoErrorCounter = new promClient.Counter({
name: 'arweave_peer_info_errors_total',
help: 'Count of failed Arweave peer info requests',
});

export const arweavePeerRefreshErrorCounter = new promClient.Counter({
name: 'arweave_peer_referesh_errors_total',
help: 'Count of errors refreshing the Arweave peers list',
});
1 change: 0 additions & 1 deletion src/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ const arweave = Arweave.init({});

export const arweaveClient = new ArweaveCompositeClient({
log,
metricsRegistry: promClient.register,
arweave,
trustedNodeUrl: config.TRUSTED_NODE_URL,
skipCache: config.SKIP_CACHE,
Expand Down

0 comments on commit 257f3f8

Please sign in to comment.