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

[HTTP/OAS] Prepare router and versioned router for generating OAS #180275

Merged
merged 15 commits into from
Apr 11, 2024

Conversation

jloleysens
Copy link
Contributor

Summary

Part of #180056

Notes

@@ -7,6 +7,8 @@
*/

export { filterHeaders } from './src/headers';
export { versionHandlerResolvers } from './src/versioned_router';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not used in this PR, just exporting in preparation for future PR, happy to hold off on this change

method: 'post',
path: '/',
validationSchemas: { body: validation, query: validation, params: validation },
isVersioned: false,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mainly making sure that the above two fields are included as expected, will be used by OAS generation script

@@ -228,7 +228,7 @@ export interface AddVersionOpts<P, Q, B> {
* Validation for this version of a route
* @public
*/
validate: false | FullValidationConfig<P, Q, B>;
validate: false | FullValidationConfig<P, Q, B> | (() => FullValidationConfig<P, Q, B>); // Provide a way to lazily load validation schemas
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will enable ResponseOps and other plugins to provide route schemas lazily. Useful for registries that only know schema shapes after setup/start time.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised to not see associated code changes to support passing a function now. Unless I missed it or it already worked and just wasn't documented (but traditional routes don't support that AFAIK, so...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have some new code in packages/core/http/core-http-router-server-internal/src/versioned_router/core_versioned_route.ts to extract the validations.

But yeah, we should probably make IRouter symmetrical! Will update and add a couple of tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushed some updates that contain tests and update Router type and implementatio to support lazy validation

@jloleysens
Copy link
Contributor Author

/ci

@jloleysens
Copy link
Contributor Author

/ci

@jloleysens jloleysens marked this pull request as ready for review April 9, 2024 11:12
@jloleysens jloleysens requested a review from a team as a code owner April 9, 2024 11:12
@jloleysens jloleysens added Feature:http Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc release_note:skip Skip the PR/issue when compiling release notes v8.14.0 labels Apr 9, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-core (Team:Core)

@jloleysens jloleysens requested review from a team as code owners April 9, 2024 13:33
@jloleysens
Copy link
Contributor Author

One last try 😅

@jloleysens
Copy link
Contributor Author

/ci

Copy link
Contributor

@pgayvallet pgayvallet left a comment

Choose a reason for hiding this comment

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

Looking good overall.

Just asked for a few clarifications before approval:

@@ -44,7 +40,7 @@ const createRequest = (
);

describe('Versioned route', () => {
let router: IRouter;
let router: Router;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to use the concrete implementation's as type here now? It doesn't seem necessary for the change on expected arguments you did below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's for CoreVersionedRoute to pass an additional argument "isVersioned" when registering a route.

Comment on lines +181 to +182
handler: RequestHandler<P, Q, B, Context, Method>,
internalOptions: { isVersioned: boolean } = { isVersioned: false }
Copy link
Contributor

Choose a reason for hiding this comment

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

So if I understand correctly, this new internalOptions third parameter doesn't leak on the public interface because we only specify it on the implementation via this new InternalRegistrar type on our method helpers than extends IRouter, is that correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, exactly


/** @internal */
export interface VersionedRouterArgs {
router: IRouter;
router: Router;
Copy link
Contributor

Choose a reason for hiding this comment

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

(thinking out loud) I get why we did that, I still can't avoid thinking it's a shame that we're now forced to use our concrete implementation directly here. Relation was pure before, it's no longer.

Copy link
Contributor Author

@jloleysens jloleysens Apr 11, 2024

Choose a reason for hiding this comment

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

I agree, it is a :shame: moment. One alternative is that we can make something like an InternalIRouter interface to keep things more pure. Wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably don't need to add a type InternalIRouter = PublicMethodOf<Router>

@@ -228,7 +228,7 @@ export interface AddVersionOpts<P, Q, B> {
* Validation for this version of a route
* @public
*/
validate: false | FullValidationConfig<P, Q, B>;
validate: false | FullValidationConfig<P, Q, B> | (() => FullValidationConfig<P, Q, B>); // Provide a way to lazily load validation schemas
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised to not see associated code changes to support passing a function now. Unless I missed it or it already worked and just wasn't documented (but traditional routes don't support that AFAIK, so...)

@jloleysens jloleysens requested review from a team as code owners April 11, 2024 08:54
@botelastic botelastic bot added the Team:obs-ux-infra_services Observability Infrastructure & Services User Experience Team label Apr 11, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/obs-ux-infra_services-team (Team:obs-ux-infra_services)

@@ -198,7 +198,7 @@ export interface VersionedRouteResponseValidation {
* Versioned route validation
* @public
*/
export interface FullValidationConfig<P, Q, B> {
export interface VersionedRouteValidation<P, Q, B> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed for consistency, not necessary change for this PR

@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #41 / apis transform basic license transform /internal/transform/reauthorize_transforms single transform reauthorize_transforms "after each" hook for "should reauthorize transform created by transform_viewer with new api key of poweruser and start the transform"
  • [job] [logs] FTR Configs #56 / transform /internal/transform/schedule_now_transforms bulk schedule "after each" hook for "should schedule multiple transforms by transformIds"

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/core-http-router-server-internal 27 49 +22

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
@kbn/core-http-router-server-internal 2 5 +3
Unknown metric groups

API count

id before after diff
@kbn/core-http-router-server-internal 27 49 +22

ESLint disabled line counts

id before after diff
@kbn/core-http-router-server-internal 0 1 +1

Total ESLint disabled count

id before after diff
@kbn/core-http-router-server-internal 0 1 +1

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Contributor

@pgayvallet pgayvallet left a comment

Choose a reason for hiding this comment

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

LGTM

@jloleysens jloleysens enabled auto-merge (squash) April 11, 2024 12:59
Copy link
Contributor

@smith smith left a comment

Choose a reason for hiding this comment

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

Synthetics changes look good

Copy link
Contributor

@patrykkopycinski patrykkopycinski left a comment

Choose a reason for hiding this comment

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

Thank you @jloleysens

@jloleysens jloleysens merged commit 8da3ec4 into elastic:main Apr 11, 2024
40 checks passed
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Apr 11, 2024
@jloleysens jloleysens deleted the http/update-core-routers-for-oas branch April 11, 2024 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:http release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Team:obs-ux-infra_services Observability Infrastructure & Services User Experience Team v8.14.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants