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

Switch OSD Optimizer to rely on file hashes instead of mtimes #8472

Merged

Conversation

Swiddis
Copy link
Contributor

@Swiddis Swiddis commented Oct 3, 2024

Description

The current build cache in OSD optimizer depends on tracking the modification times of previous files. This means it never recognizes cached build artifacts in CI, because the artifacts get "updated" every time code is pulled. Refactoring the entire cache system to use file content hashes instead of modification times results in a minor speedup in build times, in cases where the build artifacts are cached. See #8428 for more information.

As followup, I have some discussion in opensearch-project/dashboards-observability#2188 regarding how best to actually use the cached artifacts.

Issues Resolved

Resolves #8428
Unblocks opensearch-project/dashboards-observability#2188

Screenshot

image

Testing the changes

Described in #8428: I set up build runs with verbose compilation enabled and tracked the built packages over time in the case of no cache, an old cache hit, and a new cache hit. Here's the results:

image

I also checked what breaks when pulling this on top of the old build system. Aside from a full recompilation (every file is now invalid), it doesn't seem to have issues when migrating from the old version -- if there's issues then ye olde yarn osd clean should do the trick.

Changelog

  • infra: Switch OSD build cache to rely on file hashes instead of mtimes

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>
Signed-off-by: Simeon Widdis <sawiddis@amazon.com>
Copy link
Contributor

github-actions bot commented Oct 3, 2024

❌ Changelog Entry Missing Hyphen

Changelog entries must begin with a hyphen (-).

readFile$(path).pipe(
map(
(buffer) =>
[path, Crypto.createHash('sha1').update(buffer).digest('base64')] as const
Copy link
Contributor Author

@Swiddis Swiddis Oct 3, 2024

Choose a reason for hiding this comment

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

Core change is this, the rest is plumbing -- most "get the file modification ID" checks trace back to here (except one occurrence in run_compiler.ts which also was updated).

Copy link

codecov bot commented Oct 3, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 9 lines in your changes missing coverage. Please review.

Project coverage is 60.93%. Comparing base (6f712e2) to head (2ae6d43).
Report is 28 commits behind head on main.

Files with missing lines Patch % Lines
packages/osd-optimizer/src/optimizer/cache_keys.ts 20.00% 4 Missing ⚠️
packages/osd-optimizer/src/optimizer/get_hashes.ts 50.00% 2 Missing ⚠️
packages/osd-optimizer/src/common/bundle.ts 0.00% 1 Missing ⚠️
packages/osd-optimizer/src/node/cache.ts 66.66% 1 Missing ⚠️
...ckages/osd-optimizer/src/optimizer/bundle_cache.ts 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8472      +/-   ##
==========================================
- Coverage   60.94%   60.93%   -0.01%     
==========================================
  Files        3759     3759              
  Lines       89329    89330       +1     
  Branches    13973    13973              
==========================================
- Hits        54438    54437       -1     
- Misses      31494    31495       +1     
- Partials     3397     3398       +1     
Flag Coverage Δ
Linux_1 28.92% <44.44%> (+<0.01%) ⬆️
Linux_2 56.30% <22.22%> (+<0.01%) ⬆️
Linux_3 37.77% <ø> (-0.01%) ⬇️
Linux_4 29.94% <22.22%> (+<0.01%) ⬆️
Windows_1 28.94% <44.44%> (+<0.01%) ⬆️
Windows_2 56.25% <22.22%> (+<0.01%) ⬆️
Windows_3 37.78% <ø> (ø)
Windows_4 29.94% <22.22%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Swiddis
Copy link
Contributor Author

Swiddis commented Oct 3, 2024

Codecov: this code is hit in every functional test workflow multiple times

Copy link
Member

@joshuali925 joshuali925 left a comment

Choose a reason for hiding this comment

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

nice

@AMoo-Miki AMoo-Miki merged commit 0609ecf into opensearch-project:main Oct 9, 2024
80 of 81 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Oct 9, 2024
* Hotswap getMtimes to compute sha1 hashes

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Rename all the things

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Changeset file for PR #8472 created/updated

---------

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
(cherry picked from commit 0609ecf)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
ruanyl pushed a commit that referenced this pull request Oct 23, 2024
… (#8532)

* Hotswap getMtimes to compute sha1 hashes



* Rename all the things



* Changeset file for PR #8472 created/updated

---------



(cherry picked from commit 0609ecf)

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
Qxisylolo pushed a commit to Qxisylolo/OpenSearch-Dashboards that referenced this pull request Oct 30, 2024
…search-project#8472)

* Hotswap getMtimes to compute sha1 hashes

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Rename all the things

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Changeset file for PR opensearch-project#8472 created/updated

---------

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OSD Optimizer: Improve strategy for detecting stale compilation targets
4 participants