Skip to content

Commit

Permalink
User log from param and return probeconfig
Browse files Browse the repository at this point in the history
Issue: BB-536
  • Loading branch information
KillianG committed Oct 21, 2024
1 parent be2be13 commit 63bdd85
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion extensions/replication/queueProcessor/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
6 changes: 3 additions & 3 deletions lib/util/probe.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>} 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)) {
Expand All @@ -102,7 +102,7 @@ function getProbeConfig(queueProcessorConfig, siteNames) {
return siteConfig || undefined;
}

return undefined;
return queueProcessorConfig.probeServer;
}

module.exports = {
Expand Down
18 changes: 10 additions & 8 deletions tests/unit/lib/util/probe.spec.js
Original file line number Diff line number Diff line change
@@ -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 => {
Expand All @@ -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' });
});

Expand All @@ -43,7 +45,7 @@ describe('getProbeConfig', () => {
};
const siteNames = [];

const result = getProbeConfig(queueProcessorConfig, siteNames);
const result = getProbeConfig(queueProcessorConfig, siteNames, log);
assert.strictEqual(result, undefined);
});

Expand All @@ -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' });
});

Expand All @@ -68,7 +70,7 @@ describe('getProbeConfig', () => {
};
const siteNames = ['site2'];

const result = getProbeConfig(queueProcessorConfig, siteNames);
const result = getProbeConfig(queueProcessorConfig, siteNames, log);
assert.strictEqual(result, undefined);
});

Expand All @@ -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);
});
});

0 comments on commit 63bdd85

Please sign in to comment.