-
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 recognize modules routes to use new platform router #57206
Conversation
Pinging @elastic/ml-ui (:ml) |
) => Promise<any>; | ||
|
||
constructor(context: RequestHandlerContext) { | ||
this.callWithRequest = context.ml!.mlClient.callAsCurrentUser; |
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.
I think it would be a good idea to name this this.callAsCurrentUser
to be consistent with the other updated route models
params: schema.object({ | ||
moduleId: schema.string(), | ||
}), | ||
body: schema.object({ |
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.
What do you think about moving this to a schema file to be consistent with the other converted routes?
There are also enough schema files in the new_platform
directory that I think it warrants creating a schemas
dir in there. I'm happy to do that part but would be good to get these body
schemas in a separate 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 a dedicated file in 63ea75b
id: any; | ||
title: any; | ||
query: any; | ||
description: 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.
Wouldn't some of these types be string
?
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.
Added types in 63ea75b
@@ -445,11 +536,11 @@ export class DataRecognizer { | |||
} | |||
|
|||
async loadIndexPatterns() { | |||
return await this.savedObjectsClient.find({ type: 'index-pattern', perPage: 1000 }); | |||
return await this.savedObjectsClient!.find({ type: 'index-pattern', perPage: 1000 }); |
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.
It actually might be worth checking that this.savedObjectsClient
exists here instead of using non-null assertion here. Even though right now loadIndexPatterns
is only used after savedObjectsClient
has been set this check would guard against any future updates/additions to this class that might try to use this method differently.
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.
I believe it should be passed to the constructor, not the method. In that case, no check is required. I just wanted to avoid any code changes in this PR, but probably it worth a small refactoring.
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.
Refactored in 63ea75b
loadExistingSavedObjects(type) { | ||
return this.savedObjectsClient.find({ type, perPage: 1000 }); | ||
loadExistingSavedObjects(type: string) { | ||
return this.savedObjectsClient!.find({ type, perPage: 1000 }); |
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.
As mentioned above, might be worth checking that savedObjectsClient
has been set.
const reducedConfig = { | ||
jobs: moduleConfig.jobs, | ||
datafeeds: moduleConfig.datafeeds, | ||
kibana: moduleConfig.kibana, | ||
}; | ||
} as const; |
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.
I'm not familiar with this - why is it needed?
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.
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#const-assertions
But I added const assertion here by mistake, will remove
const { limits } = await this.callWithRequest('ml.info'); | ||
const maxMml = limits.max_model_memory_limit; | ||
if (maxMml !== undefined) { | ||
const maxBytes = numeral(maxMml.toUpperCase()).value(); | ||
// @ts-ignore | ||
const maxBytes: number = numeral(maxMml.toUpperCase()).value(); |
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.
Would be good to know what is being ignored here - to be consistent
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.
For some reason, the issue is numeral
from @elastic/numeral
. It complains that value
prop does not exist.
if (mml !== undefined) { | ||
const mmlBytes = numeral(mml.toUpperCase()).value(); | ||
// @ts-ignore | ||
const mmlBytes: number = numeral(mml.toUpperCase()).value(); |
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.
Same here
end, | ||
jobOverrides, | ||
datafeedOverrides, | ||
getSavedObjectsClient(elasticsearchPlugin, savedObjects!) |
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.
i'm unsure about using getSavedObjectsClient
here as it uses the elevated internal user to create the saved object repository which could be a security risk.
The original version used the getSavedObjectsClient
from the request
which I imagine had the current user's level of privileges.
I'm unsure about this and I think is worth investigating.
Also, I didn't realise that the savedObjects
being passed to the router are of the type SavedObjectsLegacyService
.
I wonder if it's possible to use the non-legacy version of the saved objects client in our plugin right now, before we move it to the new platform proper.
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.
Agreed 🤔 I think we should be to use NP's context.core.savedObjects.client
which is meant to replace request.getSavedObjectsClient
(https://github.com/elastic/kibana/blob/master/src/core/MIGRATION.md#server-side)
Since context
is scoped like the previously used legacy request
this should give us the same behavior, I'd think.
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.
Fixed in 63ea75b
moduleId: schema.string(), | ||
}), | ||
body: schema.object({ | ||
prefix: schema.string(), |
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.
prefix
should be optional.
See documentation here:
https://github.com/elastic/ml-team/blob/master/ui/rest_api/modules/modules_api_setup.md
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.
Fixed
1f975d4
to
63ea75b
Compare
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.
One small change needed, but otherwise LGTM
export const setupModuleBodySchema = schema.object({ | ||
prefix: schema.maybe(schema.string()), | ||
groups: schema.maybe(schema.arrayOf(schema.string())), | ||
indexPatternName: schema.string(), |
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.
indexPatternName
needs to be optional
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 ⚡️
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
… new platform router (elastic#57206) * [ML] modules with NP router * [ML] use extendedRouteInitializationDeps * [ML] add apidoc annotations * [ML] address PR comments * [ML] convert data_recognizer test to jest * [ML] optional indexPatternName
* master: (27 commits) Include actions new platform plugin for codeowners (elastic#57252) [APM][docs] 7.6 documentation updates (elastic#57124) Expressions refactor (elastic#54342) [ML] New Platform server shim: update annotation routes to use new platform router (elastic#57067) Remove injected ui app vars from Canvas (elastic#56190) update max_anomaly_score route schema to handle possible undefined values (elastic#57339) [Add panel flyout] Moving create new to the top of SavedObjectFinder (elastic#56428) Add mock of a legacy ui api to re-enable Canvas storybook (elastic#56673) [monitoring] Removes noisy event received log (elastic#57275) Remove use of copied MANAGEMENT_BREADCRUMBS and use `setBreadcrumbs` from management section's mount (elastic#57324) Advanced Settings management app to kibana platform plugin (elastic#56931) [ML] New Platform server shim: update recognize modules routes to use new platform router (elastic#57206) [ML] Fix overall stats for saved search on the Data Visualizer page (elastic#57312) [ML] [NP] Removing ui imports (elastic#56358) [SIEM] Fixes failing Cypress tests (elastic#57202) Create observability CODEOWNERS reference (elastic#57109) fix results service schema (elastic#57217) don't register a wrapper if browser side function exists. (elastic#57196) Ui Actions explorer example (elastic#57006) Fix update alert API to still work when AAD is out of sync (elastic#57039) ...
Summary
Part of #49743. Updates recognize module routes to use the new platform router.
Checklist