Skip to content

Commit

Permalink
chore: updated ignore endpoints configuration format (#1480)
Browse files Browse the repository at this point in the history
  • Loading branch information
aryamohanan authored Dec 9, 2024
1 parent 7fa82e2 commit ab683e0
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 25 deletions.
12 changes: 4 additions & 8 deletions packages/collector/src/announceCycle/unannounced.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,9 @@ function applySpanBatchingConfiguration(agentResponse) {
}

/**
* - The agent configuration currently uses a pipe ('|') as a separator for endpoints.
* - This function supports both ('|') and comma (',') to ensure future compatibility.
* - Additionally, it supports the `string[]` format for backward compatibility,
* as this was the previously used standard. The final design decision is not yet completed.
* https://github.ibm.com/instana/requests-for-discussion/pull/84
* The agent configuration returns the `string[]` format.
* For more information, see the related design discussion:
* https://github.ibm.com/instana/requests-for-discussion/pull/84
*
* @param {AgentAnnounceResponse} agentResponse
*/
Expand All @@ -239,9 +237,7 @@ function applyIgnoreEndpointsConfiguration(agentResponse) {
const endpointTracingConfig = Object.fromEntries(
Object.entries(endpointTracingConfigFromAgent).map(([service, endpoints]) => {
let normalizedEndpoints = null;
if (typeof endpoints === 'string') {
normalizedEndpoints = endpoints.split(/[|,]/).map(endpoint => endpoint?.trim()?.toLowerCase());
} else if (Array.isArray(endpoints)) {
if (Array.isArray(endpoints)) {
normalizedEndpoints = endpoints.map(endpoint => endpoint?.toLowerCase());
}

Expand Down
16 changes: 8 additions & 8 deletions packages/collector/test/announceCycle/unannounced_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ describe('unannounced state', () => {
prepareAnnounceResponse({
tracing: {
'ignore-endpoints': {
redis: 'get'
redis: ['get']
}
}
});
Expand All @@ -239,7 +239,7 @@ describe('unannounced state', () => {
prepareAnnounceResponse({
tracing: {
'ignore-endpoints': {
redis: 'SET|GET'
redis: ['SET', 'GET']
}
}
});
Expand All @@ -261,8 +261,8 @@ describe('unannounced state', () => {
prepareAnnounceResponse({
tracing: {
'ignore-endpoints': {
REDIS: 'get|set',
dynamodb: 'query'
REDIS: ['GET', 'SET'],
dynamodb: ['query']
}
}
});
Expand All @@ -281,11 +281,11 @@ describe('unannounced state', () => {
});
});

it('should apply tracing configuration to ignore endpoints when specified using array format', done => {
it('should set ignoreEndpoints to null when the format is invalid', done => {
prepareAnnounceResponse({
tracing: {
'ignore-endpoints': {
REDIS: ['get', 'type'],
REDIS: 'get|set',
dynamodb: 'query'
}
}
Expand All @@ -295,8 +295,8 @@ describe('unannounced state', () => {
expect(agentOptsStub.config).to.deep.equal({
tracing: {
ignoreEndpoints: {
redis: ['get', 'type'],
dynamodb: ['query']
redis: null,
dynamodb: null
}
}
});
Expand Down
4 changes: 2 additions & 2 deletions packages/collector/test/tracing/database/ioredis/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ function checkConnection(span, setupType) {

before(async () => {
await customAgentControls.startAgent({
ignoreEndpoints: { redis: 'get|set' }
ignoreEndpoints: { redis: ['get', 'set'] }
});

controls = new ProcessControls({
Expand Down Expand Up @@ -1344,7 +1344,7 @@ function checkConnection(span, setupType) {
useGlobalAgent: true,
dirname: __dirname,
env: {
INSTANA_IGNORE_ENDPOINTS: '{"redis": ["get"]}'
INSTANA_IGNORE_ENDPOINTS: 'redis:get'
}
});
await controls.start();
Expand Down
4 changes: 2 additions & 2 deletions packages/collector/test/tracing/database/redis/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ const globalAgent = require('../../../globalAgent');
let controls;
before(async () => {
await customAgentControls.startAgent({
ignoreEndpoints: { redis: 'get|set' }
ignoreEndpoints: { redis: ['get', 'set'] }
});

controls = new ProcessControls({
Expand Down Expand Up @@ -918,7 +918,7 @@ const globalAgent = require('../../../globalAgent');
env: {
REDIS_VERSION: redisVersion,
REDIS_PKG: redisPkg,
INSTANA_IGNORE_ENDPOINTS: '{"redis": ["get","set"]}'
INSTANA_IGNORE_ENDPOINTS: 'redis:get,set;'
}
});
await controls.start();
Expand Down
20 changes: 17 additions & 3 deletions packages/core/src/util/normalizeConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -718,10 +718,24 @@ function normalizeIgnoreEndpoints(config) {
}
});
} else if (process.env.INSTANA_IGNORE_ENDPOINTS) {
// The environment variable name and its format are still under discussion.
// It is currently private and will not be documented or publicly shared.
try {
config.tracing.ignoreEndpoints = JSON.parse(process.env.INSTANA_IGNORE_ENDPOINTS);
const ignoreEndpoints = Object.fromEntries(
process.env.INSTANA_IGNORE_ENDPOINTS.split(';')
.map(serviceEntry => {
const [serviceName, endpointList] = (serviceEntry || '').split(':').map(part => part.trim());

if (!serviceName || !endpointList) {
logger.warn(
`Invalid entry in INSTANA_IGNORE_ENDPOINTS ${process.env.INSTANA_IGNORE_ENDPOINTS}: "${serviceEntry}". Expected format is e.g. "service:endpoint1,endpoint2".`
);
return null;
}

return [serviceName.toLowerCase(), endpointList.split(',').map(endpoint => endpoint.trim().toLowerCase())];
})
.filter(Boolean)
);
config.tracing.ignoreEndpoints = ignoreEndpoints;
} catch (error) {
logger.warn(
`Failed to parse INSTANA_IGNORE_ENDPOINTS: ${process.env.INSTANA_IGNORE_ENDPOINTS}. Error: ${error.message}`
Expand Down
14 changes: 12 additions & 2 deletions packages/core/test/util/normalizeConfig_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,16 +477,26 @@ describe('util.normalizeConfig', () => {
});

it('should apply ignore endpoints if the INSTANA_IGNORE_ENDPOINTS is set and valid', () => {
process.env.INSTANA_IGNORE_ENDPOINTS = '{"redis": ["get", "set"]}';
process.env.INSTANA_IGNORE_ENDPOINTS = 'redis:get,set;';
const config = normalizeConfig();
expect(config.tracing.ignoreEndpoints).to.deep.equal({ redis: ['get', 'set'] });
});

it('should correctly parse INSTANA_IGNORE_ENDPOINTS containing multiple services and endpoints', () => {
process.env.INSTANA_IGNORE_ENDPOINTS = 'redis:get,set; dynamodb:query';
const config = normalizeConfig();
expect(config.tracing.ignoreEndpoints).to.deep.equal({
redis: ['get', 'set'],
dynamodb: ['query']
});
});

it('should fallback to default if INSTANA_IGNORE_ENDPOINTS is set but has an invalid format', () => {
process.env.INSTANA_IGNORE_ENDPOINTS = '"redis": ["get", "set"]';
process.env.INSTANA_IGNORE_ENDPOINTS = '"redis=get,set"';
const config = normalizeConfig();
expect(config.tracing.ignoreEndpoints).to.deep.equal({});
});

it('should apply ignore endpoints via config', () => {
const config = normalizeConfig({
tracing: {
Expand Down

0 comments on commit ab683e0

Please sign in to comment.