Skip to content

Commit

Permalink
feat(metrics): add database in-flight operations metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
karlprieb authored and djwhitt committed Oct 7, 2024
1 parent 900e3c4 commit 0c10915
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 22 deletions.
55 changes: 33 additions & 22 deletions src/database/standalone-sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2397,13 +2397,14 @@ const WORKER_POOL_SIZES: WorkerPoolSizes = {

export class StandaloneSqliteDatabase
implements
BundleIndex,
BlockListValidator,
ChainIndex,
ChainOffsetIndex,
ContiguousDataIndex,
GqlQueryable,
NestedDataIndexWriter {
BundleIndex,
BlockListValidator,
ChainIndex,
ChainOffsetIndex,
ContiguousDataIndex,
GqlQueryable,
NestedDataIndexWriter
{
log: winston.Logger;

private workers: {
Expand All @@ -2414,13 +2415,13 @@ export class StandaloneSqliteDatabase
moderation: { read: any[]; write: any[] };
bundles: { read: any[]; write: any[] };
} = {
core: { read: [], write: [] },
data: { read: [], write: [] },
gql: { read: [], write: [] },
debug: { read: [], write: [] },
moderation: { read: [], write: [] },
bundles: { read: [], write: [] },
};
core: { read: [], write: [] },
data: { read: [], write: [] },
gql: { read: [], write: [] },
debug: { read: [], write: [] },
moderation: { read: [], write: [] },
bundles: { read: [], write: [] },
};
private workQueues: {
core: { read: any[]; write: any[] };
data: { read: any[]; write: any[] };
Expand All @@ -2429,13 +2430,13 @@ export class StandaloneSqliteDatabase
moderation: { read: any[]; write: any[] };
bundles: { read: any[]; write: any[] };
} = {
core: { read: [], write: [] },
data: { read: [], write: [] },
gql: { read: [], write: [] },
debug: { read: [], write: [] },
moderation: { read: [], write: [] },
bundles: { read: [], write: [] },
};
core: { read: [], write: [] },
data: { read: [], write: [] },
gql: { read: [], write: [] },
debug: { read: [], write: [] },
moderation: { read: [], write: [] },
bundles: { read: [], write: [] },
};

// Data index circuit breakers
private getDataParentCircuitBreaker: CircuitBreaker<
Expand Down Expand Up @@ -2659,6 +2660,10 @@ export class StandaloneSqliteDatabase
method: WorkerMethodName,
args: any,
): Promise<any> {
metrics.sqliteInFlightOps.inc({
worker: workerName,
role,
});
const end = metrics.sqliteMethodDurationSummary.startTimer({
worker: workerName,
role,
Expand All @@ -2675,7 +2680,13 @@ export class StandaloneSqliteDatabase
});
this.drainQueue();
});
ret.finally(() => end());
ret.finally(() => {
metrics.sqliteInFlightOps.dec({
worker: workerName,
role,
});
end();
});
return ret;
}

Expand Down
6 changes: 6 additions & 0 deletions src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ export const sqliteWalCheckpointPages = new promClient.Gauge({
labelNames: ['db', 'type'],
});

export const sqliteInFlightOps = new promClient.Gauge({
name: 'sqlite_in_flight_ops',
help: 'Number of in-flight SQLite operations',
labelNames: ['worker', 'role'],
});

//
// Block importer metrics
//
Expand Down

0 comments on commit 0c10915

Please sign in to comment.