Skip to content

Commit

Permalink
refactor(metrics): move SQLite metrics into metrics.ts. PE-4401
Browse files Browse the repository at this point in the history
  • Loading branch information
dtfiedler committed Aug 29, 2023
1 parent 257f3f8 commit 2a777a4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
15 changes: 2 additions & 13 deletions src/database/standalone-sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
parentPort,
workerData,
} from 'node:worker_threads';
import * as promClient from 'prom-client';
import * as R from 'ramda';
import sql from 'sql-bricks';
import * as winston from 'winston';
Expand All @@ -45,6 +44,7 @@ import {
import { MANIFEST_CONTENT_TYPE } from '../lib/encoding.js';
import { currentUnixTimestamp } from '../lib/time.js';
import log from '../log.js';
import * as metrics from '../metrics.js';
import {
BlockListValidator,
BundleIndex,
Expand Down Expand Up @@ -2152,7 +2152,6 @@ export class StandaloneSqliteDatabase
NestedDataIndexWriter
{
log: winston.Logger;
methodDurationSummary: promClient.Summary<string>;
private workers: {
core: { read: any[]; write: any[] };
data: { read: any[]; write: any[] };
Expand Down Expand Up @@ -2185,29 +2184,19 @@ export class StandaloneSqliteDatabase
};
constructor({
log,
metricsRegistry,
coreDbPath,
dataDbPath,
moderationDbPath,
bundlesDbPath,
}: {
log: winston.Logger;
metricsRegistry: promClient.Registry;
coreDbPath: string;
dataDbPath: string;
moderationDbPath: string;
bundlesDbPath: string;
}) {
this.log = log.child({ class: 'StandaloneSqliteDatabase' });

// Metrics
this.methodDurationSummary = new promClient.Summary({
name: 'standalone_sqlite_method_duration_seconds',
help: 'Count of failed Arweave peer info requests',
labelNames: ['worker', 'role', 'method'],
});
metricsRegistry.registerMetric(this.methodDurationSummary);

const self = this;

function spawn(pool: WorkerPoolName, role: WorkerRoleName) {
Expand Down Expand Up @@ -2314,7 +2303,7 @@ export class StandaloneSqliteDatabase
method: string,
args: any,
): Promise<any> {
const end = this.methodDurationSummary.startTimer({
const end = metrics.methodDurationSummary.startTimer({
worker: workerName,
role,
method,
Expand Down
9 changes: 9 additions & 0 deletions src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,12 @@ export const arweavePeerRefreshErrorCounter = new promClient.Counter({
name: 'arweave_peer_referesh_errors_total',
help: 'Count of errors refreshing the Arweave peers list',
});

//
// SQLite metrics
//
export const methodDurationSummary = new promClient.Summary({
name: 'standalone_sqlite_method_duration_seconds',
help: 'Count of failed Arweave peer info requests',
labelNames: ['worker', 'role', 'method'],
});

0 comments on commit 2a777a4

Please sign in to comment.