Skip to content

Commit e909f9e

Browse files
committed
fixup! Refactor: pass scanId as parameter instead of instance field and fix metric timing
fix(tests): update tests to reflect messageId removal and scanId parameter changes
1 parent 8fd23a2 commit e909f9e

File tree

4 files changed

+31
-38
lines changed

4 files changed

+31
-38
lines changed

extensions/lifecycle/bucketProcessor/LifecycleBucketProcessor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ class LifecycleBucketProcessor {
386386
value: result,
387387
s3target: s3Client,
388388
backbeatMetadataProxy,
389-
}, (err) => {
389+
}, err => {
390390
// Increment metric after task successfully completes
391391
// This ensures we count actual processing completion, not just dispatch
392392
// Only count successful completions, not failures

tests/functional/lifecycle/LifecycleConductor.spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ const expected2Messages = (version='v2') => ([
4141
{
4242
value: {
4343
action: 'processObjects',
44-
contextInfo: { reqId: 'test-request-id', conductorScanId: 'test-scan-id', messageId: 'test-message-id' },
44+
contextInfo: { reqId: 'test-request-id', conductorScanId: 'test-scan-id' },
4545
target: { bucket: 'bucket1', owner: 'owner1', taskVersion: version },
4646
details: {},
4747
},
4848
},
4949
{
5050
value: {
5151
action: 'processObjects',
52-
contextInfo: { reqId: 'test-request-id', conductorScanId: 'test-scan-id', messageId: 'test-message-id' },
52+
contextInfo: { reqId: 'test-request-id', conductorScanId: 'test-scan-id' },
5353
target: { bucket: 'bucket1-2', owner: 'owner1', taskVersion: version },
5454
details: {},
5555
},
@@ -60,31 +60,31 @@ const expected4Messages = (version='v2') => ([
6060
{
6161
value: {
6262
action: 'processObjects',
63-
contextInfo: { reqId: 'test-request-id', conductorScanId: 'test-scan-id', messageId: 'test-message-id' },
63+
contextInfo: { reqId: 'test-request-id', conductorScanId: 'test-scan-id' },
6464
target: { bucket: 'bucket1', owner: 'owner1', taskVersion: version },
6565
details: {},
6666
},
6767
},
6868
{
6969
value: {
7070
action: 'processObjects',
71-
contextInfo: { reqId: 'test-request-id', conductorScanId: 'test-scan-id', messageId: 'test-message-id' },
71+
contextInfo: { reqId: 'test-request-id', conductorScanId: 'test-scan-id' },
7272
target: { bucket: 'bucket1-2', owner: 'owner1', taskVersion: version },
7373
details: {},
7474
},
7575
},
7676
{
7777
value: {
7878
action: 'processObjects',
79-
contextInfo: { reqId: 'test-request-id', conductorScanId: 'test-scan-id', messageId: 'test-message-id' },
79+
contextInfo: { reqId: 'test-request-id', conductorScanId: 'test-scan-id' },
8080
target: { bucket: 'bucket3', owner: 'owner3', taskVersion: version },
8181
details: {},
8282
},
8383
},
8484
{
8585
value: {
8686
action: 'processObjects',
87-
contextInfo: { reqId: 'test-request-id', conductorScanId: 'test-scan-id', messageId: 'test-message-id' },
87+
contextInfo: { reqId: 'test-request-id', conductorScanId: 'test-scan-id' },
8888
target: { bucket: 'bucket4', owner: 'owner4', taskVersion: version },
8989
details: {},
9090
},

tests/unit/lifecycle/LifecycleConductor.spec.js

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,18 @@ describe('Lifecycle Conductor', () => {
239239
};
240240

241241
sinon.stub(conductor, '_controlBacklog').callsFake(cb => cb(null));
242+
const metricStub = sinon.stub(LifecycleMetrics, 'onConductorFullScan');
242243

243244
conductor.processBuckets(err => {
244245
assert.ifError(err);
245-
assert(conductor._scanId);
246-
assert(typeof conductor._scanId === 'string');
246+
assert(metricStub.calledOnce);
247+
const scanId = metricStub.firstCall.args[0];
248+
assert(scanId);
249+
assert(typeof scanId === 'string');
247250
// Validate UUID v4 format: 8-4-4-4-12 hex characters
248251
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;
249-
assert(uuidRegex.test(conductor._scanId),
250-
`conductorScanId should be a valid UUID v4, got: ${conductor._scanId}`);
252+
assert(uuidRegex.test(scanId),
253+
`conductorScanId should be a valid UUID v4, got: ${scanId}`);
251254
done();
252255
});
253256
});
@@ -264,7 +267,7 @@ describe('Lifecycle Conductor', () => {
264267
sinon.stub(conductor._mongodbClient, 'getIndexingJobs')
265268
.callsFake((_, cb) => cb(null, ['job1', 'job2']));
266269
sinon.stub(conductor, 'listBuckets')
267-
.callsFake((mQueue, log, cb) => {
270+
.callsFake((mQueue, scanId, log, cb) => {
268271
mQueue.push({
269272
bucketName: 'testbucket',
270273
canonicalId: 'testId',
@@ -281,7 +284,7 @@ describe('Lifecycle Conductor', () => {
281284
setTimeout(() => cb(null, []), 1000);
282285
});
283286
sinon.stub(conductor, '_createBucketTaskMessages')
284-
.callsFake((_a, _b, cb) => {
287+
.callsFake((_a, _b, _c, cb) => {
285288
order.push(2);
286289
assert(conductor.activeIndexingJobsRetrieved);
287290
setTimeout(() => cb(null, []), 1000);
@@ -307,9 +310,7 @@ describe('Lifecycle Conductor', () => {
307310

308311
describe('_indexesGetOrCreate', () => {
309312
it('should include conductor scan id in task context', () => {
310-
conductor._scanId = 'scan-id-test';
311-
312-
const taskMessage = conductor._taskToMessage(getTask(true), lifecycleTaskVersions.v2, log);
313+
const taskMessage = conductor._taskToMessage(getTask(true), lifecycleTaskVersions.v2, 'scan-id-test', log);
313314
const parsed = JSON.parse(taskMessage.message);
314315
assert.strictEqual(parsed.contextInfo.conductorScanId, 'scan-id-test');
315316
});
@@ -505,7 +506,7 @@ describe('Lifecycle Conductor', () => {
505506
const lcConductor = makeLifecycleConductorWithFilters({
506507
bucketSource: 'zookeeper',
507508
});
508-
lcConductor.listBuckets(queue, fakeLogger, (err, length) => {
509+
lcConductor.listBuckets(queue, 'test-scan-id', fakeLogger, (err, length) => {
509510
assert.strictEqual(length, 2);
510511
assert.strictEqual(queue.length(), 2);
511512
const expectedQueue = [
@@ -528,7 +529,7 @@ describe('Lifecycle Conductor', () => {
528529
const lcConductor = makeLifecycleConductorWithFilters({
529530
bucketSource: 'bucketd',
530531
}, markers);
531-
lcConductor.listBuckets(queue, fakeLogger, (err, length) => {
532+
lcConductor.listBuckets(queue, 'test-scan-id', fakeLogger, (err, length) => {
532533
assert.strictEqual(length, 2);
533534
assert.strictEqual(queue.length(), 2);
534535

@@ -559,7 +560,7 @@ describe('Lifecycle Conductor', () => {
559560
'invalid:bucketuid789',
560561
'invalid',
561562
]);
562-
lcConductor.listBuckets(queue, fakeLogger, (err, length) => {
563+
lcConductor.listBuckets(queue, 'test-scan-id', fakeLogger, (err, length) => {
563564
assert.strictEqual(length, 2);
564565
assert.strictEqual(queue.length(), 2);
565566
const expectedQueue = [
@@ -582,7 +583,7 @@ describe('Lifecycle Conductor', () => {
582583
bucketsDenied: [bucket1],
583584
bucketSource: 'zookeeper',
584585
});
585-
lcConductor.listBuckets(queue, fakeLogger, (err, length) => {
586+
lcConductor.listBuckets(queue, 'test-scan-id', fakeLogger, (err, length) => {
586587
assert.strictEqual(length, 1);
587588
assert.strictEqual(queue.length(), 1);
588589
const expectedQueue = [
@@ -602,7 +603,7 @@ describe('Lifecycle Conductor', () => {
602603
bucketsDenied: [bucket1],
603604
bucketSource: 'bucketd',
604605
}, markers);
605-
lcConductor.listBuckets(queue, fakeLogger, (err, length) => {
606+
lcConductor.listBuckets(queue, 'test-scan-id', fakeLogger, (err, length) => {
606607
assert.strictEqual(length, 1);
607608
assert.strictEqual(queue.length(), 1);
608609
const expectedQueue = [
@@ -623,7 +624,7 @@ describe('Lifecycle Conductor', () => {
623624
accountsDenied: [`${accountName1}:${account1}`],
624625
bucketSource: 'zookeeper',
625626
});
626-
lcConductor.listBuckets(queue, fakeLogger, (err, length) => {
627+
lcConductor.listBuckets(queue, 'test-scan-id', fakeLogger, (err, length) => {
627628
assert.strictEqual(length, 1);
628629
assert.strictEqual(queue.length(), 1);
629630
const expectedQueue = [
@@ -643,7 +644,7 @@ describe('Lifecycle Conductor', () => {
643644
accountsDenied: [`${accountName1}:${account1}`],
644645
bucketSource: 'bucketd',
645646
}, markers);
646-
lcConductor.listBuckets(queue, fakeLogger, (err, length) => {
647+
lcConductor.listBuckets(queue, 'test-scan-id', fakeLogger, (err, length) => {
647648
assert.strictEqual(length, 1);
648649
assert.strictEqual(queue.length(), 1);
649650
const expectedQueue = [
@@ -665,7 +666,7 @@ describe('Lifecycle Conductor', () => {
665666
bucketsDenied: [bucket2],
666667
bucketSource: 'zookeeper',
667668
});
668-
lcConductor.listBuckets(queue, fakeLogger, (err, length) => {
669+
lcConductor.listBuckets(queue, 'test-scan-id', fakeLogger, (err, length) => {
669670
assert.strictEqual(length, 0);
670671
assert.strictEqual(queue.length(), 0);
671672
const expectedQueue = [];
@@ -681,7 +682,7 @@ describe('Lifecycle Conductor', () => {
681682
bucketsDenied: [bucket2],
682683
bucketSource: 'bucketd',
683684
}, markers);
684-
lcConductor.listBuckets(queue, fakeLogger, (err, length) => {
685+
lcConductor.listBuckets(queue, 'test-scan-id', fakeLogger, (err, length) => {
685686
assert.strictEqual(length, 0);
686687
assert.strictEqual(queue.length(), 0);
687688
const expectedQueue = [];
@@ -706,7 +707,7 @@ describe('Lifecycle Conductor', () => {
706707
getCollection: () => ({ find: findStub })
707708
};
708709
sinon.stub(lcConductor._zkClient, 'getData').yields(null, null, null);
709-
lcConductor.listBuckets(queue, fakeLogger, err => {
710+
lcConductor.listBuckets(queue, 'test-scan-id', fakeLogger, err => {
710711
assert.ifError(err);
711712
assert.deepEqual(findStub.getCall(0).args[0], {});
712713
done();
@@ -728,7 +729,7 @@ describe('Lifecycle Conductor', () => {
728729
getCollection: () => ({ find: findStub })
729730
};
730731
sinon.stub(lcConductor._zkClient, 'getData').yields(null, null, null);
731-
lcConductor.listBuckets(queue, fakeLogger, err => {
732+
lcConductor.listBuckets(queue, 'test-scan-id', fakeLogger, err => {
732733
assert.ifError(err);
733734
assert.deepEqual(findStub.getCall(0).args[0], {
734735
'value.owner': {
@@ -756,7 +757,7 @@ describe('Lifecycle Conductor', () => {
756757
getCollection: () => ({ find: findStub })
757758
};
758759
sinon.stub(lcConductor._zkClient, 'getData').yields(null, null, null);
759-
lcConductor.listBuckets(queue, fakeLogger, err => {
760+
lcConductor.listBuckets(queue, 'test-scan-id', fakeLogger, err => {
760761
assert.ifError(err);
761762
assert.deepEqual(findStub.getCall(0).args[0], {
762763
_id: {
@@ -781,7 +782,7 @@ describe('Lifecycle Conductor', () => {
781782
getCollection: () => ({ find: findStub })
782783
};
783784
sinon.stub(lcConductor._zkClient, 'getData').yields(null, Buffer.from('bucket1'), null);
784-
lcConductor.listBuckets(queue, fakeLogger, err => {
785+
lcConductor.listBuckets(queue, 'test-scan-id', fakeLogger, err => {
785786
assert.ifError(err);
786787
assert.deepEqual(findStub.getCall(0).args[0], {
787788
_id: {
@@ -808,7 +809,7 @@ describe('Lifecycle Conductor', () => {
808809
getCollection: () => ({ find: findStub })
809810
};
810811
sinon.stub(lcConductor._zkClient, 'getData').yields(null, Buffer.from('bucket1'), null);
811-
lcConductor.listBuckets(queue, fakeLogger, err => {
812+
lcConductor.listBuckets(queue, 'test-scan-id', fakeLogger, err => {
812813
assert.ifError(err);
813814
assert.deepEqual(findStub.getCall(0).args[0], {
814815
'_id': {

tests/utils/BackbeatTestConsumer.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,6 @@ class BackbeatTestConsumer extends BackbeatConsumer {
4040
parsedMsg.contextInfo.conductorScanId =
4141
expectedMsg.value.contextInfo.conductorScanId;
4242
}
43-
// messageId is also generated per message: check it exists,
44-
// then normalize for comparison
45-
if (expectedMsg.value.contextInfo?.messageId === 'test-message-id') {
46-
assert(parsedMsg.contextInfo?.messageId,
47-
'expected contextInfo.messageId field');
48-
parsedMsg.contextInfo.messageId =
49-
expectedMsg.value.contextInfo.messageId;
50-
}
5143
}
5244
assert.deepStrictEqual(
5345
parsedMsg, expectedMsg.value,

0 commit comments

Comments
 (0)