Skip to content
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

CUMULUS-3433 - Update to nodeJs v20 #3636

Merged
merged 32 commits into from Apr 30, 2024
Merged

Conversation

Jkovarik
Copy link
Member

@Jkovarik Jkovarik commented Apr 25, 2024

Summary: Summary of changes

Addresses CUMULUS-3433: Develop amazing new feature

Changes

  • CUMULUS-3433
    • Added importGot helper method to import got as an ESM module in
      CommmonJS typescript/webpack clients.
  • CUMULUS-3433

Reviewers, please note this PR is still in-work in that the following need to occur:

PR Checklist

  • Update CHANGELOG
  • Unit tests
  • Ad-hoc testing - Deploy changes and test manually
  • Integration tests

.sort is intermittently failing to order as expected, causing this
test to fail in local test at an alarming failure rate.    Updating
test to be more explicit/remove sort, however this needs to be
investigated prior to closing thie branch/PR/ticket
JSON.parse now throws a different error for the merged test case.
This reverts commit a19f9d1.
This reverts commit e652516.
This update has a couple of controversial changes in it:

Updating got to v14 means we're using a pure ESM module given sindre's
stance on not supporting common exports.  That's being done due to
incompatible changes in node streams requires at least got v12

Additionally there's a probable outstanding issue in got
sindresorhus/got#2341 related to node v20/fs
readstreams/nock and/or msw incompatibility (as well as a possible
open source contrib)
Updating the existing apache server to return 200 on an existing
endpoint is far better than the prior commit approach in that it's a
valid/useful unit test as a result, with the technical/less tidy
downside of requiring the unit test stack to be working.
- 5432:5432
- 8080:8080
- 9200:9200
- "127.0.0.1:20:20"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a security update to disallow port access from hosts other than localhost.

@@ -388,6 +389,15 @@ LogLevel warn
#Scriptsock cgisock
</IfModule>


### Configuration to allow PUT endpoint
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updates Apache server to have a dummy response to HTTP POST

@@ -350,7 +350,7 @@ variable "rds_admin_access_secret_arn" {
variable "async_operation_image_version" {
description = "docker image version to use for Cumulus async operations tasks"
type = string
default = "48"
default = "49"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test image from changes in this PR was pushed up to v49 in sandbox

]
);
t.deepEqual(loggerWarnStub.args[0][0], 'knex failed on attempted connection');
t.true(loggerWarnStub.args[0][1].errors.map((e) => e.message).includes('connect ECONNREFUSED 127.0.0.1:5400'));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was changed as the underlying modules changed behaviors in the update and this can result in an aggregate error with more values than the original test.

@@ -1,6 +1,6 @@
## Dockerfile to create integration/unit test environment
FROM node:16.19.0-buster
RUN apt update && npm config set unsafe-perm true &&\
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool to see unsafe-perm go away here and elsewhere... what was it doing before that's changed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NPM changed how it's invoking things in v7, instead of using the uid specified by the user config (nobody in the case of root) it uses the permissions from the folder, which works just fine for our use case.

Also, notably, they dropped support for this option when those changes were made.

@@ -9,20 +9,20 @@ services:
- ../packages/test-data/keys/ssh_client_rsa_key.pub:/ssh_client_rsa_key.pub
- ../packages/test-data:/data
build_env:
image: cumuluss/cumulus-build-env:latest
image: cumuluss/cumulus-build-env:test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a leftover from testing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch - yes, I'll revert it 👍🏻

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's going on with this? won't we just have to call this as await? is there more going on here than aliasing default to whatever we wanna call it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - this is needed because:

Compiling javascript into a CommonJS typescript module will not allow for dynamic imports. In the use case in @cumulus/ingest we don't want to make all of the JS not TS compiled as that doesn't generate typemaps and makes downstream TS module users define default/types.

If we wrap the ESM import statement in something like eval, that works great (tsc doesn't transpile it), however any user of the module that webpacks a lambda using it won't include the dependency (as using a hack like eval in this case confuses static dependency mapping).

Exporting it from a package as un-compiled JS allows us to:

  1. Have a helper that imports got in this way to avoid the above issues in typescript modules with allowJs enabled
  2. Avoid any downstream dependency detection issues
  3. Handle this issue in a tidy way across the project

packages/ingest/test/test-HttpProviderClient.js Outdated Show resolved Hide resolved
// Message should look like this:
// MESSAGE_TYPE = "SHORTPAN";
// DISPOSITION = "SUCCESSFUL";
// TIME_STAMP = 2023-03-27T18:10:56.402Z;
nock(url).post(remotePath, regex)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this validation happening somewhere else?

Copy link
Member Author

@Jkovarik Jkovarik Apr 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and no. This is one of those cases where we're re-validating library behavior that itself mocks.

got is broken in node20 when used with nock/aws and file readstreams - and other options (axios) don't handle file streaming (as well/at all) . As such, this test is only testing that something attempts to post to the nock'd HTTP endpoint, which is unit tested in the ingest module already via the workaround noted in test-HttpProviderClient.

Opinion:
In light of the issues with nock/etc, got and node 20 the value here of requiring this is at least somewhat debatable (or at least pushes the bounds of social/unsocial units) given the code being covered by the unit isn't in this task, and we have coverage re: a PAN being sent. Removing this assertion doesn't directly reduce code coverage.

The alternate approaches include:

  1. Update the HTTP server with a CGI script to actually take any post and write it to the container file system/serve it to validate something is posted and evaluate that response in the unit
  2. Update the existing integration test to use a HTTP provider. This would also require an HTTP server that will take POST/put
  3. Exposing the test mock params through the lambda client to this unit test
  4. Fix got, or implement an alternative to utilize our test mocking structure.

Co-authored-by: etcart <37375117+etcart@users.noreply.github.com>
Copy link
Contributor

@etcart etcart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

talked through the details of importGot and cleared up the last confusion

@Jkovarik
Copy link
Member Author

@etcart per our pairing/discussion session I added 2ff5403 - take a look and let me know what you think!

@Jkovarik Jkovarik merged commit 9feefbe into master Apr 30, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants