Skip to content

Commit 2b2c7e3

Browse files
authored
test: fix testing for @elastic/elasticsearch version 9 (#4583)
`@elastic/[email protected]` was released recently. This updates our testing to pass with it. So far no instrumentation changes were necessary. (I'm not sure if testing with v9 of the client would have failed with the older 8.7.1 version of the server that we had been using.) Also reduce the number of ES client versions tested. Obsoletes: #4576
1 parent cd398aa commit 2b2c7e3

File tree

9 files changed

+111
-178
lines changed

9 files changed

+111
-178
lines changed

.ci/docker/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ services:
7474
retries: 30
7575

7676
elasticsearch:
77-
image: docker.elastic.co/elasticsearch/elasticsearch:8.7.1
77+
image: docker.elastic.co/elasticsearch/elasticsearch:9.0.0
7878
environment:
7979
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
8080
- "network.host=_site_"

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ jobs:
104104
- nodemssqldata:/var/opt/mssql
105105

106106
elasticsearch:
107-
image: docker.elastic.co/elasticsearch/elasticsearch:8.7.1
107+
image: docker.elastic.co/elasticsearch/elasticsearch:9.0.0
108108
env:
109109
ES_JAVA_OPTS: '-Xms512m -Xmx512m'
110110
network.host: '_site_'

.tav.yml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,18 +267,32 @@ elasticsearch:
267267
# semver (and TAV) consider "-patch.N" to be a *prereleases*. This
268268
# leads to some tortured "versions:" ranges below.
269269
# - Version 8.11.0 dropped node v14 and v16 support.
270+
# - Version 9 dropped v18 support (effectively by using undici@7).
270271
'@elastic/elasticsearch':
271-
- versions: '>=7.0.0 <7.7.0 || >7.7.0 <7.12.0'
272+
- versions:
273+
mode: max-3
274+
include: '>=7.0.0 <7.7.0 || >7.7.0 <7.12.0'
272275
commands: node test/instrumentation/modules/@elastic/elasticsearch.test.js
273-
- versions: '>=7.12.0 <8.2'
276+
- versions:
277+
mode: max-3
278+
include: '>=7.12.0 <8.2'
274279
node: '>=12.0.0'
275280
commands: node test/instrumentation/modules/@elastic/elasticsearch.test.js
276-
- versions: '>=8.2.0-patch.1 <8.2.0 || >8.2.0 <8.11.0'
281+
- versions:
282+
mode: max-3
283+
include: '>8.2.0 <8.11.0'
277284
node: '>=14.0.0'
278285
commands: node test/instrumentation/modules/@elastic/elasticsearch.test.js
279-
- versions: '>=8.11.0'
286+
- versions:
287+
mode: max-5
288+
include: '>=8.11.0 <9.0.0'
280289
node: '>=18.0.0'
281290
commands: node test/instrumentation/modules/@elastic/elasticsearch.test.js
291+
- versions:
292+
mode: max-5
293+
include: '>=9.0.0 <10'
294+
node: '>=20.0.0'
295+
commands: node test/instrumentation/modules/@elastic/elasticsearch.test.js
282296

283297
handlebars:
284298
versions:
Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,20 @@
66
* compliance with the BSD 2-Clause License.
77
*/
88

9-
// A small example showing Elastic APM tracing @elastic/elasticsearch version 8.
9+
// A small example showing Elastic APM tracing @elastic/elasticsearch.
1010
//
1111
// This assumes an Elasticsearch running on localhost. You can use:
1212
// npm run docker:start elasticsearch
1313
// to start an Elasticsearch docker container. Then the following to stop:
1414
// npm run docker:stop
1515

1616
const apm = require('../').start({
17-
serviceName: 'example-trace-elasticsearch8',
17+
serviceName: 'example-trace-elasticsearch',
1818
});
1919

20-
// eslint-disable-next-line no-unused-vars
21-
const { Client, HttpConnection } = require('@elastic/elasticsearch');
20+
const { Client } = require('@elastic/elasticsearch');
2221

2322
const client = new Client({
24-
// By default version 8 uses the new undici HTTP client lib. You can specify
25-
// `HttpConnection` to use the older HTTP client.
26-
// Connection: HttpConnection,
27-
2823
node: process.env.ES_URL || 'http://localhost:9200',
2924
auth: {
3025
username: process.env.ES_USERNAME || undefined,
@@ -33,7 +28,7 @@ const client = new Client({
3328
maxRetries: 1,
3429
});
3530

36-
async function run() {
31+
async function main() {
3732
// For tracing spans to be created, there must be an active transaction.
3833
// Typically, a transaction is automatically started for incoming HTTP
3934
// requests to a Node.js server. However, because this script is not running
@@ -75,25 +70,23 @@ async function run() {
7570
t2.end();
7671
});
7772

78-
// Example aborting requests using AbortController (node v15 and above).
79-
if (global.AbortController) {
80-
const t3 = apm.startTransaction('t3');
81-
const ac = new AbortController(); // eslint-disable-line no-undef
82-
setImmediate(() => {
83-
ac.abort();
84-
});
85-
try {
86-
const res = await client.search(
87-
{ query: { match_all: {} } },
88-
{ signal: ac.signal },
89-
);
90-
console.log('[example 3] search response:', res);
91-
} catch (err) {
92-
console.log('[example 3] search error:', err);
93-
} finally {
94-
t3.end();
95-
}
73+
// Example aborting requests using AbortController.
74+
const t3 = apm.startTransaction('t3');
75+
const ac = new AbortController(); // eslint-disable-line no-undef
76+
setImmediate(() => {
77+
ac.abort();
78+
});
79+
try {
80+
const res = await client.search(
81+
{ query: { match_all: {} } },
82+
{ signal: ac.signal },
83+
);
84+
console.log('[example 3] search response:', res);
85+
} catch (err) {
86+
console.log('[example 3] search error:', err);
87+
} finally {
88+
t3.end();
9689
}
9790
}
9891

99-
run();
92+
main();

examples/trace-elasticsearch7.js

Lines changed: 0 additions & 85 deletions
This file was deleted.

0 commit comments

Comments
 (0)