From 094b51c921935a4def339cbd48b61b2f8cf40a3d Mon Sep 17 00:00:00 2001 From: Maha Benzekri Date: Wed, 15 May 2024 17:29:37 +0200 Subject: [PATCH] fixups post reviews --- CountItems/CountMaster.js | 2 -- CountItems/CountWorker.js | 2 +- CountItems/masterProcess.js | 15 +++++++++------ utils/monitoring.js | 6 +++--- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/CountItems/CountMaster.js b/CountItems/CountMaster.js index e7ec5582..875a5832 100644 --- a/CountItems/CountMaster.js +++ b/CountItems/CountMaster.js @@ -6,7 +6,6 @@ class CountMaster { this.log = params.log; this.manager = params.manager; this.client = params.client; - CountMaster.waitingForPromScraping = false; } stop(signal, callback) { @@ -59,7 +58,6 @@ class CountMaster { }); return this.stop(null, () => callback(err)); } - CountMaster.waitingForPromScraping = true; return callback(); }); } diff --git a/CountItems/CountWorker.js b/CountItems/CountWorker.js index 41700392..b3093ff4 100644 --- a/CountItems/CountWorker.js +++ b/CountItems/CountWorker.js @@ -37,7 +37,7 @@ class CountWorker { next => this.client._getIsTransient(bucketInfo, this.log, next), (isTransient, next) => this.client.getObjectMDStats(bucketName, bucketInfo, isTransient, this.log, next), ], (err, results) => { - monitoring.workersCount.inc({ state: err ? 'error' : 'success' }); + monitoring.bucketsCount.inc({ status: err ? 'error' : 'success' }); callback(err, results); }); } diff --git a/CountItems/masterProcess.js b/CountItems/masterProcess.js index 2b7079f8..f5272b7d 100644 --- a/CountItems/masterProcess.js +++ b/CountItems/masterProcess.js @@ -19,15 +19,17 @@ const loggerConfig = { dump: 'error', }; +let waitingForPromScraping = false; + werelogs.configure(loggerConfig); const log = new werelogs.Logger('S3Utils::CountItems::Master'); -const prometheusPollingFrequency = process.env.PROMETHEUS_POLLING_FREQUENCY && !Number.isNaN(process.env.PROMETHEUS_POLLING_FREQUENCY) - ? Number.parseInt(process.env.PROMETHEUS_POLLING_FREQUENCY, 10) +const prometheusPollingPeriod = Number.parseInt(process.env.PROMETHEUS_POLLING_PERIOD, 10) > 0 + ? Number.parseInt(process.env.PROMETHEUS_POLLING_PERIOD, 10) : 30; -const promtheusPollingThreshold = process.env.PROMETHEUS_POLLING_THRESHOLD && !Number.isNaN(process.env.PROMETHEUS_POLLING_THRESHOLD) - ? Number.parseInt(process.env.PROMETHEUS_POLLING_THRESHOLD, 10) +const promtheusPollingAttempts = Number.parseInt(process.env.PROMETHEUS_POLLING_ATTEMPTS, 10) > 0 + ? Number.parseInt(process.env.PROMETHEUS_POLLING_ATTEMPTS, 10) : 5; const numWorkers = process.env.NUM_WORKERS && !Number.isNaN(process.env.NUM_WORKERS) @@ -51,7 +53,7 @@ const countMaster = new CountMaster({ const metricServer = new WebServer(8003, log).onRequest((req, res) => monitoring.metricsHandler( () => { - if (CountMaster.waitingForPromScraping === true) { + if (waitingForPromScraping === true) { countMaster.stop(null, () => process.exit(1)); } }, @@ -76,7 +78,8 @@ countMaster.start(err => { if (err) { process.exit(1); } + waitingForPromScraping = true; setTimeout(() => { countMaster.stop(null, () => process.exit(0)); - }, promtheusPollingThreshold * prometheusPollingFrequency * 1000 * 4); + }, promtheusPollingAttempts * prometheusPollingPeriod * 1000 * 4); }); diff --git a/utils/monitoring.js b/utils/monitoring.js index f3559b00..b08360b0 100644 --- a/utils/monitoring.js +++ b/utils/monitoring.js @@ -21,10 +21,10 @@ const consolidationDuration = new promClient.Histogram({ buckets: [0.01, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10], }); -const workersCount = new promClient.Counter({ +const bucketsCount = new promClient.Counter({ name: 's3_countitems_total_buckets_count', help: 'Buckets processed by workers state', - labelNames: ['state'], + labelNames: ['status'], }); const objectsCount = new promClient.Counter({ @@ -83,6 +83,6 @@ module.exports = { metricsHandler, bucketProcessingDuration, consolidationDuration, - workersCount, + bucketsCount, objectsCount, };