-
Notifications
You must be signed in to change notification settings - Fork 534
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
chore: use nx commands #2493
chore: use nx commands #2493
Conversation
@@ -13,8 +13,35 @@ on: | |||
type: string | |||
|
|||
jobs: | |||
build: |
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.
note for reviewer: this is the build step that is going to be cached. github.run_number
is unique for the PR so each time the workflow is run this tasks overwrites the artifact saving space. retention-days
is set to 1 so the artifact will be removed the next day after the last run of this workflow.
.github/workflows/unit-test.yml
Outdated
@@ -5,7 +5,34 @@ on: | |||
pull_request: | |||
|
|||
jobs: | |||
build: |
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.
note for reviewer: same here for unit tests. I guess a single compile step can be done for both workflows but I think this will add complexity to them. This way both workflows are independent and still we reduce the resource usage
@@ -10,7 +10,6 @@ | |||
"compile": "tsc -p .", | |||
"lint": "eslint . --ext .ts", | |||
"lint:fix": "eslint . --ext .ts --fix", | |||
"precompile": "tsc --version && lerna run version:update --scope @opentelemetry/resource-detector-alibaba-cloud --include-dependencies", |
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.
note for reviewer: not necessary since nx.json
has defined the task dependencies. Same applies for other packages
"compile": { | ||
"dependsOn": [ | ||
"version:update", | ||
"^compile" |
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.
note for reviewer: this is the syntax to tell that dependencies within the monorepo should be compiled before compiling the current package
I'll sponsor to not have the "package unmaintained" logic. |
I got confused by the markup here. Are you trying to say the timing improved from |
Also I think I'm not clear enough. There is improvement in resource (CPU, Memory, ...) usage but not in the total time spent in the workflow. I'll try to elaborate Currently each job on the matrix does a compilation (necessary to generate version file and have dependencies solved) before testing. Each one of them taking its 5-7 minutes of CPU & Memory consumption. With the change we compile only once at the beginning, still taking 5-7min but only taking resources from 1 node. Then the job matrix for testing reuses the output from that previous step thanks to the cache. It might be represented like this
so total time is the same but using less resources. |
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.
- might want to add 'nx' to
ignoreDeps
in "renovate.json" for now
One thing that is lost here with nx run-many ...
vs lerna run ...
is the number of workers to run. When doing npm run compile
, for example, with lerna run ...
it would run 11 tasks in parallel on my machine. With nx run-many ...
it runs 3 tasks in parallel. lerna
is setting the "parallel / concurrency" based on the number of CPUs on the machine (https://github.com/lerna/lerna/blob/6.6.2/libs/core/src/lib/command/index.ts#L15). nx
is hardcoding the default --parallel
value to 3. I think even the latest nx version does that.
I was going to say that this means the initial npm run compile
takes longer for me. However, I unscientifically compared time npm run compile
(after running npm ci
) in git clones with and without this PR, and even with the parallel=3 it is faster with nx.
# with this PR
npm run compile 453.13s user 31.79s system 601% cpu 1:20.59 total
# without this PR (latest main)
npm run compile 655.85s user 86.89s system 880% cpu 1:24.35 total
I'll take it.
For me it means that the initial npm run compile
takes longer.
- name: Install | ||
run: npm ci | ||
- name: Build | ||
run: npm run compile |
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.
I'm a little scared of the "if npm ci
and npm run compile
layout is the same for all node versions". :)
Have you done a basic check comparing two separate git clones that do those steps, one with node 16 and one with node 22, say?
- I think I'm reasonably confident that for non-binary packages that the
node_modules/...
tree should be the same between versions -- otherwise the idea of package-lock.json is broken. - I'm not sure if we have binary deps -- i.e. ones that are built at install time via a gyp file or install or post-install npm scripts.
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.
I'm a little scared of the "if npm ci and npm run compile layout is the same for all node versions". :)
We can do even another twist on this because:
ts-node
compilessrc
&tests
folders so "in theory" is not necessary to compile, just to have theversion.ts
file available- but some packages depend on another in the same monorepo like
@opentelemetry/resouce-detector-container
and these dependencies need to be build.
Since the published packages are compiled using nodejs v16 maybe is better to have a "production" build as tests assets instead of a different build with each nodejs version (14, 18, 20, ...)?
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.
I'm not sure if we have binary deps -- i.e. ones that are built at install time via a gyp file or install or post-install npm scripts.
We don't have them anymore AFAICT. The last was removed with grpc-cencus-binary-propagator (#2276) because it always built on macOS (it had pre-built binaries for linux+glibc so building sometimes does not happen based on which system one is using). I think if there was another one left we'd have noticed it by now as it tends to take a lot of time on install. 🙂
Since the published packages are compiled using nodejs v16 maybe is better to have a "production" build as tests assets instead of a different build with each nodejs version (14, 18, 20, ...)?
I think having the Node.js version matched with the published packages makes sense from a testing standpoint. This way we can preempt surprises if there are any. @david-luna would you mind putting a comment in the publish workflow and here that the versions should always be updated together? 🙂
detectors/node/opentelemetry-resource-detector-container/package.json
Outdated
Show resolved
Hide resolved
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.
Looks good % some nits, thanks for working on this. 🎉
Looking forward to seeing it in action 🙂
- name: Install | ||
run: npm ci | ||
- name: Build | ||
run: npm run compile |
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.
I'm not sure if we have binary deps -- i.e. ones that are built at install time via a gyp file or install or post-install npm scripts.
We don't have them anymore AFAICT. The last was removed with grpc-cencus-binary-propagator (#2276) because it always built on macOS (it had pre-built binaries for linux+glibc so building sometimes does not happen based on which system one is using). I think if there was another one left we'd have noticed it by now as it tends to take a lot of time on install. 🙂
Since the published packages are compiled using nodejs v16 maybe is better to have a "production" build as tests assets instead of a different build with each nodejs version (14, 18, 20, ...)?
I think having the Node.js version matched with the published packages makes sense from a testing standpoint. This way we can preempt surprises if there are any. @david-luna would you mind putting a comment in the publish workflow and here that the versions should always be updated together? 🙂
Which problem is this PR solving?
This PR tries to work towards the migration from
lerna
tonx
open-telemetry/opentelemetry-js#4240. Although the issue is on the core repository I think both repos should be aligned in the tooling. I've just started with this one because it seems more straight-forward.Changes
This PR surfaces the
[email protected]
package required bylerna
. I haven't tried to use a higher version sincelerna
is not completely removed yet and it might have version conflicts. Thepackage.json
's script section has been changed to use the equivalentnx
commands for building and testing the packages, with some nuances:nx.json
file has been added defining task dependencies so some package scripts likeprecompile
are not neededversion:update
,lint
andcompile
. More details belowThe workflow does not change. Indeed the development guidelines needs no changes since already recommends to run
npm run compile
at the root folder before start doing changes in a package.Cache
nx
can cache the output of a task like the compilation. Having it active may come handy for developers since you can switch branches and rebuild only what changed just bynpm run compile
at the root. The rest will come from the cache. Cache is located insidenode_modules
so its easy to invalidate vianpm run ci
or just removing thenode_modules/.cache/nx
folder.Using it in CI
For unit and TAV tests there is a compilation step before running the test suite. Turns out that the tests are using the
tsconfig.json
to compile the tests before running. The file has the following optionsso the tests are compiling again the code in order to run. This is an unnecessary use of resources.
Test jobs in workflows do a clean checkout before testing so running
npm run test
in a package would fail because one or more of this reasons:version.ts
file is missingTest workflows run
npm run compile
for all packagesAnd because of that workflows run
npm run compile
for all packages before testing consuming time.This PR leverages
nx
cache to avoid this extra compilation given the assumption that TypeScript is giving the same output regardless of the nodejs version used for compilation:So we can change the workflows to
The gain is significant since the compilation takes around 5
7min and with the cache is around 36sec (2sec downloading + 2~3sec compiling).