Skip to content

Commit 65d6032

Browse files
committed
test: added config precedence integretion tests
1 parent 542e088 commit 65d6032

1 file changed

Lines changed: 124 additions & 0 deletions

File tree

  • packages/collector/test/integration/currencies/databases/redis

packages/collector/test/integration/currencies/databases/redis/test_base.js

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,130 @@ module.exports = function (name, version, isLatest, mode) {
11001100
});
11011101
});
11021102

1103+
describe('Config precedence', () => {
1104+
describe('when both agent config and env var are set, env var takes precedence', () => {
1105+
const { AgentStubControls } = require('@_local/collector/test/apps/agentStubControls');
1106+
const customAgentControls = new AgentStubControls();
1107+
let controls;
1108+
1109+
before(async () => {
1110+
await customAgentControls.startAgent({
1111+
ignoreEndpoints: { redis: ['get', 'set'] }
1112+
});
1113+
1114+
controls = new ProcessControls({
1115+
agentControls: customAgentControls,
1116+
dirname: __dirname,
1117+
appName: isLegacyVersion ? 'legacyApp' : 'app',
1118+
env: {
1119+
LIBRARY_LATEST: isLatest,
1120+
LIBRARY_VERSION: version,
1121+
LIBRARY_NAME: name,
1122+
REDIS_SETUP_TYPE: mode,
1123+
INSTANA_IGNORE_ENDPOINTS: 'redis:get;'
1124+
}
1125+
});
1126+
await controls.startAndWaitForAgentConnection(5000, Date.now() + 1000 * 60 * 5);
1127+
});
1128+
1129+
beforeEach(async () => {
1130+
await customAgentControls.clearReceivedTraceData();
1131+
});
1132+
1133+
after(async () => {
1134+
await customAgentControls.stopAgent();
1135+
await controls.stop();
1136+
});
1137+
1138+
it('should use env var config and ignore only get (not set)', async () => {
1139+
await controls
1140+
.sendRequest({
1141+
method: 'POST',
1142+
path: '/values',
1143+
qs: {
1144+
key: 'discount',
1145+
value: 50
1146+
}
1147+
})
1148+
.then(async () => {
1149+
return retry(async () => {
1150+
const spans = await customAgentControls.getSpans();
1151+
// 1 x http entry span
1152+
// 1 x http client span
1153+
// 1 x redis set span (set is NOT ignored because env var only ignores 'get')
1154+
expect(spans.length).to.equal(3);
1155+
1156+
const redisSpans = spans.filter(span => span.n === 'redis');
1157+
expect(redisSpans.length).to.equal(1);
1158+
expect(redisSpans[0].data.redis.command).to.equal('set');
1159+
});
1160+
});
1161+
});
1162+
});
1163+
});
1164+
1165+
mochaSuiteFn('disable redis:', function () {
1166+
describe('when both agent config and env var are set, env var takes precedence', () => {
1167+
const { AgentStubControls } = require('@_local/collector/test/apps/agentStubControls');
1168+
const customAgentControls = new AgentStubControls();
1169+
let controls;
1170+
1171+
before(async () => {
1172+
await customAgentControls.startAgent({
1173+
disable: { redis: false }
1174+
});
1175+
1176+
controls = new ProcessControls({
1177+
agentControls: customAgentControls,
1178+
dirname: __dirname,
1179+
appName: isLegacyVersion ? 'legacyApp' : 'app',
1180+
env: {
1181+
LIBRARY_LATEST: isLatest,
1182+
LIBRARY_VERSION: version,
1183+
LIBRARY_NAME: name,
1184+
REDIS_SETUP_TYPE: mode,
1185+
INSTANA_TRACING_DISABLE: 'redis'
1186+
}
1187+
});
1188+
await controls.startAndWaitForAgentConnection(5000, Date.now() + 1000 * 60 * 5);
1189+
});
1190+
1191+
beforeEach(async () => {
1192+
await customAgentControls.clearReceivedTraceData();
1193+
});
1194+
1195+
after(async () => {
1196+
await customAgentControls.stopAgent();
1197+
await controls.stop();
1198+
});
1199+
1200+
it('should use env var config and disable redis tracing', async () => {
1201+
await controls
1202+
.sendRequest({
1203+
method: 'POST',
1204+
path: '/values',
1205+
qs: {
1206+
key: 'discount',
1207+
value: 50
1208+
}
1209+
})
1210+
.then(async () => {
1211+
return retry(async () => {
1212+
const spans = await customAgentControls.getSpans();
1213+
// 1 x http entry span
1214+
// 1 x http client span
1215+
// No redis spans because redis is disabled via env var
1216+
expect(spans.length).to.equal(2);
1217+
1218+
spans.forEach(span => {
1219+
expect(span.n).not.to.equal('redis');
1220+
});
1221+
});
1222+
});
1223+
});
1224+
});
1225+
});
1226+
11031227
describe('(1) when env variable INSTANA_IGNORE_ENDPOINTS_PATH is used', async () => {
11041228
globalAgent.setUpCleanUpHooks();
11051229
let controls;

0 commit comments

Comments
 (0)