[ML] New Platform server shim: update analytics routes to use new platform router#53521
Conversation
|
Pinging @elastic/ml-ui (:ml) |
peteharverson
left a comment
There was a problem hiding this comment.
Tested the data frame analytics pages, and all LGTM
There was a problem hiding this comment.
You can type 'ml' the same way search did it:
kibana/src/plugins/data/server/search/search_service.ts
Lines 37 to 41 in 8395596
This will allow any consumers of this context to get type information as well.
There was a problem hiding this comment.
Good point - added here: f9a7b5b5c5cd88050be8512f2e59a79c512daa68
There was a problem hiding this comment.
This will expose the stack trace of e which could reveal information about the server like the location of files. This should rather be response.internalError({body: e.message}); (also in other places in the PR)
There was a problem hiding this comment.
Thanks for taking a look! 😄
Updated here: 66d9d97048c385885a158804899124f469390672
There was a problem hiding this comment.
Validation is our best protection against prototype pollution attacks, allowUnknowns: true disables a lot of that protection. Is it possible to enumerate all the expected properties in the schema?
There was a problem hiding this comment.
Good call - updated here: 66d9d97048c385885a158804899124f469390672
There was a problem hiding this comment.
NIT: subjective opinion, but you could inline the handlers as they are all used only once. This will also helps when converting to TS as the context, request, response types will be inferred.
licensePreRoutingFactory(xpackMainPlugin, (context, request, response) {
try {
const { analyticsId } = request.params;
const results = await context.ml.mlClient.callAsCurrentUser('ml.deleteDataFrameAnalytics', {
analyticsId,
});
return response.ok({
body: { ...results },
});
} catch (e) {
// Case: default
return response.internalError({ body: e.message });
}
})There was a problem hiding this comment.
Great suggestion! Changed in 1be4d620155fc0186cd7fedcaebb6c7ba5a51c9c
There was a problem hiding this comment.
Should use proper type forwarding here, will be useful when your handlers will be migrated to TS (see src/core/server/http/router/error_wrapper.ts for an example)
export const licensePreRoutingFactory = <
P extends ObjectType,
Q extends ObjectType,
B extends ObjectType
>(
xpackMainPlugin: any,
handler: RequestHandler<P, Q, B>
): RequestHandler<P, Q, B> => {
...
}There was a problem hiding this comment.
You don't need to use customError for common return types. Use response.forbidden instead
There was a problem hiding this comment.
Updated to use forbidden in 8c93d6b4a20f1de2821b6ab6f8835703bdb09abf
There was a problem hiding this comment.
NIT: comment seems strange?
There was a problem hiding this comment.
Removed in 1be4d620155fc0186cd7fedcaebb6c7ba5a51c9c
1be4d62 to
b6ac51d
Compare
There was a problem hiding this comment.
is this going to return a 403 for every error that gets thrown.
Do we not want to do something similar to how the old routes work where the errors thrown from the es endpoints are wrapped in a boom error? or something similar if we don't want to use boom anymore.
There was a problem hiding this comment.
Yep - find and replace gone wrong which I thought I removed but slipped through. Thanks. Fixed in 8c93d6b4a20f1de2821b6ab6f8835703bdb09abf
There was a problem hiding this comment.
nit, it's good practice to keep const vars like this are the top of the file
There was a problem hiding this comment.
👌 Moved to top in 8c93d6b4a20f1de2821b6ab6f8835703bdb09abf
f9a7b5b to
3c173a0
Compare
💚 Build Succeeded
History
To update your PR or re-run it, just comment with: |
|
This has been updated and is ready for a final look when you get a chance. cc @walterra, @peteharverson, @darnautov, @pgayvallet. |
walterra
left a comment
There was a problem hiding this comment.
Code itself LGTM, caveat: I don't know much about all the server side APIs involved but I see you got good feedback from others in that regard.
|
I just noticed that i'm seeing server errors when viewing the results for a regression job. the Calling the underlying es endpoint manually returns this error: It looks like the use of The old version of @jgowdyelastic - yep that status did need to get set as an option in the new error wrapper. The ui still gives the right callout so I missed this. Thanks for catching it. Added the status option here: b8c3bd08ea8efa46ea8c4496e80193987215e9a1 |
peteharverson
left a comment
There was a problem hiding this comment.
Tested latest edits and LGTM
b8c3bd0 to
5174b07
Compare
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
…tform router (elastic#53521) * update dfAnalytics routes to use np router * add route schemas and only show error message * convert route file to ts and set handlers inline * update df analytics param type * update mlClient type and assert mlClient is not null * handle errors correctly * ensure error status gets passed correctly to wrapper
…tform router (#53521) (#53897) * update dfAnalytics routes to use np router * add route schemas and only show error message * convert route file to ts and set handlers inline * update df analytics param type * update mlClient type and assert mlClient is not null * handle errors correctly * ensure error status gets passed correctly to wrapper
* master: Rename `/api/security/oidc` to `/api/security/oidc/callback`. (elastic#53886) Updating transitive dependencies to use handlebars@4.5.3 (elastic#53899) [Reporting/Tests] consolidate functional test configs (elastic#52671) [Reporting] Correct the docvalue_fields params in the search query Download CSV from Dashboard Panel (elastic#52833) [Test/Newsfeed] Re-enable test and add news item to be filtered (elastic#53905) cleanup server-log action (elastic#53326) [Uptime] Delete uptime eslint rule skip (elastic#50912) [skip-ci] Expression Lifecycle Docs (elastic#51494) [Endpoint] add react router to endpoint app (elastic#53808) [SIEM][Detection Engine] Silence 409 errors on signal creation (elastic#53859) [Maps] get max_result_window and max_inner_result_window from index settings (elastic#53500) [ML] New Platform server shim: update analytics routes to use new platform router (elastic#53521) fixes typo on engine detection page (elastic#53877)
* master: Rename `/api/security/oidc` to `/api/security/oidc/callback`. (elastic#53886) Updating transitive dependencies to use handlebars@4.5.3 (elastic#53899) [Reporting/Tests] consolidate functional test configs (elastic#52671) [Reporting] Correct the docvalue_fields params in the search query Download CSV from Dashboard Panel (elastic#52833) [Test/Newsfeed] Re-enable test and add news item to be filtered (elastic#53905) cleanup server-log action (elastic#53326) [Uptime] Delete uptime eslint rule skip (elastic#50912) [skip-ci] Expression Lifecycle Docs (elastic#51494) [Endpoint] add react router to endpoint app (elastic#53808) [SIEM][Detection Engine] Silence 409 errors on signal creation (elastic#53859) [Maps] get max_result_window and max_inner_result_window from index settings (elastic#53500) [ML] New Platform server shim: update analytics routes to use new platform router (elastic#53521) fixes typo on engine detection page (elastic#53877) [Maps] push mapbox value extraction from VectorStyle and into DynamicStyleProperty (elastic#53806) Fix suggested value for time_zone in range query (elastic#53841) Clean up generic hooks, use react-use instead (elastic#53822)
…ris/kibana into alerting/created_at-and-updated_at * 'alerting/created_at-and-updated_at' of github.com:gmmorris/kibana: Rename `/api/security/oidc` to `/api/security/oidc/callback`. (elastic#53886) Updating transitive dependencies to use handlebars@4.5.3 (elastic#53899) [Reporting/Tests] consolidate functional test configs (elastic#52671) [Reporting] Correct the docvalue_fields params in the search query Download CSV from Dashboard Panel (elastic#52833) [Test/Newsfeed] Re-enable test and add news item to be filtered (elastic#53905) cleanup server-log action (elastic#53326) [Uptime] Delete uptime eslint rule skip (elastic#50912) [skip-ci] Expression Lifecycle Docs (elastic#51494) [Endpoint] add react router to endpoint app (elastic#53808) [SIEM][Detection Engine] Silence 409 errors on signal creation (elastic#53859) [Maps] get max_result_window and max_inner_result_window from index settings (elastic#53500) [ML] New Platform server shim: update analytics routes to use new platform router (elastic#53521) fixes typo on engine detection page (elastic#53877) [Maps] push mapbox value extraction from VectorStyle and into DynamicStyleProperty (elastic#53806) Fix suggested value for time_zone in range query (elastic#53841) Clean up generic hooks, use react-use instead (elastic#53822)
…t-types * alerting/created_at-and-updated_at: updatedAt should equal createdAt on creation Move index patterns: src/legacy/core_plugins/data 👉 src/plugins/data (elastic#53794) moved Task Manager server code under "server" directory (elastic#53777) Rename `/api/security/oidc` to `/api/security/oidc/callback`. (elastic#53886) Updating transitive dependencies to use handlebars@4.5.3 (elastic#53899) [Reporting/Tests] consolidate functional test configs (elastic#52671) [Reporting] Correct the docvalue_fields params in the search query Download CSV from Dashboard Panel (elastic#52833) [Test/Newsfeed] Re-enable test and add news item to be filtered (elastic#53905) cleanup server-log action (elastic#53326) [Uptime] Delete uptime eslint rule skip (elastic#50912) [skip-ci] Expression Lifecycle Docs (elastic#51494) [Endpoint] add react router to endpoint app (elastic#53808) [SIEM][Detection Engine] Silence 409 errors on signal creation (elastic#53859) [Maps] get max_result_window and max_inner_result_window from index settings (elastic#53500) [ML] New Platform server shim: update analytics routes to use new platform router (elastic#53521) fixes typo on engine detection page (elastic#53877) [Maps] push mapbox value extraction from VectorStyle and into DynamicStyleProperty (elastic#53806) Fix suggested value for time_zone in range query (elastic#53841) Clean up generic hooks, use react-use instead (elastic#53822)

Summary
Updates all data frame analytics routes to use new platform router.
Checklist
Use
strikethroughsto remove checklist items you don't feel are applicable to this PR.- [ ] Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n support~~- [ ] Documentation was added for features that require explanation or tutorials
- [ ] Unit or functional tests were updated or added to match the most common scenarios- [ ] This was checked for keyboard-only and screenreader accessibilityFor maintainers
- [ ] This was checked for breaking API changes and was labeled appropriately- [ ] This includes a feature addition or change that requires a release note and was labeled appropriately