Skip to content

Commit 30e45bd

Browse files
committed
feat: track lmdb stats
1 parent 39f2508 commit 30e45bd

File tree

10 files changed

+65
-33
lines changed

10 files changed

+65
-33
lines changed

yarn-project/archiver/src/archiver/archiver.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export class Archiver implements ArchiveSource {
176176
config.l1Contracts.registryAddress,
177177
archiverStore,
178178
config.archiverPollingIntervalMS ?? 10_000,
179-
new ArchiverInstrumentation(telemetry),
179+
new ArchiverInstrumentation(telemetry, () => archiverStore.estimateSize()),
180180
{ l1StartBlock, l1GenesisTime, epochDuration, slotDuration, ethereumSlotDuration },
181181
);
182182
await archiver.start(blockUntilSynced);
@@ -271,9 +271,6 @@ export class Archiver implements ArchiveSource {
271271
// the chain locally before we start unwinding stuff. This can be optimized by figuring out
272272
// up to which point we're pruning, and then requesting L2 blocks up to that point only.
273273
await this.handleEpochPrune(provenBlockNumber, currentL1BlockNumber);
274-
275-
const storeSizes = this.store.estimateSize();
276-
this.instrumentation.recordDBMetrics(storeSizes);
277274
}
278275
}
279276

yarn-project/archiver/src/archiver/instrumentation.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
type Gauge,
66
type Histogram,
77
LmdbMetrics,
8+
LmdbStatsCallback,
89
Metrics,
910
type TelemetryClient,
1011
type UpDownCounter,
@@ -23,7 +24,7 @@ export class ArchiverInstrumentation {
2324

2425
private log = createDebugLogger('aztec:archiver:instrumentation');
2526

26-
constructor(private telemetry: TelemetryClient) {
27+
constructor(private telemetry: TelemetryClient, lmdbStats?: LmdbStatsCallback) {
2728
const meter = telemetry.getMeter('Archiver');
2829
this.blockHeight = meter.createGauge(Metrics.ARCHIVER_BLOCK_HEIGHT, {
2930
description: 'The height of the latest block processed by the archiver',
@@ -72,13 +73,10 @@ export class ArchiverInstrumentation {
7273
name: Metrics.ARCHIVER_DB_NUM_ITEMS,
7374
description: 'Num items in the archiver database',
7475
},
76+
lmdbStats,
7577
);
7678
}
7779

78-
public recordDBMetrics(metrics: { mappingSize: number; numItems: number; actualSize: number }) {
79-
this.dbMetrics.recordDBMetrics(metrics);
80-
}
81-
8280
public isEnabled(): boolean {
8381
return this.telemetry.isEnabled();
8482
}

yarn-project/p2p/src/mem_pools/instrumentation.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
Attributes,
44
type Histogram,
55
LmdbMetrics,
6+
LmdbStatsCallback,
67
Metrics,
78
type TelemetryClient,
89
type UpDownCounter,
@@ -58,7 +59,7 @@ export class PoolInstrumentation<PoolObject extends Gossipable> {
5859

5960
private defaultAttributes;
6061

61-
constructor(telemetry: TelemetryClient, name: PoolName) {
62+
constructor(telemetry: TelemetryClient, name: PoolName, dbStats?: LmdbStatsCallback) {
6263
const meter = telemetry.getMeter(name);
6364
this.defaultAttributes = { [Attributes.POOL_NAME]: name };
6465

@@ -98,13 +99,10 @@ export class PoolInstrumentation<PoolObject extends Gossipable> {
9899
name: Metrics.MEMPOOL_DB_NUM_ITEMS,
99100
description: 'Num items in database for the Tx mempool',
100101
},
102+
dbStats,
101103
);
102104
}
103105

104-
public recordDBMetrics(metrics: { mappingSize: number; numItems: number; actualSize: number }) {
105-
this.dbMetrics.recordDBMetrics(metrics);
106-
}
107-
108106
public recordSize(poolObject: PoolObject) {
109107
this.objectSize.record(poolObject.getSize());
110108
}

yarn-project/p2p/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class AztecKVTxPool implements TxPool {
3737

3838
this.#store = store;
3939
this.#log = log;
40-
this.#metrics = new PoolInstrumentation(telemetry, PoolName.TX_POOL);
40+
this.#metrics = new PoolInstrumentation(telemetry, PoolName.TX_POOL, () => store.estimateSize());
4141
}
4242

4343
public markAsMined(txHashes: TxHash[], blockNumber: number): Promise<void> {
@@ -53,8 +53,6 @@ export class AztecKVTxPool implements TxPool {
5353
}
5454
this.#metrics.recordRemovedObjects(deleted, 'pending');
5555
this.#metrics.recordAddedObjects(txHashes.length, 'mined');
56-
const storeSizes = this.#store.estimateSize();
57-
this.#metrics.recordDBMetrics(storeSizes);
5856
});
5957
}
6058

yarn-project/prover-client/src/proving_broker/factory.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export async function createAndStartProvingBroker(
1111
client: TelemetryClient,
1212
): Promise<ProvingBroker> {
1313
const database = config.proverBrokerDataDirectory
14-
? new KVBrokerDatabase(AztecLmdbStore.open(config.proverBrokerDataDirectory))
14+
? new KVBrokerDatabase(AztecLmdbStore.open(config.proverBrokerDataDirectory), client)
1515
: new InMemoryBrokerDatabase();
1616

1717
const broker = new ProvingBroker(database, client, {

yarn-project/prover-client/src/proving_broker/proving_broker.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe.each([
1818
() => ({ database: new InMemoryBrokerDatabase(), cleanup: undefined }),
1919
() => {
2020
const store = openTmpStore(true);
21-
const database = new KVBrokerDatabase(store);
21+
const database = new KVBrokerDatabase(store, new NoopTelemetryClient());
2222
const cleanup = () => store.close();
2323
return { database, cleanup };
2424
},

yarn-project/prover-client/src/proving_broker/proving_broker_database/persisted.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
import { type ProofUri, ProvingJob, type ProvingJobId, ProvingJobSettledResult } from '@aztec/circuit-types';
22
import { jsonParseWithSchema, jsonStringify } from '@aztec/foundation/json-rpc';
33
import { type AztecKVStore, type AztecMap } from '@aztec/kv-store';
4+
import { LmdbMetrics, Metrics, TelemetryClient } from '@aztec/telemetry-client';
45

56
import { type ProvingBrokerDatabase } from '../proving_broker_database.js';
67

78
export class KVBrokerDatabase implements ProvingBrokerDatabase {
89
private jobs: AztecMap<ProvingJobId, string>;
910
private jobResults: AztecMap<ProvingJobId, string>;
10-
11-
constructor(private store: AztecKVStore) {
11+
private metrics: LmdbMetrics;
12+
13+
constructor(private store: AztecKVStore, client: TelemetryClient) {
14+
this.metrics = new LmdbMetrics(
15+
client.getMeter('KVBrokerDatabase'),
16+
{
17+
name: Metrics.PROVING_QUEUE_DB_MAP_SIZE,
18+
description: 'Database map size for the proving broker',
19+
},
20+
{
21+
name: Metrics.PROVING_QUEUE_DB_USED_SIZE,
22+
description: 'Database used size for the proving broker',
23+
},
24+
{ name: Metrics.PROVING_QUEUE_DB_NUM_ITEMS, description: 'Number of items in the broker database' },
25+
() => store.estimateSize(),
26+
);
1227
this.jobs = store.openMap('proving_jobs');
1328
this.jobResults = store.openMap('proving_job_results');
1429
}
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,47 @@
1-
import { type Gauge, type Meter, type Metrics, ValueType } from './telemetry.js';
1+
import { BatchObservableResult, type Meter, type Metrics, ObservableGauge, ValueType } from './telemetry.js';
22

33
export type LmdbMetricDescriptor = {
44
name: Metrics;
55
description: string;
66
};
77

8+
export type LmdbStatsCallback = () => { mappingSize: number; numItems: number; actualSize: number };
9+
810
export class LmdbMetrics {
9-
private dbMapSize: Gauge;
10-
private dbUsedSize: Gauge;
11-
private dbNumItems: Gauge;
11+
private dbMapSize: ObservableGauge;
12+
private dbUsedSize: ObservableGauge;
13+
private dbNumItems: ObservableGauge;
1214

1315
constructor(
1416
meter: Meter,
1517
dbMapSizeDescriptor: LmdbMetricDescriptor,
1618
dbUsedSizeDescriptor: LmdbMetricDescriptor,
1719
dbNumItemsDescriptor: LmdbMetricDescriptor,
20+
private getStats?: LmdbStatsCallback,
1821
) {
19-
this.dbMapSize = meter.createGauge(dbMapSizeDescriptor.name, {
22+
this.dbMapSize = meter.createObservableGauge(dbMapSizeDescriptor.name, {
2023
description: dbMapSizeDescriptor.description,
2124
valueType: ValueType.INT,
2225
});
23-
this.dbUsedSize = meter.createGauge(dbUsedSizeDescriptor.name, {
26+
this.dbUsedSize = meter.createObservableGauge(dbUsedSizeDescriptor.name, {
2427
description: dbUsedSizeDescriptor.description,
2528
valueType: ValueType.INT,
2629
});
27-
this.dbNumItems = meter.createGauge(dbNumItemsDescriptor.name, {
30+
this.dbNumItems = meter.createObservableGauge(dbNumItemsDescriptor.name, {
2831
description: dbNumItemsDescriptor.description,
2932
valueType: ValueType.INT,
3033
});
31-
}
3234

33-
public recordDBMetrics(metrics: { mappingSize: number; numItems: number; actualSize: number }) {
34-
this.dbMapSize.record(metrics.mappingSize);
35-
this.dbNumItems.record(metrics.actualSize);
36-
this.dbUsedSize.record(metrics.actualSize);
35+
meter.addBatchObservableCallback(this.recordDBMetrics, [this.dbMapSize, this.dbUsedSize, this.dbNumItems]);
3736
}
37+
38+
private recordDBMetrics = (observable: BatchObservableResult) => {
39+
if (!this.getStats) {
40+
return;
41+
}
42+
const metrics = this.getStats();
43+
observable.observe(this.dbMapSize, metrics.mappingSize);
44+
observable.observe(this.dbNumItems, metrics.numItems);
45+
observable.observe(this.dbUsedSize, metrics.actualSize);
46+
};
3847
}

yarn-project/telemetry-client/src/metrics.ts

+3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ export const PROVING_QUEUE_RETRIED_JOBS = 'aztec.proving_queue.retried_jobs';
8686
export const PROVING_QUEUE_TIMED_OUT_JOBS = 'aztec.proving_queue.timed_out_jobs';
8787
export const PROVING_QUEUE_JOB_WAIT = 'aztec.proving_queue.job_wait';
8888
export const PROVING_QUEUE_JOB_DURATION = 'aztec.proving_queue.job_duration';
89+
export const PROVING_QUEUE_DB_NUM_ITEMS = 'aztec.proving_queue.db.num_items';
90+
export const PROVING_QUEUE_DB_MAP_SIZE = 'aztec.proving_queue.db.map_size';
91+
export const PROVING_QUEUE_DB_USED_SIZE = 'aztec.proving_queue.db.used_size';
8992

9093
export const PROVING_AGENT_IDLE = 'aztec.proving_queue.agent.idle';
9194

yarn-project/telemetry-client/src/telemetry.ts

+14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import {
22
type AttributeValue,
3+
BatchObservableCallback,
34
type MetricOptions,
5+
Observable,
6+
type BatchObservableResult as OtelBatchObservableResult,
47
type Gauge as OtelGauge,
58
type Histogram as OtelHistogram,
69
type ObservableGauge as OtelObservableGauge,
@@ -33,6 +36,7 @@ export type UpDownCounter = OtelUpDownCounter<Attributes>;
3336
export type ObservableGauge = OtelObservableGauge<Attributes>;
3437
export type ObservableUpDownCounter = OtelObservableUpDownCounter<Attributes>;
3538
export type ObservableResult = OtelObservableResult<Attributes>;
39+
export type BatchObservableResult = OtelBatchObservableResult<Attributes>;
3640

3741
export { Tracer };
3842

@@ -55,6 +59,16 @@ export interface Meter {
5559
*/
5660
createObservableGauge(name: Metrics, options?: MetricOptions): ObservableGauge;
5761

62+
addBatchObservableCallback(
63+
callback: BatchObservableCallback<Attributes>,
64+
observables: Observable<Attributes>[],
65+
): void;
66+
67+
removeBatchObservableCallback(
68+
callback: BatchObservableCallback<Attributes>,
69+
observables: Observable<Attributes>[],
70+
): void;
71+
5872
/**
5973
* Creates a new histogram instrument. A histogram is a metric that samples observations (usually things like request durations or response sizes) and counts them in configurable buckets.
6074
* @param name - The name of the histogram

0 commit comments

Comments
 (0)