From d20e96880efb00a8417361111347f2294e0a6f9f Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Tue, 29 Aug 2023 13:31:48 -0600 Subject: [PATCH] refactor(metrics): move global bundling metrics into metrics.ts. PE-4401 --- src/metrics.ts | 36 ++++++++++++++++++++++++++++++++++++ src/system.ts | 45 +++++++-------------------------------------- 2 files changed, 43 insertions(+), 38 deletions(-) diff --git a/src/metrics.ts b/src/metrics.ts index d4047446..42195da8 100644 --- a/src/metrics.ts +++ b/src/metrics.ts @@ -31,6 +31,40 @@ export const uncaughtExceptionCounter = new promClient.Counter({ help: 'Count of uncaught exceptions', }); +// +// Global bundle metrics +// + +export const bundlesCounter = new promClient.Counter({ + name: 'bundles_total', + help: 'Count of all bundles seen', + labelNames: ['bundle_format', 'parent_type'], +}); + +export const bundlesMatchedCounter = new promClient.Counter({ + name: 'bundles_matched_total', + help: 'Count of bundles matched for unbundling', + labelNames: ['bundle_format'], +}); + +export const bundlesQueuedCounter = new promClient.Counter({ + name: 'bundles_queued_total', + help: 'Count of bundles queued for unbundling', + labelNames: ['bundle_format'], +}); + +export const bundlesUnbundledCounter = new promClient.Counter({ + name: 'bundles_unbundled_total', + help: 'Count of bundles unbundled', + labelNames: ['bundle_format'], +}); + +export const dataItemsQueuedCounter = new promClient.Counter({ + name: 'data_items_queued_total', + help: 'Count of data items queued for indexing', + labelNames: ['bundle_format'], +}); + // // Arweave client metrics // @@ -48,6 +82,7 @@ export const arweavePeerRefreshErrorCounter = new promClient.Counter({ // // SQLite metrics // + export const methodDurationSummary = new promClient.Summary({ name: 'standalone_sqlite_method_duration_seconds', help: 'Count of failed Arweave peer info requests', @@ -57,6 +92,7 @@ export const methodDurationSummary = new promClient.Summary({ // // Block importer metrics // + export const blockImporterRunningGauge = new promClient.Gauge({ name: 'block_importer_running', help: 'Depth of the last observed chain fork', diff --git a/src/system.ts b/src/system.ts index e7aa7873..f1e12736 100644 --- a/src/system.ts +++ b/src/system.ts @@ -17,7 +17,6 @@ */ import { default as Arweave } from 'arweave'; import EventEmitter from 'node:events'; -import * as promClient from 'prom-client'; import { ArweaveCompositeClient } from './arweave/composite-client.js'; import * as config from './config.js'; @@ -123,17 +122,11 @@ const ans104TxMatcher = new MatchTags([ { name: 'Bundle-Version', valueStartsWith: '2.' }, ]); -const bundlesCounter = new promClient.Counter({ - name: 'bundles_total', - help: 'Count of all bundles seen', - labelNames: ['bundle_format', 'parent_type'], -}); - export const prioritizedTxIds = new Set(); eventEmitter.on(events.TX_INDEXED, async (tx: MatchableItem) => { if (await ans104TxMatcher.match(tx)) { - bundlesCounter.inc({ + metrics.bundlesCounter.inc({ bundle_format: 'ans-104', parent_type: 'transaction', }); @@ -146,7 +139,7 @@ eventEmitter.on( events.ANS104_DATA_ITEM_DATA_INDEXED, async (item: MatchableItem) => { if (await ans104TxMatcher.match(item)) { - bundlesCounter.inc({ + metrics.bundlesCounter.inc({ bundle_format: 'ans-104', parent_type: 'data_item', }); @@ -194,7 +187,7 @@ export const bundleRepairWorker = new BundleRepairWorker({ filtersChanged: config.FILTER_CHANGE_REPROCESS, }); -// Configure contigous data source +// Configure contiguous data source const chunkDataSource = new ReadThroughChunkDataCache({ log, chunkSource: arweaveClient, @@ -230,18 +223,6 @@ const ans104Unbundler = new Ans104Unbundler({ dataItemIndexFilterString: config.ANS104_INDEX_FILTER_STRING, }); -const bundlesMatchedCounter = new promClient.Counter({ - name: 'bundles_matched_total', - help: 'Count of bundles matched for unbundling', - labelNames: ['bundle_format'], -}); - -const bundlesQueuedCounter = new promClient.Counter({ - name: 'bundles_queued_total', - help: 'Count of bundles queued for unbundling', - labelNames: ['bundle_format'], -}); - eventEmitter.on( events.ANS104_BUNDLE_INDEXED, async (item: NormalizedDataItem | PartialJsonTransaction) => { @@ -254,7 +235,7 @@ eventEmitter.on( const prioritized = prioritizedTxIds.has(item.id); prioritizedTxIds.delete(item.id); if (await config.ANS104_UNBUNDLE_FILTER.match(item)) { - bundlesMatchedCounter.inc({ bundle_format: 'ans-104' }); + metrics.bundlesMatchedCounter.inc({ bundle_format: 'ans-104' }); await db.saveBundle({ id: item.id, format: 'ans-104', @@ -272,7 +253,7 @@ eventEmitter.on( }, prioritized, ); - bundlesQueuedCounter.inc({ bundle_format: 'ans-104' }); + metrics.bundlesQueuedCounter.inc({ bundle_format: 'ans-104' }); } else { await db.saveBundle({ id: item.id, @@ -287,15 +268,9 @@ eventEmitter.on( }, ); -const bundlesUnbundledCounter = new promClient.Counter({ - name: 'bundles_unbundled_total', - help: 'Count of bundles unbundled', - labelNames: ['bundle_format'], -}); - eventEmitter.on(events.ANS104_UNBUNDLE_COMPLETE, async (bundleEvent: any) => { try { - bundlesUnbundledCounter.inc({ bundle_format: 'ans-104' }); + metrics.bundlesUnbundledCounter.inc({ bundle_format: 'ans-104' }); db.saveBundle({ id: bundleEvent.parentId, format: 'ans-104', @@ -320,14 +295,8 @@ const ans104DataIndexer = new Ans104DataIndexer({ indexWriter: nestedDataIndexWriter, }); -const dataItemsQueuedCounter = new promClient.Counter({ - name: 'data_items_queued_total', - help: 'Count of data items queued for indexing', - labelNames: ['bundle_format'], -}); - eventEmitter.on(events.ANS104_DATA_ITEM_MATCHED, async (dataItem: any) => { - dataItemsQueuedCounter.inc({ bundle_format: 'ans-104' }); + metrics.dataItemsQueuedCounter.inc({ bundle_format: 'ans-104' }); dataItemIndexer.queueDataItem(dataItem); ans104DataIndexer.queueDataItem(dataItem); });