diff --git a/extensions/replication/queueProcessor/task.js b/extensions/replication/queueProcessor/task.js index 590c45509..6eb351907 100644 --- a/extensions/replication/queueProcessor/task.js +++ b/extensions/replication/queueProcessor/task.js @@ -240,7 +240,7 @@ function initAndStart(zkClient) { }); startProbeServer( - getProbeConfig(repConfig.queueProcessor, siteNames), + getProbeConfig(repConfig.queueProcessor, siteNames, log), (err, probeServer) => { if (err) { log.fatal('error creating probe server', { diff --git a/lib/util/probe.js b/lib/util/probe.js index 2d57a836d..c627c7227 100644 --- a/lib/util/probe.js +++ b/lib/util/probe.js @@ -72,10 +72,10 @@ function observeKafkaStats(msg) { * @param {Object} queueProcessorConfig - Configuration of the queue processor that * holds the probe server configs for all sites * @param {Array} siteNames - List of site names (should contain at most one element) + * @param {Logger} logger - Logger instance * @returns {Object|undefined} Config for site or global config, undefined if no match found or invalid config */ -function getProbeConfig(queueProcessorConfig, siteNames) { - const logger = new Logger('Backbeat:Probe:getProbeConfig'); +function getProbeConfig(queueProcessorConfig, siteNames, logger) { if (siteNames.length === 0) { if (!Array.isArray(queueProcessorConfig.probeServer)) { @@ -102,7 +102,7 @@ function getProbeConfig(queueProcessorConfig, siteNames) { return siteConfig || undefined; } - return undefined; + return queueProcessorConfig.probeServer; } module.exports = { diff --git a/tests/unit/lib/util/probe.spec.js b/tests/unit/lib/util/probe.spec.js index f04069543..d3afdcd56 100644 --- a/tests/unit/lib/util/probe.spec.js +++ b/tests/unit/lib/util/probe.spec.js @@ -1,6 +1,7 @@ const assert = require('assert'); const { startProbeServer, getProbeConfig } = require('../../../../lib/util/probe'); +const Logger = require('werelogs').Logger; describe('Probe server', () => { it('is not created with no config', done => { @@ -27,13 +28,14 @@ describe('Probe server', () => { }); describe('getProbeConfig', () => { + const log = new Logger('getProbeConfig'); it('returns the probeServer config when siteNames is empty and probeServer is a single object', () => { const queueProcessorConfig = { probeServer: { bindAddress: '127.0.0.1', port: '8080' } }; const siteNames = []; - const result = getProbeConfig(queueProcessorConfig, siteNames); + const result = getProbeConfig(queueProcessorConfig, siteNames, log); assert.deepStrictEqual(result, { bindAddress: '127.0.0.1', port: '8080' }); }); @@ -43,7 +45,7 @@ describe('getProbeConfig', () => { }; const siteNames = []; - const result = getProbeConfig(queueProcessorConfig, siteNames); + const result = getProbeConfig(queueProcessorConfig, siteNames, log); assert.strictEqual(result, undefined); }); @@ -56,7 +58,7 @@ describe('getProbeConfig', () => { }; const siteNames = ['site2']; - const result = getProbeConfig(queueProcessorConfig, siteNames); + const result = getProbeConfig(queueProcessorConfig, siteNames, log); assert.deepStrictEqual(result, { site: 'site2', bindAddress: '127.0.0.2', port: '8081' }); }); @@ -68,7 +70,7 @@ describe('getProbeConfig', () => { }; const siteNames = ['site2']; - const result = getProbeConfig(queueProcessorConfig, siteNames); + const result = getProbeConfig(queueProcessorConfig, siteNames, log); assert.strictEqual(result, undefined); }); @@ -81,17 +83,17 @@ describe('getProbeConfig', () => { }; const siteNames = ['site1', 'site2']; // More than one element in siteNames - const result = getProbeConfig(queueProcessorConfig, siteNames); + const result = getProbeConfig(queueProcessorConfig, siteNames, log); assert.strictEqual(result, undefined); }); - it('returns undefined when probeServer is not an array and siteNames is not empty', () => { + it('returns probeserver when probeServer is not an array and siteNames is not empty', () => { const queueProcessorConfig = { probeServer: { bindAddress: '127.0.0.1', port: '8080' } // probeServer is a single object }; const siteNames = ['site1']; // siteNames is not empty - const result = getProbeConfig(queueProcessorConfig, siteNames); - assert.strictEqual(result, undefined); + const result = getProbeConfig(queueProcessorConfig, siteNames, log); + assert.deepStrictEqual(result, queueProcessorConfig.probeServer); }); });