Skip to content

Commit

Permalink
test: fix failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
aryamohanan committed Dec 2, 2024
1 parent e06e324 commit fd2f3a3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 35 deletions.
9 changes: 4 additions & 5 deletions packages/collector/test/apps/agentStub.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const enableSpanBatching = process.env.ENABLE_SPANBATCHING === 'true';
const kafkaTraceCorrelation = process.env.KAFKA_TRACE_CORRELATION
? process.env.KAFKA_TRACE_CORRELATION === 'true'
: null;
const ignoreRedisEndpoints = process.env.INSTANA_IGNORE_ENDPOINTS && JSON.parse(process.env.INSTANA_IGNORE_ENDPOINTS);
const ignoreEndpoints = process.env.INSTANA_IGNORE_ENDPOINTS && JSON.parse(process.env.INSTANA_IGNORE_ENDPOINTS);

let discoveries = {};
let rejectAnnounceAttempts = 0;
Expand Down Expand Up @@ -87,7 +87,7 @@ app.put('/com.instana.plugin.nodejs.discovery', (req, res) => {
}
};

if (kafkaTraceCorrelation != null || extraHeaders.length > 0 || enableSpanBatching || ignoreRedisEndpoints) {
if (kafkaTraceCorrelation != null || extraHeaders.length > 0 || enableSpanBatching || ignoreEndpoints) {
response.tracing = {};

if (extraHeaders.length > 0) {
Expand All @@ -104,9 +104,8 @@ app.put('/com.instana.plugin.nodejs.discovery', (req, res) => {
if (enableSpanBatching) {
response.tracing['span-batching-enabled'] = true;
}
if (ignoreRedisEndpoints) {
response.tracing = {};
response.tracing['ignore-endpoints'] = ignoreRedisEndpoints;
if (ignoreEndpoints) {
response.tracing['ignore-endpoints'] = ignoreEndpoints;
}
}
res.send(response);
Expand Down
2 changes: 1 addition & 1 deletion packages/collector/test/apps/agentStubControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class AgentStubControls {
env.KAFKA_TRACE_CORRELATION = opts.kafkaConfig.traceCorrelation.toString();
}
}
if (opts?.ignoreEndpoints) {
if (opts.ignoreEndpoints) {
env.INSTANA_IGNORE_ENDPOINTS = JSON.stringify(opts.ignoreEndpoints);
}

Expand Down
48 changes: 28 additions & 20 deletions packages/collector/test/tracing/database/ioredis/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1281,8 +1281,8 @@ function checkConnection(span, setupType) {
});
}
});
mochaSuiteFn('ignore-endpoints test:', function () {
describe('ignore-endpoints enabled via agent config', () => {
mochaSuiteFn('ignore-endpoints:', function () {
describe('when ignore-endpoints is enabled via agent configuration', () => {
const { AgentStubControls } = require('../../../apps/agentStubControls');
const customAgentControls = new AgentStubControls();
let controls;
Expand All @@ -1294,10 +1294,7 @@ function checkConnection(span, setupType) {

controls = new ProcessControls({
agentControls: customAgentControls,
dirname: __dirname,
env: {
REDIS_CLUSTER: setupType === 'cluster'
}
dirname: __dirname
});
await controls.startAndWaitForAgentConnection();
});
Expand All @@ -1311,7 +1308,7 @@ function checkConnection(span, setupType) {
await controls.stop();
});

it('should ignore redis spans for configured ignore endpoints', async () => {
it('should ignore redis spans for ignored endpoints (get, set)', async () => {
await controls
.sendRequest({
method: 'POST',
Expand All @@ -1324,15 +1321,20 @@ function checkConnection(span, setupType) {
.then(async () => {
return retry(async () => {
const spans = await customAgentControls.getSpans();
// 1 x http entry span
expect(spans.length).to.equal(1);
spans.forEach(span => {
expect(span.n).not.to.equal('redis');
});
expectAtLeastOneMatching(spans, [
span => expect(span.n).to.equal('node.http.server'),
span => expect(span.data.http.method).to.equal('POST')
]);
});
});
});
});
describe('ignore-endpoints enabled via tracing config', async () => {
describe('when ignore-endpoints is enabled via tracing configuration', async () => {
globalAgent.setUpCleanUpHooks();
const agentControls = globalAgent.instance;
let controls;
Expand All @@ -1342,8 +1344,7 @@ function checkConnection(span, setupType) {
useGlobalAgent: true,
dirname: __dirname,
env: {
REDIS_CLUSTER: setupType === 'cluster',
INSTANA_IGNORE_ENDPOINTS: '{"redis": ["get"}'
INSTANA_IGNORE_ENDPOINTS: '{"redis": ["get"]}'
}
});
await controls.start();
Expand All @@ -1360,21 +1361,21 @@ function checkConnection(span, setupType) {
afterEach(async () => {
await controls.clearIpcMessages();
});
it('should ignore redis spans for configured ignore endpoints', async function () {
it('should ignore redis spans for ignored endpoint (get)', async function () {
await controls
.sendRequest({
method: 'GET',
path: '/values',
qs: {
key: 'price'
key: 'discount',
value: 50
}
})

.then(async response => {
expect(String(response)).to.equal('42');

.then(async () => {
return retry(async () => {
const spans = await agentControls.getSpans();
// 1 x http entry span
expect(spans.length).to.equal(1);
spans.forEach(span => {
expect(span.n).not.to.equal('redis');
Expand All @@ -1387,25 +1388,32 @@ function checkConnection(span, setupType) {
});
});
});
it('should create redis spans for non-ignored redis endpoints', async () => {
it('should not ignore redis spans for endpoints that are not in the ignore list', async () => {
await controls
.sendRequest({
method: 'POST',
path: '/values',
qs: {
key: 'price',
value: 42
key: 'discount',
value: 50
}
})
.then(async () => {
return retry(async () => {
const spans = await agentControls.getSpans();
expect(spans.length).to.equal(2);
expect(spans.some(span => span.n === 'redis')).to.be.true;
expectAtLeastOneMatching(spans, [

const entrySpan = expectAtLeastOneMatching(spans, [
span => expect(span.n).to.equal('node.http.server'),
span => expect(span.data.http.method).to.equal('POST')
]);

expectExactlyOneMatching(spans, [
span => expect(span.t).to.equal(entrySpan.t),
span => expect(span.p).to.equal(entrySpan.s),
span => expect(span.n).to.equal('redis'),
span => expect(span.data.redis.command).to.equal('set')
]);
});
});
});
Expand Down
17 changes: 8 additions & 9 deletions packages/collector/test/tracing/database/redis/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const globalAgent = require('../../../globalAgent');
// Please set the environment variables to run the tests against azure redis cluster:
// export AZURE_REDIS_CLUSTER=team-nodejs-redis-cluster-tekton.redis.cache.windows.net:6380
// export AZURE_REDIS_CLUSTER_PWD=
['default'].forEach(setupType => {
['default', 'cluster'].forEach(setupType => {
describe(`tracing/redis ${setupType}`, function () {
['redis', '@redis/client'].forEach(redisPkg => {
describe(`require: ${redisPkg}`, function () {
Expand Down Expand Up @@ -199,6 +199,7 @@ const globalAgent = require('../../../globalAgent');
})
);
}));

it('must trace hset/hget calls', () =>
controls
.sendRequest({
Expand Down Expand Up @@ -851,8 +852,8 @@ const globalAgent = require('../../../globalAgent');
});
}
});
mochaSuiteFn('ignore-endpoints test:', function () {
describe('ignore-endpoints enabled via agent config', () => {
mochaSuiteFn('ignore-endpoints:', function () {
describe('when ignore-endpoints is enabled via agent configuration', () => {
const { AgentStubControls } = require('../../../apps/agentStubControls');
const customAgentControls = new AgentStubControls();
let controls;
Expand All @@ -867,8 +868,7 @@ const globalAgent = require('../../../globalAgent');
redisVersion === 'latest' ? path.join(__dirname, 'app.js') : path.join(__dirname, 'legacyApp.js'),
env: {
REDIS_VERSION: redisVersion,
REDIS_PKG: redisPkg,
REDIS_CLUSTER: setupType === 'cluster'
REDIS_PKG: redisPkg
}
});
await controls.startAndWaitForAgentConnection(5000, Date.now() + 1000 * 60 * 5);
Expand All @@ -883,7 +883,7 @@ const globalAgent = require('../../../globalAgent');
await controls.stop();
});

it('should ignore redis spans for configured ignore endpoints', async () => {
it('should ignore redis spans for ignored endpoints (get, set)', async () => {
await controls
.sendRequest({
method: 'POST',
Expand Down Expand Up @@ -918,8 +918,7 @@ const globalAgent = require('../../../globalAgent');
env: {
REDIS_VERSION: redisVersion,
REDIS_PKG: redisPkg,
REDIS_CLUSTER: setupType === 'cluster',
INSTANA_IGNORE_ENDPOINTS: '{"redis": ["get"}'
INSTANA_IGNORE_ENDPOINTS: '{"redis": ["get","set"]}'
}
});
await controls.start();
Expand Down Expand Up @@ -987,7 +986,7 @@ const globalAgent = require('../../../globalAgent');
});
});
});
it('should create redis spans for non-ignored redis endpoints', async () => {
it('should not ignore redis spans for endpoints that are not in the ignore list', async () => {
await controls
.sendRequest({
method: 'GET',
Expand Down

0 comments on commit fd2f3a3

Please sign in to comment.