-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[ML] New Platform server shim: update analytics routes to use new platform router #53521
[ML] New Platform server shim: update analytics routes to use new platform router #53521
Conversation
Pinging @elastic/ml-ui (:ml) |
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.
Tested the data frame analytics pages, and all LGTM
@@ -180,17 +189,28 @@ export class Plugin { | |||
}; | |||
}); | |||
|
|||
// Can access via new platform router's handler function 'context' parameter - context.ml.mlClient | |||
const mlClient = core.elasticsearch.createClient('ml', { plugins: [elasticsearchJsPlugin] }); | |||
// @ts-ignore // 'ml' not 'search' or 'security' or 'licensing |
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.
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
declare module 'kibana/server' { | |
interface RequestHandlerContext { | |
search?: IRouteHandlerSearchContext; | |
} | |
} |
This will allow any consumers of this context to get type information as well.
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.
Good point - added here: f9a7b5b5c5cd88050be8512f2e59a79c512daa68
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.
looks like this @ts-ignore isn't needed now
}); | ||
} catch (e) { | ||
// Case: default | ||
return response.internalError({ body: e }); |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking a look! 😄
Updated here: 66d9d97048c385885a158804899124f469390672
params: schema.object({ | ||
analyticsId: schema.string(), | ||
}), | ||
body: schema.object({ ...dataAnalyticsJobConfigSchema }, { allowUnknowns: true }), |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call - updated here: 66d9d97048c385885a158804899124f469390672
}, | ||
config: { | ||
...commonRouteConfig, | ||
licensePreRoutingFactory(xpackMainPlugin, dfAnalyticsDeleteJobHandler) |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great suggestion! Changed in 1be4d620155fc0186cd7fedcaebb6c7ba5a51c9c
export const licensePreRoutingFactory = ( | ||
xpackMainPlugin: any, | ||
handler: RequestHandler<any, any, any> | ||
): RequestHandler<any, any, any> => { |
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.
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> => {
...
}
return response.customError({ | ||
body: { | ||
message: licenseCheckResults.message, | ||
}, | ||
statusCode: 403, |
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.
You don't need to use customError
for common return types. Use response.forbidden
instead
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.
Updated to use forbidden
in 8c93d6b4a20f1de2821b6ab6f8835703bdb09abf
body: { ...results }, | ||
}); | ||
} catch (e) { | ||
// Case: default |
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.
NIT: comment seems strange?
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.
Removed in 1be4d620155fc0186cd7fedcaebb6c7ba5a51c9c
1be4d62
to
b6ac51d
Compare
body: { ...results }, | ||
}); | ||
} catch (e) { | ||
return response.forbidden({ body: e.message }); |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep - find and replace gone wrong which I thought I removed but slipped through. Thanks. Fixed in 8c93d6b4a20f1de2821b6ab6f8835703bdb09abf
} | ||
} | ||
|
||
export const PLUGIN_ID = 'ml'; |
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.
nit, it's good practice to keep const vars like this are the top of the file
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.
👌 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. |
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.
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.
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.
LGTM!!
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 |
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.
Tested latest edits and LGTM
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.
Latest changes 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 [email protected] (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 [email protected] (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 [email protected] (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 [email protected] (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