Skip to content

Commit a7ef787

Browse files
trentmPeterEinberger
authored andcommitted
test: convert sqs.test.js over to use localstack for end-to-end tests (similar to s3.test.js) (elastic#3334)
- update to the latest localstack - restore testing of recent releases of aws-sdk (skipping the "bad" 2.1372.0 release that attempted to switch SQS over to the new "JSON protocol") - changes the SQS "integration tests" to run use-sqs.js against localstack, instead of just against a local mock SQS server with canned responses Fixes: elastic#3324
1 parent 4635b4e commit a7ef787

File tree

15 files changed

+498
-802
lines changed

15 files changed

+498
-802
lines changed

.ci/docker/docker-compose.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,13 @@ services:
119119

120120
localstack:
121121
# https://hub.docker.com/r/localstack/localstack/tags
122-
image: localstack/localstack:0.12.12
122+
image: localstack/localstack:2.1.0
123123
environment:
124-
- LOCALSTACK_SERVICES=s3
125124
- DATA_DIR=/var/lib/localstack
126125
ports:
127126
- "4566:4566"
128127
healthcheck:
129-
test: ["CMD", "curl", "-f", "http://localhost:4566/health"]
128+
test: ["CMD", "curl", "-f", "http://localhost:4566/_localstack/health"]
130129
interval: 30s
131130
timeout: 10s
132131
retries: 5

.github/workflows/test.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,8 @@ jobs:
114114
- nodeesdata:/usr/share/elasticsearch/data
115115

116116
localstack:
117-
image: localstack/localstack:0.12.12
117+
image: localstack/localstack:2.1.0
118118
env:
119-
LOCALSTACK_SERVICES: 's3'
120119
DATA_DIR: '/var/lib/localstack'
121120
ports:
122121
- "4566:4566"

.tav.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -496,20 +496,19 @@ memcached:
496496

497497
aws-sdk:
498498
# We want this version range:
499-
# versions: '>=2.858 <3'
499+
# versions: '>=2.858 <2.1372.0 || >2.1372.0 <3'
500500
# However, awk-sdk releases *very* frequently (almost every day) and there
501501
# is no need to test *all* those releases. Instead we statically list a subset
502502
# of versions to test.
503503
#
504+
# - v2.1372.0 changed the SQS client protocol from "query" to "json", which
505+
# isn't supported in localstack. It was reverted in v2.1373.0.
506+
#
504507
# Maintenance note: This should be updated periodically using:
505508
# ./dev-utils/aws-sdk-tav-versions.sh
506509
#
507-
# Test v2.858.0, every N=102 of 515 releases, and current latest.
508-
#
509-
# Workaround note: Until localstack supports SQS using the JSON protocol
510-
# we cannot test against >=2.1372.0. Cap the versions tested for now.
511-
# See https://github.com/elastic/apm-agent-nodejs/issues/3324
512-
versions: '2.858.0 || 2.960.0 || 2.1062.0 || 2.1164.0 || 2.1266.0 || 2.1368.0 || 2.1371.0'
510+
# Test v2.858.0, every N=108 of 542 releases, and current latest.
511+
versions: '2.858.0 || 2.966.0 || 2.1074.0 || 2.1182.0 || 2.1290.0 || 2.1399.0 || 2.1400.0 || >2.1400.0 <3'
513512
commands:
514513
- node test/instrumentation/modules/aws-sdk/aws4-retries.test.js
515514
- node test/instrumentation/modules/aws-sdk/s3.test.js

dev-utils/aws-sdk-tav-versions.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
npm info -j aws-sdk | node -e '
1010
var semver = require("semver");
1111
var chunks = [];
12+
var wantVerRange = ">=2.858 <2.1372.0 || >2.1372.0 <3"
1213
process.stdin
1314
.resume()
1415
.on("data", (chunk) => { chunks.push(chunk) })
1516
.on("end", () => {
1617
var input = JSON.parse(chunks.join(""));
17-
var vers = input.versions.filter(v => semver.satisfies(v, ">=2.858.0 <3"));
18+
var vers = input.versions.filter(v => semver.satisfies(v, wantVerRange));
1819
var modulus = Math.floor((vers.length - 2) / 5);
1920
console.log(" # Test v2.858.0, every N=%d of %d releases, and current latest.", modulus, vers.length);
2021
vers = vers.filter((v, idx, arr) => idx % modulus === 0 || idx === arr.length - 1);

docs/supported-technologies.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ The Node.js agent will automatically instrument the following modules to give yo
139139
[options="header"]
140140
|=======================================================================
141141
|Module |Version |Note
142-
|https://www.npmjs.com/package/aws-sdk[aws-sdk] |>1 <3 |Will instrument SQS send/receive/delete messages, all S3 methods, all DynamoDB methods, and the SNS publish method
142+
|https://www.npmjs.com/package/aws-sdk[aws-sdk] |>=2.858.0 <3 |Will instrument SQS send/receive/delete messages, all S3 methods, all DynamoDB methods, and the SNS publish method
143143
|https://www.npmjs.com/package/@aws-sdk/client-s3[@aws-sdk/client-s3] |>=3.15.0 <4 |Will instrument all S3 methods
144144
|https://www.npmjs.com/package/cassandra-driver[cassandra-driver] |>=3.0.0 <5 |Will instrument all queries
145145
|https://www.npmjs.com/package/elasticsearch[elasticsearch] |>=8.0.0 |Will instrument all queries

examples/trace-sqs-send-message.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,16 @@ sqs.getQueueUrl({ QueueName: queueName }, function (err, data) {
6666
const queueUrl = data.QueueUrl
6767
// console.log('queueUrl:', queueUrl)
6868

69+
const rand = Math.random()
6970
const params = {
7071
QueueUrl: queueUrl,
71-
MessageBody: `this is my message (${Math.random()})`,
72+
MessageBody: `this is my message (${rand}})`,
7273
MessageAttributes: {
7374
foo: { DataType: 'String', StringValue: 'bar' }
74-
}
75+
},
76+
// Only used for FIFO queues.
77+
MessageGroupId: 'example-trace-sqs',
78+
MessageDeduplicationId: rand.toString()
7579
}
7680
console.log('Sending message with body: %j', params.MessageBody)
7781
sqs.sendMessage(params, function (err, data) {

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"lint:tav": "./dev-utils/lint-tav-json.js",
1717
"coverage": "COVERAGE=true ./test/script/run_tests.sh",
1818
"test": "./test/script/run_tests.sh",
19-
"test:deps": "dependency-check index.js start.js start-next.js 'lib/**/*.js' 'test/**/*.js' '!test/activation-method/fixtures' '!test/instrumentation/azure-functions/fixtures' '!test/instrumentation/modules/next/a-nextjs-app' '!test/opentelemetry-bridge' '!test/opentelemetry-metrics/fixtures' --no-dev -i async_hooks -i perf_hooks -i node:http -i @azure/functions-core -i worker_threads",
19+
"test:deps": "dependency-check index.js start.js start-next.js 'lib/**/*.js' 'test/**/*.js' '!test/activation-method/fixtures' '!test/instrumentation/azure-functions/fixtures' '!test/instrumentation/modules/next/a-nextjs-app' '!test/opentelemetry-bridge' '!test/opentelemetry-metrics/fixtures' --no-dev -i async_hooks -i perf_hooks -i node:http -i @azure/functions-core -i worker_threads -i timers",
2020
"test:tav": "(cd test/opentelemetry-metrics/fixtures && tav --quiet) && (cd test/opentelemetry-bridge && tav --quiet) && (cd test/instrumentation/modules/next/a-nextjs-app && tav --quiet) && tav --quiet",
2121
"test:types": "tsc --project test/types/tsconfig.json && tsc --project test/types/transpile/tsconfig.json && node test/types/transpile/index.js && tsc --project test/types/transpile-default/tsconfig.json && node test/types/transpile-default/index.js # requires node >=14.17",
2222
"test:babel": "babel test/babel/src.js --out-file test/babel/out.js && cd test/babel && node out.js",
@@ -136,7 +136,7 @@
136136
"ajv": "^7.2.4",
137137
"apollo-server-core": "^3.0.0",
138138
"apollo-server-express": "^3.0.0",
139-
"aws-sdk": "^2.622.0",
139+
"aws-sdk": "^2.1400.0",
140140
"backport": "^5.1.2",
141141
"benchmark": "^2.1.4",
142142
"bluebird": "^3.7.2",

test/docker-compose.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,13 @@ services:
119119

120120
localstack:
121121
# https://hub.docker.com/r/localstack/localstack/tags
122-
image: localstack/localstack:0.12.12
122+
image: localstack/localstack:2.1.0
123123
environment:
124-
- "LOCALSTACK_SERVICES=s3"
125124
- "DATA_DIR=/var/lib/localstack"
126125
ports:
127126
- "4566:4566"
128127
healthcheck:
129-
test: ["CMD", "curl", "-f", "http://localhost:4566/health"]
128+
test: ["CMD", "curl", "-f", "http://localhost:4566/_localstack/health"]
130129
interval: 30s
131130
timeout: 10s
132131
retries: 5

test/instrumentation/modules/@aws-sdk/client-s3.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ tape.test('simple S3 V3 usage scenario', function (t) {
130130
cloud: { region: 'us-east-2' },
131131
service: { type: '', name: '', resource: 's3' }
132132
},
133-
http: { status_code: 200 }
133+
http: { status_code: 200, response: { encoded_body_size: 222 } }
134134
},
135135
outcome: 'success'
136136
}, 'listAllBuckets produced expected span')
@@ -148,7 +148,7 @@ tape.test('simple S3 V3 usage scenario', function (t) {
148148
cloud: { region: 'us-east-2' },
149149
service: { type: '', name: '', resource: 'elasticapmtest-bucket-3' }
150150
},
151-
http: { status_code: 200, response: { encoded_body_size: 177 } }
151+
http: { status_code: 200, response: { encoded_body_size: 61 } }
152152
},
153153
otel: {
154154
attributes: { 'aws.s3.bucket': 'elasticapmtest-bucket-3' }
@@ -190,7 +190,7 @@ tape.test('simple S3 V3 usage scenario', function (t) {
190190
cloud: { region: 'us-east-2' },
191191
service: { type: '', name: '', resource: 'elasticapmtest-bucket-3' }
192192
},
193-
http: { status_code: 200, response: { encoded_body_size: 0 } }
193+
http: { status_code: 200, response: { encoded_body_size: 58 } }
194194
},
195195
otel: {
196196
attributes: {
@@ -315,7 +315,7 @@ tape.test('simple S3 V3 usage scenario', function (t) {
315315
cloud: { region: 'us-east-2' },
316316
service: { type: '', name: '', resource: 'elasticapmtest-bucket-3' }
317317
},
318-
http: { status_code: 204, response: { encoded_body_size: 0 } }
318+
http: { status_code: 204 }
319319
},
320320
otel: {
321321
attributes: {
@@ -339,7 +339,7 @@ tape.test('simple S3 V3 usage scenario', function (t) {
339339
cloud: { region: 'us-east-2' },
340340
service: { type: '', name: '', resource: 'elasticapmtest-bucket-3' }
341341
},
342-
http: { status_code: 204, response: { encoded_body_size: 0 } }
342+
http: { status_code: 204 }
343343
},
344344
otel: {
345345
attributes: { 'aws.s3.bucket': 'elasticapmtest-bucket-3' }

test/instrumentation/modules/aws-sdk/fixtures/sqs.js

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

test/instrumentation/modules/aws-sdk/fixtures/use-s3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const apm = require('../../../../..').start({
4444
serviceName: 'use-s3',
4545
captureExceptions: false,
4646
centralConfig: false,
47-
metricsInterval: 0,
47+
metricsInterval: '0s',
4848
cloudProvider: 'none',
4949
stackTraceLimit: 4, // get it smaller for reviewing output
5050
logLevel: 'info'

0 commit comments

Comments
 (0)