Skip to content

Commit e28bcbc

Browse files
authored
chore: fixed failing config related tests (#2508)
1 parent 9f52cec commit e28bcbc

5 files changed

Lines changed: 431 additions & 123 deletions

File tree

packages/collector/src/announceCycle/agentready.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ function enter(_ctx) {
130130
}
131131
}
132132

133-
const updatedConfig = coreConfig.update(agentOpts.config, util.constants.CONFIG_SOURCES.AGENT);
133+
const updatedConfig = coreConfig.update({
134+
externalConfig: agentOpts.config,
135+
source: util.constants.CONFIG_SOURCES.AGENT
136+
});
134137
tracing.activate(updatedConfig);
135138

136139
if (agentOpts.autoProfile && autoprofile) {

packages/collector/test/unit/src/announceCycle/agentready.test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ describe('agent ready state', () => {
3535
let uncaughtStub;
3636
let eolStub;
3737
beforeEach(() => {
38+
const coreConfig = require('@_local/core/src/config');
39+
coreConfig.normalize({ finalConfigBase: {} });
40+
3841
agentOptsStub = {
3942
config: {},
4043
agentUuid: 'test-uuid'
@@ -90,7 +93,8 @@ describe('agent ready state', () => {
9093
it('should forward agent config to tracing component', () => {
9194
agentOptsStub.config = { foo: { bar: 'baz' } };
9295
agentReadyState.enter();
93-
expect(tracingStub.activate).to.have.been.calledWith(agentOptsStub.config);
96+
const updatedConfig = tracingStub.activate.firstCall.args[0];
97+
expect(updatedConfig.foo.bar).to.equal('baz');
9498
});
9599
});
96100

packages/core/src/config/index.js

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -957,28 +957,40 @@ function normalizePreloadOpentelemetry({ userConfig = {}, defaultConfig = {}, fi
957957
/**
958958
* Updates configuration values dynamically from external sources (e.g., agent)
959959
*
960-
* @param {Object.<string, any>} externalConfig
961-
* @param {number} source
962-
*/
963-
exports.update = function update(externalConfig, source) {
960+
* @param {Object} [params]
961+
* @param {Record<string, any>} [params.externalConfig]
962+
* @param {number} [params.source]
963+
* @param {Record<string, any>} [params.target=currentConfig]
964+
* @param {string} [params.basePath='config']
965+
* @returns {Record<string, any>}
966+
*/
967+
exports.update = function update({ externalConfig = {}, source, target = currentConfig, basePath = 'config' } = {}) {
964968
if (!externalConfig || typeof externalConfig !== 'object' || Object.keys(externalConfig).length === 0) {
965969
return currentConfig;
966970
}
967971

968972
Object.keys(externalConfig).forEach(key => {
969-
const configPath = `config.${key}`;
970-
const currentMeta = configStore.get(configPath);
973+
const path = `${basePath}.${key}`;
974+
const currentMeta = configStore.get(path);
971975

972976
if (currentMeta && currentMeta.source < source) {
973-
logger.debug(`[config] Skipping ${key}: current source ${currentMeta.source} > incoming ${source}`);
974-
return currentConfig;
977+
logger.debug(`[config] Skipping ${path}: current source ${currentMeta.source} > incoming ${source}`);
978+
return;
975979
}
976980

977-
/** @type {Record<string, any>} */
978-
const configAsRecord = currentConfig;
979-
configAsRecord[key] = deepMerge(configAsRecord[key], externalConfig[key]);
981+
const incomingValue = externalConfig[key];
982+
983+
if (incomingValue && typeof incomingValue === 'object' && !Array.isArray(incomingValue)) {
984+
if (!target[key] || typeof target[key] !== 'object') {
985+
target[key] = {};
986+
}
980987

981-
configStore.set(configPath, { source });
988+
update({ externalConfig: incomingValue, source, target: target[key], basePath: path });
989+
} else {
990+
target[key] = incomingValue;
991+
configStore.set(path, { source });
992+
}
982993
});
994+
983995
return currentConfig;
984996
};

packages/core/src/config/util.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ exports.resolve = function resolve({ envValue, inCodeValue, agentValue, defaultV
6666
return true;
6767
}
6868

69-
if (rawValue !== undefined) {
70-
logger?.warn(`[config] Validation failed for ${sourceKey}: ${JSON.stringify(rawValue)}`);
71-
}
72-
7369
return false;
7470
});
7571

0 commit comments

Comments
 (0)