Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 1 addition & 12 deletions packages/aws-fargate/images/inspector/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions packages/aws-fargate/images/inspector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,5 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Bastian Krol <[email protected]>",
"license": "ISC",
"dependencies": {
"node-fetch": "^2.6.0"
}
"license": "ISC"
}
13 changes: 1 addition & 12 deletions packages/aws-fargate/images/test-images/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions packages/aws-fargate/images/test-images/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,5 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Bastian Krol <[email protected]>",
"license": "ISC",
"dependencies": {
"node-fetch": "^2.6.0"
}
"license": "ISC"
}
1 change: 0 additions & 1 deletion packages/aws-fargate/test/Control.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

const { fork } = require('child_process');
const path = require('path');
const fetch = require('node-fetch-v2');

const config = require('@instana/core/test/config');
const AbstractServerlessControl = require('../../serverless/test/util/AbstractServerlessControl');
Expand Down
1 change: 0 additions & 1 deletion packages/aws-fargate/test/esm/app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/

import http from 'http';
import fetch from 'node-fetch';

const downstreamDummyUrl = process.env.DOWNSTREAM_DUMMY_URL;
const port = process.env.TASK_HTTP_PORT;
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-fargate/test/esm/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ if (supportedVersion(process.versions.node)) {
expect(span.data.http.url).to.contain(control.downstreamDummyUrl);
expect(span.data.http.header).to.deep.equal({
'x-exit-request-header-1': 'exit request header value 1',
'x-exit-request-header-2': 'exit,request,header,value 2'
'x-exit-request-header-2': 'exit, request, header, value 2'
});
expect(span.ec).to.equal(0);
verifyHeaders(span);
Expand Down
1 change: 0 additions & 1 deletion packages/aws-fargate/test/integration_test/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ process.on('SIGTERM', () => {
});

const http = require('http');
const fetch = require('node-fetch-v2');

const { sendToParent } = require('../../../core/test/test_util');

Expand Down
5 changes: 1 addition & 4 deletions packages/aws-fargate/test/integration_test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -974,10 +974,7 @@ describe('AWS fargate integration test', function () {
expect(span.data.http.url).to.contain(control.downstreamDummyUrl);
expect(span.data.http.header).to.deep.equal({
'x-exit-request-header-1': 'exit request header value 1',
// This should be
// 'x-exit-request-header-2': 'exit, request, header, value 2'
// but node-fetch handles this case inconsistently, so it is actually
'x-exit-request-header-2': 'exit,request,header,value 2'
'x-exit-request-header-2': 'exit, request, header, value 2'
});
expect(span.ec).to.equal(0);
verifyHeaders(span);
Expand Down
5 changes: 1 addition & 4 deletions packages/aws-lambda/lambdas/wrapped-async/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,5 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Bastian Krol <[email protected]>",
"license": "MIT",
"dependencies": {
"node-fetch": "^2.3.0"
}
"license": "MIT"
}
2 changes: 0 additions & 2 deletions packages/aws-lambda/test/lambdas/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ const delay = require('../../../core/test/test_util/delay');
// assumed root dir of the Lambda.
require('../../src/metrics/rootDir').root = require('path').resolve(__dirname, '..', '..');

const fetch = require('node-fetch-v2');

const downstreamDummyUrl = process.env.DOWNSTREAM_DUMMY_URL;
const response = {};

Expand Down
2 changes: 0 additions & 2 deletions packages/aws-lambda/test/lambdas/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ const delay = require('../../../core/test/test_util/delay');
// assumed root dir of the Lambda.
require('../../src/metrics/rootDir').root = require('path').resolve(__dirname, '..', '..');

const fetch = require('node-fetch-v2');

const downstreamDummyUrl = process.env.DOWNSTREAM_DUMMY_URL;
const response = {};

Expand Down
2 changes: 0 additions & 2 deletions packages/aws-lambda/test/specification_compliance/lambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ const instana = require('../..');
// assumed root dir of the Lambda.
require('../../src/metrics/rootDir').root = require('path').resolve(__dirname, '..', '..');

const fetch = require('node-fetch-v2');

const downstreamDummyUrl = process.env.DOWNSTREAM_DUMMY_URL;

exports.handler = instana.wrap(async event => {
Expand Down
2 changes: 1 addition & 1 deletion packages/azure-container-services/test/Control.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

const { fork } = require('child_process');
const path = require('path');
const fetch = require('node-fetch-v2');

const portfinder = require('@instana/collector/test/test_util/portfinder');
const config = require('@instana/core/test/config');
const AbstractServerlessControl = require('../../serverless/test/util/AbstractServerlessControl');
Expand Down
1 change: 0 additions & 1 deletion packages/azure-container-services/test/esm/app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/

import http from 'http';
import fetch from 'node-fetch';
import getAppPort from '@instana/collector/test/test_util/app-port.js';

const downstreamDummyUrl = process.env.DOWNSTREAM_DUMMY_URL;
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 @@ -6,7 +6,7 @@
'use strict';

const spawn = require('child_process').spawn;
const fetch = require('node-fetch-v2');

const portFinder = require('../test_util/portfinder');
const path = require('path');
const _ = require('lodash');
Expand Down
1 change: 0 additions & 1 deletion packages/collector/test/apps/expressControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

'use strict';

const fetch = require('node-fetch-v2');
const fs = require('fs');
const path = require('path');
const spawn = require('child_process').spawn;
Expand Down
1 change: 0 additions & 1 deletion packages/collector/test/immediate/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const { expect } = require('chai');
const { spawn } = require('child_process');
const _ = require('lodash');
const portfinder = require('../test_util/portfinder');
const fetch = require('node-fetch-v2');

const config = require('../../../core/test/config');
const { delay, retry } = require('../../../core/test/test_util');
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 54 additions & 23 deletions packages/collector/test/test_util/ProcessControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const _ = require('lodash');
const fork = require('child_process').fork;
const fs = require('fs');
const path = require('path');
const fetch = require('node-fetch-v2');

const config = require('../../../core/test/config');
const http2Promise = require('./http2Promise');
Expand Down Expand Up @@ -346,34 +345,66 @@ class ProcessControls {
requestOpts.headers['Content-Type'] = 'application/json';
}

let response;
const result = await fetch(requestOpts.url, requestOpts);
const contentType = result.headers.get('content-type');
// Handle timeout using AbortController (native fetch doesn't support timeout option directly)
let timeoutId;
if (requestOpts.timeout) {
const controller = new AbortController();
requestOpts.signal = controller.signal;

if (contentType && contentType.includes('application/json')) {
response = await result.json();
} else if (contentType && (contentType.includes('text/html') || contentType.includes('text/plain'))) {
response = await result.text();
} else {
// CASE: Some tests do not use express and then the header is missing
// Some tests use `res.send`, which is not a JSON response.
response = await result.text();
timeoutId = setTimeout(() => {
controller.abort();
}, requestOpts.timeout);
}

if (checkStatusCode) {
if (result.status < 200 || result.status >= 300) {
throw new Error(response);
let response;
try {
const result = await fetch(requestOpts.url, requestOpts);

// Clear timeout if request completes successfully
if (timeoutId) {
clearTimeout(timeoutId);
}
}

if (resolveWithFullResponse) {
return {
headers: result.headers,
body: response
};
}
const contentType = result.headers.get('content-type');

if (contentType && contentType.includes('application/json')) {
response = await result.json();
} else if (contentType && (contentType.includes('text/html') || contentType.includes('text/plain'))) {
response = await result.text();
} else {
// CASE: Some tests do not use express and then the header is missing
// Some tests use `res.send`, which is not a JSON response.
response = await result.text();
}

if (checkStatusCode) {
if (result.status < 200 || result.status >= 300) {
throw new Error(response);
}
}

if (resolveWithFullResponse) {
return {
headers: result.headers,
body: response
};
}

return response;
} catch (err) {
if (timeoutId) {
clearTimeout(timeoutId);
}

return response;
if (err.name === 'AbortError') {
const timeoutError = new Error('Request timeout');
timeoutError.type = 'request-timeout';
timeoutError.error = { code: 'ETIMEDOUT' };
throw timeoutError;
}

throw err;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

require('../../../../../src')();
const agentPort = process.env.INSTANA_AGENT_PORT;
const fetch = require('node-fetch-v2');

const delay = require('@instana/core/test/test_util/delay');

const AWS = require('aws-sdk');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ process.on('SIGTERM', () => {

require('../../../../../..')();
const agentPort = process.env.INSTANA_AGENT_PORT;
const fetch = require('node-fetch-v2');

const delay = require('../../../../../../../core/test/test_util/delay');

const AWS = require('aws-sdk');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ process.on('SIGTERM', () => {
});

const agentPort = process.env.INSTANA_AGENT_PORT;
import fetch from 'node-fetch';

import delay from '../../../../../../../core/test/test_util/delay.js';
import getAppPort from '../../../../../test_util/app-port.js';
import logger from '@instana/core/test/test_util/log.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const app = express();
const port = require('../../../../../test_util/app-port')();
const streamName = process.env.AWS_KINESIS_STREAM_NAME || 'nodejs-team';
const agentPort = process.env.INSTANA_AGENT_PORT;
const fetch = require('node-fetch-v2');

const AWS = require('aws-sdk');
const logPrefix = `AWS SDK v2 Kinesis (${process.pid}):\t`;
const log = require('@instana/core/test/test_util/log').getLogger(logPrefix);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import getAppPort from '../../../../../test_util/app-port.js';
const port = getAppPort();
const streamName = process.env.AWS_KINESIS_STREAM_NAME || 'nodejs-team';
const agentPort = process.env.INSTANA_AGENT_PORT;
import fetch from 'node-fetch';

import AWS from 'aws-sdk';
const logPrefix = `AWS SDK v2 Kinesis (${process.pid}):\t`;
import log from '@instana/core/test/test_util/log.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ process.on('SIGTERM', () => {

require('../../../../../..')();
const agentPort = process.env.INSTANA_AGENT_PORT;
const fetch = require('node-fetch-v2');

const delay = require('../../../../../../../core/test/test_util/delay');

const AWS = require('aws-sdk');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ process.on('SIGTERM', () => {
});

const agentPort = process.env.INSTANA_AGENT_PORT;
import fetch from 'node-fetch';

import delay from '../../../../../../../core/test/test_util/delay.js';
import AWS from 'aws-sdk';
import express from 'express';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ process.on('SIGTERM', () => {

require('../../../../../..')();
const agentPort = process.env.INSTANA_AGENT_PORT;
const fetch = require('node-fetch-v2');

const delay = require('@instana/core/test/test_util/delay');

const AWS = require('aws-sdk');
Expand Down
Loading