-
Notifications
You must be signed in to change notification settings - Fork 619
test(instrumentation-aws-sdk): update devDeps to modern version of instrumented packages #2723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(instrumentation-aws-sdk): update devDeps to modern version of instrumented packages #2723
Conversation
…strumented packages This flips the usage of 'npm test' and 'npm run test-all-versions' so that the former uses recent versions of the instrumented packages. This allows updating devDeps to the latest. 'npm test' will *skip* tests for older versions of node that aren't supported by the latest version of the instrumented packages. Testing all the old versions (of node and instrumented packages) is left to 'npm run test-all-versions' (TAV). Refs: open-telemetry#2722
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2723 +/- ##
==========================================
+ Coverage 91.53% 91.86% +0.33%
==========================================
Files 171 171
Lines 8172 8172
Branches 1660 1660
==========================================
+ Hits 7480 7507 +27
+ Misses 692 665 -27 🚀 New features to boost your workflow:
|
alternative attempted: top-level "skip this test file" logicAn alternative I've used before is to have a top-level if-block in a give test file that just exited if the node version was too old for the given version of the module, e.g.: However, this cannot work with alternative attempted: load dep in try/catchI made another attempt to load the devDep in a try/catch, then have each mocha test block Example diff--- a/plugins/node/opentelemetry-instrumentation-aws-sdk/test/s3.test.ts
+++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/test/s3.test.ts
@@ -22,7 +22,17 @@ import { AwsInstrumentation } from '../src';
import { AttributeNames } from '../src/enums';
registerInstrumentationTesting(new AwsInstrumentation());
-import { PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
+// Skip tests, rather than crashing, if this import fails.
+let PutObjectCommand: unknown;
+let S3Client: unknown;
+try {
+ const mod = require('@aws-sdk/client-s3');
+ PutObjectCommand = mod.PutObjectCommand;
+ S3Client = mod.S3Client;
+} catch {
+ // Assuming the failure is due to this Node.js and aws-sdk being incompatible.
+}
+
import * as fs from 'fs';
import * as nock from 'nock';
@@ -33,6 +43,14 @@ import { expect } from 'expect';
const region = 'us-east-1';
describe('S3 - v3', () => {
+ beforeEach(function () {
+ if (!S3Client) {
+ // Skip because, presumably, the current version of node is too low to
+ // to support this version of `@aws-sdk/client-s3`.
+ this.skip();
+ }
+ });
+
describe('PutObject', () => {
it('Request span attributes - adds bucket Name', async () => {
const dummyBucketName = 'ot-demo-test';This is code-heavy because of the scoping of the loaded vars. Also potentially having to add the The main hurdle that stopped me here was when types are imported from the instrumented module, e.g.: opentelemetry-js-contrib/plugins/node/opentelemetry-instrumentation-aws-sdk/test/aws-sdk-v3.test.ts Line 30 in 8a5c214
Note that in the diff above I am using |
|
^ hup the pkg: label to get TAV tests to run. |
|
Suggesting an alternative. In the past, we used to have something like this in the github workflow yaml: and then when executing the test, we run them with this flag: This would prevent running the tests for specific packages on incompatible node versions (only in CI but that can be good enough until we drop support for old node versions). |
…_DISABLE Previous name was from an earlier rev of this PR. I've verified that SKIP_TEST_IF_DISABLE usage in .tav.yml works as expected.
We discussed this a while back offline. My argument against this was:
|
|
Now that I fixed usage of Reproduced locally: The issue here is that each of the AWS SDK JS v3 clients (
Options:
Option 2 is certainly easier than option 1, if it works, but less "correct". |
…o that TAV config can target one at a time
commit 122a8fe does this option 1. |
…settings (that were accidentally included from *other* test files -- named AWS_ auth-related envvars from aws-sdk-v3.test.js) need to be set to avoid this credentials error:
CredentialsProviderError: Could not load credentials from any providers
at .../node_modules/@aws-sdk/client-s3/node_modules/@aws-sdk/credential-provider-node/dist-cjs/index.js:129:13
| // set aws environment variables, so tests in non aws environment are able to run | ||
| process.env.AWS_ACCESS_KEY_ID = 'testing'; | ||
| process.env.AWS_SECRET_ACCESS_KEY = 'testing'; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewer note: Now that .tav.yml is running this test file alone (mocha ... test/sqs.test.ts), instead of with all the other test files (in the same process), this now needs to set AWS_ auth-related envvars to avoid a client error. When running all the test files (mocha ... 'test/**/*.test.ts'), then those envvars were being set in "test/aws-sdk-v3.test.ts" and solving the auth-related issue for all the test files).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewer note: "test/aws-sdk-v3.test.ts" was broken into separate test files that each only test a single @aws-sdk/client-* client. This allows TAV (test-all-versions) to work properly when it is varying the installed version of a single client package at a time.
This was added in open-telemetry#2723 and missed during rebase
This was added in open-telemetry#2723 and missed during rebase
… is no longer necessary With JS SDK 2.0 the min supported Node.js is v18, which suffices for the latest instrumented deps currently being used.
…strumented packages (open-telemetry#2723) This flips the usage of 'npm test' and 'npm run test-all-versions' so that the former uses recent versions of the instrumented packages. This allows updating devDeps to the latest. 'npm test' will skip tests for older versions of node that aren't supported by the latest version of the instrumented packages. Testing all the old versions (of node and instrumented packages) is left to 'npm run test-all-versions' (TAV). Refs: open-telemetry#2722
This flips the usage of 'npm test' and 'npm run test-all-versions' so that
the former uses recent versions of the instrumented packages. This allows
updating devDeps to the latest. 'npm test' will skip tests for older
versions of node that aren't supported by the latest version of the
instrumented packages.
Testing all the old versions (of node and instrumented packages) is
left to 'npm run test-all-versions' (TAV).
Refs: #2722
skipping tests on older Node.js versions is awkward
The mechanism proposed here to skip running tests in
npm testfor older Node.js versions is to use a preload script viamocha --require ...(as is already being used for TS-to-JS transpilation) and a config envvar to state the min supported Node.js version. Effectively this:That preload "skip-test-if.js" will
process.exit(0)to skip tests.I'll mention some alternatives attempted in comments below.