Skip to content

Commit

Permalink
Merge branch 'improvement/BB-623' into q/8.7
Browse files Browse the repository at this point in the history
  • Loading branch information
bert-e committed Nov 6, 2024
2 parents e297638 + bb69b62 commit 2418cfc
Show file tree
Hide file tree
Showing 8 changed files with 413 additions and 14 deletions.
4 changes: 3 additions & 1 deletion extensions/notification/NotificationConfigValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ const joiSchema = joi.object({
concurrency: joi.number().greater(0).default(1000),
},
destinations: joi.array().items(destinationSchema).default([]),
probeServer: probeServerJoi.default()
// TODO: BB-625 reset to being required after supporting probeserver in S3C
// for bucket notification proceses
probeServer: probeServerJoi.optional()
});

function configValidator(backbeatConfig, extConfig) {
Expand Down
15 changes: 11 additions & 4 deletions lib/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const assert = require('assert');
const { EventEmitter } = require('events');
const joi = require('joi');

const fs = require('fs');
const path = require('path');
Expand Down Expand Up @@ -54,10 +55,16 @@ class Config extends EventEmitter {
throw new Error(`could not parse config file: ${err.message}`);
}

const { value: parsedConfig, err } = backbeatConfigJoi.validate(config);
if (err) {
throw new Error(`could not validate config file: ${err.message}`);
}
this._parseConfig(config);
}

/**
* Parses Backbeat's configuration
* @param {Object} config backbeat configuration
* @returns {undefined}
*/
_parseConfig(config) {
const parsedConfig = joi.attempt(config, backbeatConfigJoi);

if (parsedConfig.extensions) {
Object.keys(parsedConfig.extensions).forEach(extName => {
Expand Down
8 changes: 7 additions & 1 deletion lib/config.joi.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ const joiSchema = joi.object({
}).when('logSource', { is: 'dmd', then: joi.required() }),
mongo: mongoJoi,
kafka: qpKafkaJoi.when('logSource', { is: 'kafka', then: joi.required() }),
probeServer: probeServerJoi.default(),
// TODO: BB-625 reset to being required after supporting probeserver in S3C
// for bucket notification proceses
probeServer: probeServerJoi.when('...extensions', {
is: joi.object().keys({ notification: joi.exist() }),
then: joi.optional(),
otherwise: joi.required(),
}),
circuitBreaker: joi.object().optional(),
},
log: logJoi,
Expand Down
3 changes: 1 addition & 2 deletions lib/util/probe.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ const RdkafkaStats = require('node-rdkafka-prometheus');
*/
function startProbeServer(config, callback) {
if (!config) {
const err = new Error('configuration for probe server is missing');
callback(err);
callback();
return;
}

Expand Down
4 changes: 0 additions & 4 deletions tests/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,6 @@
"host": "127.0.0.1",
"port": 8900
},
"healthcheckServer": {
"bindAddress": "0.0.0.0",
"port": 4042
},
"redis": {
"name": "backbeat-test",
"password": "",
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/lib/config/Config.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict'; // eslint-disable-line

const assert = require('assert');

const { Config } = require('../../../../lib/Config');
const backbeatConfig = require('./config.json');

describe('Config', () => {
it('should make the probeserver config in the queuePoulator' +
'required when multiple extensions are configured', () => {
const config = new Config();
const testConfig = { ...backbeatConfig };
delete testConfig.queuePopulator.probeServer;
assert.throws(() => config._parseConfig(testConfig));
});

it('should make the probeserver config in the queuePoulator' +
'optional when only notification config is specified', () => {
const config = new Config();
const testConfig = { ...backbeatConfig };
delete testConfig.queuePopulator.probeServer;
testConfig.extensions = { notification: testConfig.extensions.notification };
assert.doesNotThrow(() => config._parseConfig(testConfig));
});
});
Loading

0 comments on commit 2418cfc

Please sign in to comment.