-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Conversation
- 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>
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.
@toyamagu-2021 Can you help test this change?
Signed-off-by: Anton Gilgur <4970083+agilgur5@users.noreply.github.com>
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.
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
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. |
Thanks for clarifying! |
Signed-off-by: Dillen Padhiar <dillen_padhiar@intuit.com>
Fixes #11764
Motivation
Buffer
requires a polyfill in client-side JSblame
+ commit history)Modifications
use
charCodeAt
to extract an int from a character of a string instead of converting the string to a Bufferalso re-enable the
tslint
rule at the end of the codeVerification
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).