Skip to content

Commit ba30395

Browse files
support per extension log level
Issue: BB-807
1 parent 7e9cc25 commit ba30395

7 files changed

Lines changed: 66 additions & 6 deletions

File tree

‎bin/ingestion.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ const { connectionString, autoCreateNamespace, retries } = zkConfig;
3333
const RESUME_NODE = 'scheduledResume';
3434

3535
const log = new werelogs.Logger('Backbeat:IngestionPopulator');
36-
werelogs.configure({ level: config.log.logLevel,
37-
dump: config.log.dumpLevel });
36+
const ingestionLogConfig = ingestionExtConfigs.log ?? config.log;
37+
werelogs.configure({ level: ingestionLogConfig.logLevel,
38+
dump: ingestionLogConfig.dumpLevel });
3839

3940
let scheduler;
4041
let ingestionPopulator;

‎extensions/ingestion/IngestionConfigValidator.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const joi = require('joi');
2-
const { probeServerJoi } = require('../../lib/config/configItems.joi');
2+
const { probeServerJoi, logJoiOptional } = require('../../lib/config/configItems.joi');
33

44
const joiSchema = joi.object({
55
auth: joi.object({
@@ -18,6 +18,7 @@ const joiSchema = joi.object({
1818
circuitBreaker: joi.object().optional(),
1919
}).optional(),
2020
producerParams: joi.object().unknown(true).default({}),
21+
log: logJoiOptional,
2122
});
2223

2324
function configValidator(backbeatConfig, extConfig) {

‎extensions/mongoProcessor/MongoProcessorConfigValidator.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const joi = require('joi');
2-
const { retryParamsJoi, probeServerJoi } = require('../../lib/config/configItems.joi');
2+
const { retryParamsJoi, probeServerJoi, logJoiOptional } = require('../../lib/config/configItems.joi');
33

44
const { MAX_QUEUED_DEFAULT } = require('../../lib/constants').backbeatConsumer;
55

@@ -11,6 +11,7 @@ const joiSchema = joi.object({
1111
maxQueued: joi.number().greater(0).default(MAX_QUEUED_DEFAULT),
1212
probeServer: probeServerJoi.default(),
1313
circuitBreaker: joi.object().optional(),
14+
log: logJoiOptional,
1415
});
1516

1617
function configValidator(backbeatConfig, extConfig) {

‎extensions/mongoProcessor/mongoProcessorTask.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ const mongoProcessorConfig = config.extensions.mongoProcessor;
2323
const mongoClientConfig = config.queuePopulator.mongo;
2424

2525
const log = new werelogs.Logger('Backbeat:MongoProcessor:task');
26-
werelogs.configure({ level: config.log.logLevel,
27-
dump: config.log.dumpLevel });
26+
const mongoProcessorLogConfig = mongoProcessorConfig.log ?? config.log;
27+
werelogs.configure({ level: mongoProcessorLogConfig.logLevel,
28+
dump: mongoProcessorLogConfig.dumpLevel });
2829

2930
const mqp = new MongoQueueProcessor(kafkaConfig, mongoProcessorConfig,
3031
mongoClientConfig, mConfig);

‎lib/config/configItems.joi.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ const logJoi =
5151
dumpLevel: 'error',
5252
});
5353

54+
// logJoi with no default :
55+
// Callers fall back to the global log config when this one is not configured
56+
const logJoiOptional =
57+
joi.object({
58+
logLevel: joi.alternatives()
59+
.try('error', 'warn', 'info', 'debug', 'trace'),
60+
dumpLevel: joi.alternatives()
61+
.try('error', 'warn', 'info', 'debug', 'trace'),
62+
}).optional();
63+
5464
const adminCredsJoi = joi.object()
5565
.min(1)
5666
.pattern(/^[A-Za-z0-9]{20}$/, joi.string());
@@ -168,6 +178,7 @@ module.exports = {
168178
transportJoi,
169179
bootstrapListJoi,
170180
logJoi,
181+
logJoiOptional,
171182
adminCredsJoi,
172183
authJoi,
173184
inheritedAuthJoi,

‎tests/unit/ingestion/IngestionConfigValidator.spec.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ const baseExtConfig = {
1414

1515
const qpBatchMaxRead = config.queuePopulator.batchMaxRead;
1616

17+
describe('IngestionConfigValidator log override', () => {
18+
it('should pass through log config when set', () => {
19+
const validated = configValidator({}, {
20+
...baseExtConfig,
21+
log: { logLevel: 'debug', dumpLevel: 'error' },
22+
});
23+
assert.deepStrictEqual(validated.log, { logLevel: 'debug', dumpLevel: 'error' });
24+
});
25+
26+
it('should leave log undefined when not set, deferring to global config.log', () => {
27+
const validated = configValidator({}, baseExtConfig);
28+
assert.strictEqual(validated.log, undefined);
29+
});
30+
});
31+
1732
describe('IngestionConfigValidator batchMaxRead fallback', () => {
1833
it('should override queuePopulator.batchMaxRead when set in extension config', () => {
1934
const validated = configValidator({}, { ...baseExtConfig, batchMaxRead: 500 });
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
3+
const assert = require('assert');
4+
const config = require('../../../lib/Config');
5+
const configValidator = require('../../../extensions/mongoProcessor/MongoProcessorConfigValidator');
6+
7+
const baseConfig = {
8+
topic: 'backbeat-ingestion',
9+
groupId: 'backbeat-ingestion-group',
10+
probeServer: { port: 4000 },
11+
};
12+
13+
describe('MongoProcessorConfigValidator log override', () => {
14+
it('should pass through log config when set', () => {
15+
const validated = configValidator({}, {
16+
...baseConfig,
17+
log: { logLevel: 'warn', dumpLevel: 'error' },
18+
});
19+
assert.deepStrictEqual(validated.log, { logLevel: 'warn', dumpLevel: 'error' });
20+
});
21+
22+
it('should leave log undefined when not set, deferring to global config.log', () => {
23+
const validated = configValidator({}, baseConfig);
24+
assert.strictEqual(validated.log, undefined);
25+
// mongoProcessorTask.js: const logConfig = mongoProcessorConfig.log ?? config.log
26+
const logConfig = validated.log ?? config.log;
27+
assert.strictEqual(logConfig.logLevel, config.log.logLevel);
28+
assert.strictEqual(logConfig.dumpLevel, config.log.dumpLevel);
29+
});
30+
});

0 commit comments

Comments
 (0)