Skip to content

Commit 0e59a23

Browse files
authored
feat: support node v17 (#2380)
There were a few changes (in mongodb instrumentation) and tests to deal with `localhost` resolving to a IPv6 due to this change in node v17 nodejs/node#39987
1 parent e08ae4e commit 0e59a23

File tree

11 files changed

+36
-20
lines changed

11 files changed

+36
-20
lines changed

.ci/.jenkins_nightly_nodejs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
# made, these will stop and there will be no value in testing v17 nightlies.
1010
#
1111
NODEJS_VERSION:
12-
- "17"
12+
- "18"

.ci/.jenkins_nodejs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
NODEJS_VERSION:
2+
- "17"
23
- "16"
34
- "16.0"
45
- "14"

.ci/.jenkins_tav_nodejs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
NODEJS_VERSION:
2+
- "17"
23
- "16"
34
- "14"
45
- "12"

.github/workflows/test.yml

+2
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ jobs:
120120
strategy:
121121
matrix:
122122
node:
123+
- '17'
123124
- '16'
124125
- '16.0'
125126
- '14'
@@ -138,4 +139,5 @@ jobs:
138139
node-version: ${{ matrix.node }}
139140
- run: docker ps # show the services against which we'll be testing
140141
- run: npm install
142+
- run: npm ls --all || true
141143
- run: npm test

CHANGELOG.asciidoc

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Notes:
3737
[float]
3838
===== Features
3939
40+
* Add support for node v17.
41+
4042
* When an error is captured, the APM agent will only immediately flush it to
4143
APM server if it is an "unhandled" error. Unhandled errors are typically those
4244
captured via the `uncaughtException` process event. Before this change, a

lib/instrumentation/modules/mongodb.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
const semver = require('semver')
44
const { getDBDestination } = require('../context')
55

6-
// Match expected `<hostname>:<port>`.
7-
const HOSTNAME_PORT_RE = /^([^:]+):(\d+)$/
6+
// Match expected `<hostname>:<port>`, e.g. "mongo:27017", "::1:27017",
7+
// "127.0.0.1:27017".
8+
const HOSTNAME_PORT_RE = /^(.+):(\d+)$/
89

910
module.exports = (mongodb, agent, { version, enabled }) => {
1011
if (!enabled) return mongodb

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"url": "git://github.com/elastic/apm-agent-nodejs.git"
4444
},
4545
"engines": {
46-
"node": "^8.6.0 || 10 || 12 || 14 || 15 || 16"
46+
"node": "^8.6.0 || 10 || 12 || 14 || 15 || 16 || 17"
4747
},
4848
"keywords": [
4949
"opbeat",

test/instrumentation/modules/fastify/_async-await.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ test('transaction name', function (t) {
3030

3131
fastify.listen(0, function (err, address) {
3232
t.error(err)
33-
address = address || 'http://localhost:' + fastify.server.address().port
33+
address = 'http://localhost:' + fastify.server.address().port
3434
http.get(`${address}/hello/world`, function (res) {
3535
const chunks = []
3636
res.on('data', chunks.push.bind(chunks))
@@ -81,7 +81,7 @@ if (semver.gte(fastifyVersion, '2.0.0-rc')) {
8181

8282
fastify.listen(0, function (err, address) {
8383
t.error(err)
84-
http.get(`${address}/hello/world`, function (res) {
84+
http.get(`http://localhost:${fastify.server.address().port}/hello/world`, function (res) {
8585
const chunks = []
8686
res.on('data', chunks.push.bind(chunks))
8787
res.on('end', function () {

test/instrumentation/modules/hapi/shared.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ module.exports = (moduleName) => {
77
captureExceptions: false,
88
logLevel: 'fatal',
99
metricsInterval: 0,
10-
centralConfig: false
10+
centralConfig: false,
11+
cloudProvider: 'none'
1112
})
1213

1314
var isHapiIncompat = require('../../../_is_hapi_incompat')
@@ -48,7 +49,7 @@ module.exports = (moduleName) => {
4849
agent.captureError = originalCaptureError
4950

5051
var server = startServer(function (err, port) {
51-
t.error(err)
52+
t.error(err, 'no error from startServer')
5253
http.get('http://localhost:' + port + '/captureError?foo=bar')
5354
})
5455
})
@@ -523,7 +524,7 @@ module.exports = (moduleName) => {
523524
})
524525

525526
function makeServer (opts) {
526-
var server = new Hapi.Server()
527+
var server = new Hapi.Server({ host: 'localhost' })
527528
if (semver.satisfies(pkg.version, '<17')) {
528529
server.connection(opts)
529530
}

test/instrumentation/modules/http2.test.js

+18-10
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ isSecure.forEach(secure => {
2525
var method = secure ? 'createSecureServer' : 'createServer'
2626

2727
test(`http2.${method} compatibility mode`, t => {
28-
t.plan(15)
28+
t.plan(16)
2929

3030
// Note NODE_OPTIONS env because it sometimes has a setting relevant
3131
// for this test.
@@ -71,7 +71,7 @@ isSecure.forEach(secure => {
7171
})
7272

7373
test(`http2.${method} stream respond`, t => {
74-
t.plan(15)
74+
t.plan(16)
7575

7676
resetAgent((data) => {
7777
assert(t, data, secure, port)
@@ -114,7 +114,7 @@ isSecure.forEach(secure => {
114114
})
115115

116116
test(`http2.${method} stream respondWithFD`, t => {
117-
t.plan(16)
117+
t.plan(17)
118118

119119
resetAgent((data) => {
120120
assert(t, data, secure, port)
@@ -164,7 +164,7 @@ isSecure.forEach(secure => {
164164
})
165165

166166
test(`http2.${method} stream respondWithFile`, t => {
167-
t.plan(15)
167+
t.plan(16)
168168

169169
resetAgent((data) => {
170170
assert(t, data, secure, port)
@@ -278,7 +278,7 @@ isSecure.forEach(secure => {
278278
})
279279

280280
test(`http2.request${secure ? ' secure' : ' '}`, t => {
281-
t.plan(34)
281+
t.plan(36)
282282

283283
resetAgent(3, (data) => {
284284
t.strictEqual(data.transactions.length, 2)
@@ -478,17 +478,25 @@ function assertPath (t, trans, secure, port, path, httpVersion) {
478478
}
479479
break
480480
}
481-
// Sometime between node (v8.6.0, v8.17.0] there was a fix such that
482-
// socket.remoteAddress was set properly for https.
483-
const expectedRemoteAddress = httpVersion === '1.1' && semver.lt(process.version, '8.17.0')
484-
? undefined : '::ffff:127.0.0.1'
481+
482+
// What is "expected" for transaction.context.request.socket.remote_address
483+
// is a bit of a pain.
484+
if (httpVersion === '1.1' && semver.lt(process.version, '8.17.0')) {
485+
// Before node v8.17.0 `socket.remoteAddress` was not set for https.
486+
t.pass(`skip checking on transaction.context.request.socket.remote_address on node ${process.version}`)
487+
} else {
488+
// With node v17 on Linux (or at least on the linux containers used for
489+
// GitHub Action tests), the localhost socket.remoteAddress is "::1".
490+
t.ok(trans.context.request.socket.remote_address === '::ffff:127.0.0.1' || trans.context.request.socket.remote_address === '::1',
491+
'transaction.context.request.socket.remote_address is as expected: ' + trans.context.request.socket.remote_address)
492+
}
493+
delete trans.context.request.socket.remote_address
485494

486495
t.deepEqual(trans.context.request, {
487496
http_version: httpVersion,
488497
method: 'GET',
489498
url: expectedUrl,
490499
socket: {
491-
remote_address: expectedRemoteAddress,
492500
encrypted: secure
493501
},
494502
headers: expectedReqHeaders

test/script/run_tests.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fi
6969
# Skip for node v8 because it results in this warning:
7070
# openssl config failed: error:25066067:DSO support routines:DLFCN_LOAD:could not load the shared library
7171
if [[ $major_node_version -gt 8 ]]; then
72-
export NODE_OPTIONS="$NODE_OPTIONS --openssl-config=./test/openssl-config-for-testing.cnf"
72+
export NODE_OPTIONS="$NODE_OPTIONS --openssl-config=$(pwd)/test/openssl-config-for-testing.cnf"
7373
fi
7474

7575
if [[ "$CI" || "$1" == "none" ]]

0 commit comments

Comments
 (0)