From 1e44dd52b4fce7e4f4749cd82f398eef8e8c31b5 Mon Sep 17 00:00:00 2001 From: Siegfried Puchbauer Date: Thu, 9 Jan 2020 12:23:36 -0800 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20allow=20for=20not=20coll?= =?UTF-8?q?ecting=20block=20information?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now honoring the configuration to disable block watcher, effectively not monitoring chain data (blocks, tx, event logs). This is useful when using ethlogger to monitor multiple nodes to gather node information, but only capture chain data from one of the nodes. --- src/cliflags.ts | 7 ++++++- src/config.ts | 19 ++++++++++++++++--- src/index.ts | 34 ++++++++++++++++++++-------------- 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/src/cliflags.ts b/src/cliflags.ts index 01d7d38..d4f0646 100644 --- a/src/cliflags.ts +++ b/src/cliflags.ts @@ -33,21 +33,26 @@ export const CLI_FLAGS = { 'collect-blocks': flags.boolean({ allowNo: true, + env: 'COLLECT_BLOCKS', description: - 'Enables ethereum block watcher (enabled by default unless specified otherwise in the config file)', + 'Enables ethereum block watcher, ingesting blocks, transactions, event logs ' + + 'and ABI-decoded information from method calls and event logs', }), 'collect-node-metrics': flags.boolean({ allowNo: true, + env: 'COLLECT_NODE_METRICS', description: 'Enables collection of node metrics (enabled by default unless specified otherwise in the config file)', }), 'collect-node-info': flags.boolean({ allowNo: true, + env: 'COLLECT_NODE_INFO', description: 'Enables collection of node info events (enabled by default unless specified otherwise in the config file)', }), 'collect-internal-metrics': flags.boolean({ allowNo: true, + env: 'COLLECT_INTERNAL_METRICS', description: 'Enables collection of ethlogger-internal metrics (enabled by default unless specified otherwise in the config file)', }), diff --git a/src/config.ts b/src/config.ts index fae3ea2..3e6a4bd 100644 --- a/src/config.ts +++ b/src/config.ts @@ -708,7 +708,11 @@ export async function loadEthloggerConfig(flags: CliFlags, dryRun: boolean = fal fingerprintContracts: defaults.abi?.fingerprintContracts ?? true, }, blockWatcher: { - enabled: flags['collect-blocks'] ?? defaults.blockWatcher?.enabled ?? true, + enabled: + flags['collect-blocks'] ?? + parseBooleanEnvVar(CLI_FLAGS['collect-blocks'].env) ?? + defaults.blockWatcher?.enabled ?? + true, blocksMaxChunkSize: defaults.blockWatcher?.blocksMaxChunkSize ?? 25, pollInterval: parseDuration(defaults.blockWatcher?.pollInterval) ?? 500, startAt: parseStartAt(flags['start-at-block'] ?? defaults.blockWatcher?.startAt) ?? 'genesis', @@ -724,6 +728,7 @@ export async function loadEthloggerConfig(flags: CliFlags, dryRun: boolean = fal internalMetrics: { enabled: flags['collect-internal-metrics'] ?? + parseBooleanEnvVar(CLI_FLAGS['collect-internal-metrics'].env) ?? defaults.internalMetrics?.enabled ?? (() => { if ( @@ -742,12 +747,20 @@ export async function loadEthloggerConfig(flags: CliFlags, dryRun: boolean = fal collectInterval: parseDuration(defaults.internalMetrics?.collectInterval) ?? 1000, }, nodeInfo: { - enabled: flags['collect-node-info'] ?? defaults.nodeInfo?.enabled ?? true, + enabled: + flags['collect-node-info'] ?? + parseBooleanEnvVar(CLI_FLAGS['collect-node-info'].env) ?? + defaults.nodeInfo?.enabled ?? + true, collectInterval: parseDuration(defaults.nodeInfo?.collectInterval) ?? 60000, retryWaitTime: waitTimeFromConfig(defaults.nodeInfo?.retryWaitTime) ?? 60000, }, nodeMetrics: { - enabled: flags['collect-node-metrics'] ?? defaults.nodeMetrics?.enabled ?? true, + enabled: + flags['collect-node-metrics'] ?? + parseBooleanEnvVar(CLI_FLAGS['collect-node-metrics'].env) ?? + defaults.nodeMetrics?.enabled ?? + true, collectInterval: parseDuration(defaults.nodeMetrics?.collectInterval) ?? 60000, retryWaitTime: waitTimeFromConfig(defaults.nodeMetrics?.retryWaitTime) ?? 60000, }, diff --git a/src/index.ts b/src/index.ts index cb892f4..af8b227 100644 --- a/src/index.ts +++ b/src/index.ts @@ -155,24 +155,30 @@ class Ethlogger extends Command { addResource(nodeStatsCollector); internalStatsCollector.addSource(nodeStatsCollector, 'nodeStatsCollector'); - const blockWatcher = new BlockWatcher({ - checkpoints, - ethClient: client, - output, - abiRepo: abiRepo, - startAt: config.blockWatcher.startAt, - contractInfoCache, - chunkSize: config.blockWatcher.blocksMaxChunkSize, - pollInterval: config.blockWatcher.pollInterval, - }); - addResource(blockWatcher); - internalStatsCollector.addSource(blockWatcher, 'blockWatcher'); + let blockWatcher: BlockWatcher | null = null; + + if (config.blockWatcher.enabled) { + blockWatcher = new BlockWatcher({ + checkpoints, + ethClient: client, + output, + abiRepo: abiRepo, + startAt: config.blockWatcher.startAt, + contractInfoCache, + chunkSize: config.blockWatcher.blocksMaxChunkSize, + pollInterval: config.blockWatcher.pollInterval, + }); + addResource(blockWatcher); + internalStatsCollector.addSource(blockWatcher, 'blockWatcher'); + } else { + debug('Block watcher is disabled'); + } internalStatsCollector.start(); return Promise.all( - [blockWatcher.start(), nodeStatsCollector.start()].map(p => - p.catch(e => { + [blockWatcher?.start(), nodeStatsCollector.start()].map(p => + p?.catch(e => { if (e !== ABORT) { error('Error in ethlogger task:', e); return Promise.reject(e);