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

[ML] New Platform server shim: update recognize modules routes to use new platform router #57206

Merged
merged 6 commits into from
Feb 11, 2020

Conversation

darnautov
Copy link
Contributor

@darnautov darnautov commented Feb 10, 2020

Summary

Part of #49743. Updates recognize module routes to use the new platform router.

Checklist

  • Documentation was added for features that require explanation or tutorials

@darnautov darnautov added :ml v8.0.0 release_note:skip Skip the PR/issue when compiling release notes v7.7.0 labels Feb 10, 2020
@darnautov darnautov requested a review from a team as a code owner February 10, 2020 15:23
@darnautov darnautov self-assigned this Feb 10, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

) => Promise<any>;

constructor(context: RequestHandlerContext) {
this.callWithRequest = context.ml!.mlClient.callAsCurrentUser;
Copy link
Contributor

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({
Copy link
Contributor

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.

Copy link
Contributor Author

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;
Copy link
Contributor

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?

Copy link
Contributor Author

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 });
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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 });
Copy link
Contributor

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;
Copy link
Contributor

@alvarezmelissa87 alvarezmelissa87 Feb 10, 2020

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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();
Copy link
Contributor

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

Copy link
Contributor Author

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();
Copy link
Contributor

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!)
Copy link
Member

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.

Copy link
Contributor

@alvarezmelissa87 alvarezmelissa87 Feb 10, 2020

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.

Copy link
Contributor Author

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(),
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Member

@jgowdyelastic jgowdyelastic left a 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(),
Copy link
Member

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

@peteharverson peteharverson mentioned this pull request Feb 11, 2020
78 tasks
Copy link
Contributor

@alvarezmelissa87 alvarezmelissa87 left a comment

Choose a reason for hiding this comment

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

LGTM ⚡️

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

@darnautov darnautov merged commit b133357 into elastic:master Feb 11, 2020
@darnautov darnautov deleted the ML-49743-modules branch February 11, 2020 16:11
darnautov added a commit to darnautov/kibana that referenced this pull request Feb 11, 2020
… 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
darnautov added a commit that referenced this pull request Feb 11, 2020
… new platform router (#57206) (#57335)

* [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
gmmorris added a commit to gmmorris/kibana that referenced this pull request Feb 11, 2020
* 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)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:ml release_note:skip Skip the PR/issue when compiling release notes v7.7.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants