Skip to content

Commit

Permalink
Add metric for watcher sync mode
Browse files Browse the repository at this point in the history
  • Loading branch information
prathamesh0 committed Dec 18, 2023
1 parent 9775ce6 commit 2e730fd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
8 changes: 7 additions & 1 deletion packages/util/src/job-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
fetchBlocksAtHeight,
fetchAndSaveFilteredLogsAndBlocks
} from './common';
import { lastBlockNumEvents, lastBlockProcessDuration, lastProcessedBlockNumber } from './metrics';
import { isSyncingHistoricalBlocks, lastBlockNumEvents, lastBlockProcessDuration, lastProcessedBlockNumber } from './metrics';

const log = debug('vulcanize:job-runner');

Expand Down Expand Up @@ -116,6 +116,9 @@ export class JobRunner {

switch (kind) {
case JOB_KIND_INDEX: {
// Update metrics
isSyncingHistoricalBlocks.set(0);

const { data: { cid, blockHash, blockNumber, parentHash, timestamp } } = job;

// Check if blockHash present in job.
Expand Down Expand Up @@ -166,6 +169,9 @@ export class JobRunner {
}

async processHistoricalBlocks (job: PgBoss.JobWithDoneCallback<HistoricalJobData, HistoricalJobResponseData>): Promise<void> {
// Update metrics
isSyncingHistoricalBlocks.set(1);

const { data: { blockNumber: startBlock, processingEndBlockNumber } } = job;

if (this._historicalProcessingCompletedUpto) {
Expand Down
10 changes: 8 additions & 2 deletions packages/util/src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ export const eventProcessingEthCallDuration = new client.Histogram({
help: 'Duration of eth_calls made in event processing'
});

export const isSyncingHistoricalBlocks = new client.Gauge({
name: 'is_syncing_historical_blocks',
help: 'Whether the watcher is syncing in historical mode'
});
isSyncingHistoricalBlocks.set(Number(undefined));

// Export metrics on a server
const app: Application = express();

Expand Down Expand Up @@ -189,7 +195,7 @@ const registerUpstreamChainHeadMetrics = async ({ upstream }: Config): Promise<v

const registerWatcherConfigMetrics = async ({ server, upstream, jobQueue }: Config): Promise<void> => {
const watcherConfigMetric = new client.Gauge({
name: 'watcher_config',
name: 'watcher_config_info',
help: 'Watcher configuration info (static)',
labelNames: ['category', 'field']
});
Expand All @@ -208,7 +214,7 @@ const registerWatcherConfigMetrics = async ({ server, upstream, jobQueue }: Conf
watcherConfigMetric.set({ category: 'upstream', field: 'eth_server_filter_logs_by_addresses' }, Number(upstream.ethServer.filterLogsByAddresses));
watcherConfigMetric.set({ category: 'upstream', field: 'eth_server_filter_logs_by_topics' }, Number(upstream.ethServer.filterLogsByTopics));

watcherConfigMetric.set({ category: 'jobqueue', field: 'eventsInBatch' }, Number(jobQueue.eventsInBatch));
watcherConfigMetric.set({ category: 'jobqueue', field: 'events_in_batch' }, Number(jobQueue.eventsInBatch));
watcherConfigMetric.set({ category: 'jobqueue', field: 'block_delay_in_milli_secs' }, Number(jobQueue.blockDelayInMilliSecs));
watcherConfigMetric.set({ category: 'jobqueue', field: 'use_block_ranges' }, Number(jobQueue.useBlockRanges));
watcherConfigMetric.set({ category: 'jobqueue', field: 'historical_logs_block_range' }, Number(jobQueue.historicalLogsBlockRange));
Expand Down

0 comments on commit 2e730fd

Please sign in to comment.