Skip to content

Commit ebcfebd

Browse files
fix: enforced max limit on metrics transmission config (#2511)
1 parent 0479b6a commit ebcfebd

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

packages/core/src/config/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ const { validateStackTraceMode, validateStackTraceLength } = require('./configVa
7373
/** @type {String[]} */
7474
const allowedSecretMatchers = ['equals', 'equals-ignore-case', 'contains', 'contains-ignore-case', 'regex', 'none'];
7575

76+
const transmissionDelayMaxValue = 5000;
77+
7678
/**
7779
* @typedef {Object} InstanaConfig
7880
* @property {string} [serviceName]
@@ -223,6 +225,14 @@ function normalizeMetricsConfig(config) {
223225
'INSTANA_METRICS_TRANSMISSION_DELAY'
224226
);
225227

228+
// Validate max value for transmissionDelay
229+
if (config.metrics.transmissionDelay > transmissionDelayMaxValue) {
230+
logger.warn(
231+
`The value of config.metrics.transmissionDelay (or INSTANA_METRICS_TRANSMISSION_DELAY) (${config.metrics.transmissionDelay}) exceeds the maximum allowed value of ${transmissionDelayMaxValue}. Assuming the max value ${transmissionDelayMaxValue}.`
232+
);
233+
config.metrics.transmissionDelay = transmissionDelayMaxValue;
234+
}
235+
226236
config.metrics.timeBetweenHealthcheckCalls =
227237
config.metrics.timeBetweenHealthcheckCalls || defaults.metrics.timeBetweenHealthcheckCalls;
228238
}

packages/core/test/config/normalizeConfig_test.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ describe('config.normalizeConfig', () => {
7070
it('should use custom metrics transmission settings from config', () => {
7171
const config = coreConfig.normalize({
7272
metrics: {
73-
transmissionDelay: 9753
73+
transmissionDelay: 753
7474
}
7575
});
76-
expect(config.metrics.transmissionDelay).to.equal(9753);
76+
expect(config.metrics.transmissionDelay).to.equal(753);
7777
});
7878

7979
it('should use custom metrics transmission settings from env vars', () => {
@@ -88,6 +88,27 @@ describe('config.normalizeConfig', () => {
8888
expect(config.metrics.transmissionDelay).to.equal(1000);
8989
});
9090

91+
it('should use max metrics transmission settings when value exceeds max of 5000', () => {
92+
process.env.INSTANA_METRICS_TRANSMISSION_DELAY = '6000';
93+
const normalizedConfig = coreConfig.normalize();
94+
expect(normalizedConfig.metrics.transmissionDelay).to.equal(5000);
95+
});
96+
97+
it('should accept metrics transmission delay at max value of 5000', () => {
98+
process.env.INSTANA_METRICS_TRANSMISSION_DELAY = '5000';
99+
const normalizedConfig = coreConfig.normalize();
100+
expect(normalizedConfig.metrics.transmissionDelay).to.equal(5000);
101+
});
102+
103+
it('should use max metrics transmission settings when value exceeds max 5000', () => {
104+
const config = coreConfig.normalize({
105+
metrics: {
106+
transmissionDelay: 9753
107+
}
108+
});
109+
expect(config.metrics.transmissionDelay).to.equal(5000);
110+
});
111+
91112
it('should use custom config.metrics.timeBetweenHealthcheckCalls', () => {
92113
const config = coreConfig.normalize({
93114
metrics: {

0 commit comments

Comments
 (0)