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

Change the built-in HTTP request validation to no longer use @kbn/config-schema #78353

Closed
kobelb opened this issue Sep 23, 2020 · 3 comments
Closed
Labels
performance Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc

Comments

@kobelb
Copy link
Contributor

kobelb commented Sep 23, 2020

At the moment, @kbn/config-schema is slow because Joi is admittedly slow, and not focused on increasing performance in the short-term: hapijs/joi#2340 (comment).

While performing some performance profiling for Fleet, I'm seeing around 6% of the total CPU time being spent validating the request. This CPU profile was captured after changing Fleet's custom route handling to no longer use @kbn/config-schema and almost all of the cost comes from the built-in HTTP request validation being dependent on Joi:

Screen Shot 2020-09-23 at 1 48 39 PM

Prior to figuring out how to how to increase the performance of @kbn/config-schema, which is being tracked by #78351, we could potentially change the build-in HTTP request validation to no longer be based on @kbn/config-schema.

@kobelb kobelb added the Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc label Sep 23, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-platform (Team:Platform)

@kobelb kobelb added bug Fixes for quality problems that affect the customer experience performance labels Sep 23, 2020
@pgayvallet
Copy link
Contributor

For information, even if we don't provide an alternative to config-schema, it is currently already possible to use a custom validation function for routing:

export interface RouteValidatorConfig<P, Q, B> {
/**
* Validation logic for the URL params
* @public
*/
params?: RouteValidationSpec<P>;
/**
* Validation logic for the Query params
* @public
*/
query?: RouteValidationSpec<Q>;
/**
* Validation logic for the body payload
* @public
*/
body?: RouteValidationSpec<B>;
}

export type RouteValidationSpec<T> = ObjectType | Type<T> | RouteValidationFunction<T>;

export type RouteValidationFunction<T> = (
data: any,
validationResult: RouteValidationResultFactory
) =>
| {
value: T;
error?: never;
}
| {
value?: never;
error: RouteValidationError;
};

@pgayvallet pgayvallet removed the bug Fixes for quality problems that affect the customer experience label Mar 31, 2021
@lizozom
Copy link
Contributor

lizozom commented Apr 18, 2022

Duplicate of #78351
Closing this issue due to inactivity.
Feel free to reopen if needed 🙏🏻

@lizozom lizozom closed this as completed Apr 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc
Projects
None yet
Development

No branches or pull requests

4 participants