Skip to content

Commit 3a150a7

Browse files
committed
fix(tests, monitoring): fix test scanId extraction and PromQL dashboard bug
The PromQL expression (time() * 1000 - scan_start_time) / 1000 was evaluating to time() when scan_start_time = 0, causing massive spikes. The fix ensures the expression only evaluates when scan_start_time > 0, filtering out idle processors. Issue: BB-740
1 parent 94261db commit 3a150a7

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

monitoring/lifecycle/dashboard.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4647,7 +4647,7 @@
46474647
"targets": [
46484648
{
46494649
"datasource": null,
4650-
"expr": "(time() * 1000 - s3_lifecycle_bucket_processor_scan_start_time{job=\"${job_lifecycle_bucket_processor}\", namespace=\"${namespace}\"}) / 1000 > 0",
4650+
"expr": "(time() * 1000 - s3_lifecycle_bucket_processor_scan_start_time{job=\"${job_lifecycle_bucket_processor}\", namespace=\"${namespace}\"}) / 1000 and s3_lifecycle_bucket_processor_scan_start_time{job=\"${job_lifecycle_bucket_processor}\", namespace=\"${namespace}\"} > 0",
46514651
"format": "time_series",
46524652
"hide": false,
46534653
"instant": false,

monitoring/lifecycle/dashboard.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,9 @@ def color_override(name, color):
815815
Target(
816816
expr='(time() * 1000 - '
817817
+ Metrics.BUCKET_PROCESSOR_SCAN_START_TIME()
818-
+ ') / 1000 > 0',
818+
+ ') / 1000 and '
819+
+ Metrics.BUCKET_PROCESSOR_SCAN_START_TIME()
820+
+ ' > 0',
819821
legendFormat='{{pod}}',
820822
),
821823
],

tests/unit/lifecycle/LifecycleConductor.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,21 +238,35 @@ describe('Lifecycle Conductor', () => {
238238
setData: (path, data, version, cb) => cb(null, { version: 1 }),
239239
};
240240
conductor._producer = { send: (msg, cb) => cb(null, {}) };
241+
const addDefaultFieldsStub = sinon.stub();
242+
const testLog = conductor.logger.newRequestLogger();
243+
testLog.addDefaultFields = addDefaultFieldsStub;
244+
sinon.stub(conductor.logger, 'newRequestLogger').returns(testLog);
241245

242246
sinon.stub(conductor, '_controlBacklog').callsFake(cb => cb(null));
247+
let capturedScanId = null;
243248
sinon.stub(conductor, 'listBuckets')
244249
.callsFake((queue, scanId, log, cb) => {
245250
// Verify scanId is a valid UUID
246251
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
247252
assert(uuidRegex.test(scanId),
248253
`conductorScanId should be a valid UUID v4, got: ${scanId}`);
254+
capturedScanId = scanId;
255+
assert(addDefaultFieldsStub.calledOnce);
256+
assert.strictEqual(addDefaultFieldsStub.firstCall.args[0].conductorScanId, scanId);
249257
cb(null, 0);
250258
});
251259
const metricStub = sinon.stub(LifecycleMetrics, 'onConductorFullScan');
252260

253261
conductor.processBuckets(err => {
254262
assert.ifError(err);
255263
assert(metricStub.calledOnce);
264+
const logPassedToMetric = metricStub.firstCall.args[0];
265+
assert.strictEqual(logPassedToMetric, testLog);
266+
assert(capturedScanId);
267+
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
268+
assert(uuidRegex.test(capturedScanId),
269+
`captured conductorScanId should be a valid UUID v4, got: ${capturedScanId}`);
256270
done();
257271
});
258272
});

0 commit comments

Comments
 (0)