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

fix(ui): don't use Buffer for FNV hash #11766

Merged
merged 2 commits into from
Sep 6, 2023

Conversation

agilgur5
Copy link
Member

@agilgur5 agilgur5 commented Sep 6, 2023

Fixes #11764

Motivation

Modifications

Verification

  • unit tests for FNV hashing still pass, so think the implementation is equivalent and we're good!

Misc Notes

I decided not to replace the FNV hash implementation with a library as basically all of them are unmaintained and this change only ended up being a few LoC. Some of the libraries are also quite large (implementing many different algorithms and are not tree-shakeable), or have build issues, or use BigInt (which is not supported in older browsers... although those are all EoL and I wouldn't personally support such old browsers, but still something to consider).

- Buffers require a polyfill in client-side JS
  - aac4f89 upgraded to Webpack v5, which [no longer auto adds Node polyfills](https://github.com/webpack/changelog-v5#automatic-nodejs-polyfills-removed)
  - this seems to be the only one we use (as far as I can tell) -- and this code quite literally copies server-side Go code, so makes sense that it may use server-side libraries
    - add comments in the code about where this is copied from so that it is easier to track (I had to go through the `blame` + commit history)

- use `charCodeAt` to extract an int from the string instead of converting the string to a Buffer
  - was inpsired by looking at some JS FNV implementations and stumbled upon some lines like this: https://github.com/schwarzkopfb/fnv1a/blob/2c5ee2889e42a6bd38c64a29b227eaf9e048e40d/index.js#L22
  - unit tests still pass, so think the implementation is equivalent and we're good!

- also re-enable the `tslint` rule at the end of the code

Signed-off-by: Anton Gilgur <agilgur5@gmail.com>
Copy link
Member

@terrytangyuan terrytangyuan left a comment

Choose a reason for hiding this comment

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

@toyamagu-2021 Can you help test this change?

Signed-off-by: Anton Gilgur <4970083+agilgur5@users.noreply.github.com>
Copy link
Member

@toyamagu-2021 toyamagu-2021 left a comment

Choose a reason for hiding this comment

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

Thanks! Works fine.

But I wonder why we should calculate podName by nix hash in frontend?
We may derive podName from nodeId...

nodeId=steps-dflj9-1988631110
podName=steps-dflj9-whalesay-1988631110

@terrytangyuan terrytangyuan merged commit 53b4701 into argoproj:master Sep 6, 2023
24 checks passed
@agilgur5 agilgur5 deleted the fix-ui-fnv-hash branch September 6, 2023 23:07
@agilgur5
Copy link
Member Author

agilgur5 commented Sep 6, 2023

But I wonder why we should calculate podName by nix hash in frontend? We may derive podName from nodeId...

nodeId=steps-dflj9-1988631110
podName=steps-dflj9-whalesay-1988631110

the logic, as far as I can tell, is that when the name is too long it needs to be shortened, so a hash is used. The back-end PR is #6712 which also has a few back-links to other issues and PRs. Could also ask JP if he remembers (he is currently active on both Slack and GitHub -- can tag him here if you're curious)

I've definitely had some long names before and it's common to do some truncation or hashing when names are too long for k8s's limit. So it makes sense to me.

@toyamagu-2021
Copy link
Member

Thanks for clarifying!
Now also makes sense to me.

dpadhiar pushed a commit to dpadhiar/argo-workflows that referenced this pull request May 9, 2024
Signed-off-by: Dillen Padhiar <dillen_padhiar@intuit.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[master branch only] UI crashes when clicking node with an error message: Buffer is not defined
3 participants