perf(veritech): Run simple Joi validations in Rust instead of JS #5573
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR intercepts the simplest Joi validations and runs them in Rust instead of dispatching to Veritech:
Any validation not supported on that list, or with any unexpected options, is dispatched to Veritech instead and runs and returns exactly as before.
We produce the same results, as well as the same error message, for all of these, so user experience should be identical.
Why
Once Clover added automated validations to lots of fields on many assets, Veritech is under heavy load because every time you drag out a new asset, many Joi validations are run. All of the Clover validations are very straightforward, however, and encompass a very small subset of what is possible with Joi.
How
When a user does
.setValidationFormat(Joi.string().min(2).max(3).required()
in an asset function, we internally calldescribe()
on that Joi schema, which produces JSON that looks like this:Because there is no longer any JS involved, we can read this format in any language we like and interpret it.
Testing
Risk Mitigation
deny_unknown_fields
to ensure we only deserialize exactly things we support, and tests those few things heavilyLater
Arguably the goal is to run all Clover validations in Rust instead of JS. However,
pattern()
isn't supported as part of this turn. There is a Rust library we may pick up, but regexes are a large surface area to test, and we want to evaluate whether this has a discernible impact before we reach out for that.