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] NP: migrate server #58680

Merged

Conversation

alvarezmelissa87
Copy link
Contributor

Summary

Migrate legacy server to NP.

Create server plugin/index for ml in x-pack/plugins
Move all legacy/server files to plugins/ml
Update all shared type/constants/etc imports in NP server to import from legacy/ (once client is fully moved over those import paths can be updated)

NOTES

x-pack/legacy/plugins/ml/public/application/license/check_license.tsx getFeatures has been hardcoded to return full permissions for now. This will be handled in a follow-up.

In the NP plugin license check, isAvailable is set to isEnabled for now as the NP license check returns false for isAvailable with a basic license - ML should be available on basic with very reduced functionality. This will also be sorted in the follow up.

Checklist

Delete any items that are not applicable to this PR.

@alvarezmelissa87 alvarezmelissa87 added :ml release_note:skip Skip the PR/issue when compiling release notes Feature:NP Migration v7.7.0 labels Feb 26, 2020
@alvarezmelissa87 alvarezmelissa87 requested a review from a team as a code owner February 26, 2020 23:29
@alvarezmelissa87 alvarezmelissa87 self-assigned this Feb 26, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

return response.customError(wrapError(error));
const { getPrivileges } = privilegesProvider(
context.ml!.mlClient.callAsCurrentUser,
cachedLicenseCheckResult,
Copy link
Member

@jgowdyelastic jgowdyelastic Feb 27, 2020

Choose a reason for hiding this comment

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

I think it's ok to call getLicenseCheckResults again in here rather than caching the license object locally.
getLicenseCheckResults just returns the already created license results object and has no overhead.
job_service.ts is doing this without a cache also in this file on line 80.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in 609be5c4c218d1feed4b249158c438ce7c30f99d

@@ -25,7 +25,9 @@ type CalculateModelMemoryLimitPayload = TypeOf<typeof modelMemoryLimitSchema>;
/**
* Routes for job validation
*/
export function jobValidationRoutes({ config, xpackMainPlugin, router }: RouteInitialization) {
export function jobValidationRoutes({ version, getLicenseCheckResults, router }: any) {
// const { isSecurityDisabled } = getLicenseCheckResults();
Copy link
Member

Choose a reason for hiding this comment

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

commented code can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

609be5c4c218d1feed4b249158c438ce7c30f99d

}: RouteInitialization) {
export function systemRoutes({ getLicenseCheckResults, router, spacesPlugin, cloud }: any) {
let cachedLicenseCheckResult: LicenseCheckResult;
// const { isSecurityDisabled } = getLicenseCheckResults();
Copy link
Member

Choose a reason for hiding this comment

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

commented code can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

609be5c4c218d1feed4b249158c438ce7c30f99d

let sampleLinksInitialized = false;

plugins.features.registerFeature({
id: 'ml',
Copy link
Member

Choose a reason for hiding this comment

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

all 'ml' strings in this file could be PLUGIN_ID from types.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call - added in 609be5c4c218d1feed4b249158c438ce7c30f99d

import { LicensingPluginSetup } from '../../licensing/server';
import { SpacesPluginSetup } from '../../spaces/server';

export const PLUGIN_ID = 'ml';
Copy link
Member

Choose a reason for hiding this comment

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

it'd be good to move this to common as we often need this string client side. it could go in app.ts.
(also API_BASE_PATH in there can go as it's a leftover from transforms being in ML)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in 609be5c4c218d1feed4b249158c438ce7c30f99d

};
});

const routeInit = {
Copy link
Member

Choose a reason for hiding this comment

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

this should have a type so we can use it in each route.

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 in 609be5c4c218d1feed4b249158c438ce7c30f99d

};

annotationRoutes({
...routeInit,
Copy link
Member

@jgowdyelastic jgowdyelastic Feb 27, 2020

Choose a reason for hiding this comment

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

i wonder if it's worth merging these into a single object?
An alternative approach could be to pass the routeInit as a single first argument to each route, so they are all the same, and for the routes that require additional information, pass that as a second argument.
The routes themselves could then manage the type of that second "additional dependancies" parameter.
Something like:

systemRoutes(routeInit, {
  spacesPlugin: plugins.spaces,
  cloud: plugins.cloud,
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea - used the second idea of having an 'additional dependencies' second parameter where applicable. 609be5c4c218d1feed4b249158c438ce7c30f99d

if (isEnabled === true && plugins.home) {
if (
this.licenseCheckResults.type &&
['platinum', 'trial'].includes(this.licenseCheckResults.type)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should include enterprise too, in line with the list of VALID_FULL_LICENSE_MODES in server/lib/check_license/check_license.ts. We should probably define that list of full license modes in e.g. common/constants/license.ts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated and moved to constants/license.ts in 609be5c4c218d1feed4b249158c438ce7c30f99d

@@ -49,10 +49,11 @@ export function checkLicense(xpackLicenseInfo: XPackInfo): Response {

const VALID_FULL_LICENSE_MODES = ['platinum', 'enterprise', 'trial'];
Copy link
Contributor

Choose a reason for hiding this comment

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

See other comment regarding moving this into a common constants file. Could be done in the follow-up to fix the licensing checks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

609be5c4c218d1feed4b249158c438ce7c30f99d

import { licensePreRoutingFactory } from '../new_platform/licence_check_pre_routing_factory';
import { RouteInitialization } from '../new_platform/plugin';
import { licensePreRoutingFactory } from './license_check_pre_routing_factory';
// import { RouteInitialization } from '../new_platform/plugin';
Copy link
Contributor

Choose a reason for hiding this comment

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

Are all these commented out lines for the RouteInitialization needed in all the routes files?

Copy link
Member

Choose a reason for hiding this comment

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

RouteInitialization could be reused for my requested change.
#58680 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 609be5c4c218d1feed4b249158c438ce7c30f99d

@peteharverson
Copy link
Contributor

Gave this a good test, and all works well, apart from the ML item with the Jobs List doesn't appear in the Management app. Is this related to the licensing work that needs to be done?

};

plugin(initializerContext).setup(core, plugins);
async init(server: Server) {
Copy link
Member

Choose a reason for hiding this comment

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

managementSections: ['plugins/ml/application/management'], on line 24 isn't registering our management section anymore.
Is there a NP equivalent?
(github wouldn't let me add this to line 24)

Copy link
Contributor

Choose a reason for hiding this comment

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

There is, but I think it should work. Maybe this this an issue with the fact that there is now both a x-pack/legacy/plugins/ml and x-pack/plugins/ml folders? But the NP ml plugin has no public part, so I'm not sure to understand. @elastic/kibana-app-arch would you mind to take a look?

Copy link
Contributor Author

@alvarezmelissa87 alvarezmelissa87 Feb 27, 2020

Choose a reason for hiding this comment

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

@jgowdyelastic - looks like the issue is that in applicatoins/management the code to register the app in management is wrapped in an if block that relies on legacy xpackInfo.

The solution is to use the frontend licensing service - npSetup.plugins.licensing where npSetup comes from import { npSetup } from 'ui/new_platform'

Then we can can pull the relevant license info from

licensing.license$.subscribe(async license => {
  if (license.type && VALID_FULL_LICENSE_MODES.includes(license.type)) {
    ... <register management app>

Probably this same approached can be used in the work you'll be doing for check_license.tsx @jgowdyelastic 🤔
cc @peteharverson for context

features: FeaturesPluginSetup;
home: HomeServerPluginSetup;
licensing: LicensingPluginSetup;
security: any;
Copy link
Member

Choose a reason for hiding this comment

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

this should be SecurityPluginSetup

Copy link
Contributor Author

Choose a reason for hiding this comment

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

609be5c4c218d1feed4b249158c438ce7c30f99d

}

export interface PluginsSetup {
cloud: any;
Copy link
Member

Choose a reason for hiding this comment

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

this should be CloudSetup

Copy link
Contributor Author

Choose a reason for hiding this comment

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

609be5c4c218d1feed4b249158c438ce7c30f99d

@@ -3,6 +3,7 @@
"version": "0.0.1",
"kibanaVersion": "kibana",
"configPath": ["ml"],
"requiredPlugins": ["licensing"],
"server": true,
"ui": true
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This file doesn't do anything in legacy. I would remove it completely.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed in 609be5c4c218d1feed4b249158c438ce7c30f99d

@alvarezmelissa87
Copy link
Contributor Author

Registering the management section can be addressed in a follow-up PR as we have to do follow up work for licensing issues as well.

This has been updated for all comments and is ready for final look cc @jgowdyelastic, @peteharverson, @joshdover

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.

Tested and LGTM!
This PR is a cut (over) above the rest!
It certainly makes the cut (over)!
Sorry, yeah I know, I could cut (over) it out.

Copy link
Contributor

@peteharverson peteharverson left a comment

Choose a reason for hiding this comment

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

Latest edits LGTM!

@alvarezmelissa87 alvarezmelissa87 force-pushed the ml-np-server-cutover-step-one branch from 609be5c to 2560317 Compare February 27, 2020 20:55
@peteharverson peteharverson mentioned this pull request Feb 27, 2020
78 tasks
@alvarezmelissa87
Copy link
Contributor Author

retest

Copy link
Contributor

@joshdover joshdover left a comment

Choose a reason for hiding this comment

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

No major issues spotted 👍

makeMlUsageCollector(plugins.usageCollection, core.savedObjects);
});

plugins.licensing.license$.subscribe(async license => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a huge concern, but you should unsubscribe from this observable in the stop phase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh good catch - added to checklist 👍

Comment on lines +138 to +141
// This `isAvailable` check for the ml plugin returns false for a basic license
// ML should be available on basic with reduced functionality (only file data visualizer)
// TODO: This will need to be updated in the second step of this cutover to NP.
isAvailable: isEnabled,
Copy link
Contributor

Choose a reason for hiding this comment

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

How did this work before / what is the approach to solving this in the follow up?

@alvarezmelissa87 alvarezmelissa87 force-pushed the ml-np-server-cutover-step-one branch from 2560317 to 53c2b6f Compare February 27, 2020 22:28
@alvarezmelissa87 alvarezmelissa87 force-pushed the ml-np-server-cutover-step-one branch from 53c2b6f to 3a872d5 Compare February 28, 2020 00:21
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

  • 💔 Build #29580 failed 53c2b6f1e55ed64d330e6e8640def48ab82829f8
  • 💔 Build #29559 failed 25603177277414674f498f72d64b75f5b26b012f
  • 💔 Build #29474 failed 609be5c4c218d1feed4b249158c438ce7c30f99d
  • 💔 Build #29352 failed e5db02df04b0bf7388fa4d91399109670f63dab5
  • 💔 Build #29324 failed af0b7edbd184afd07966c62d7c1d746503b4e68d

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

@alvarezmelissa87 alvarezmelissa87 merged commit 8c3d71b into elastic:master Feb 28, 2020
alvarezmelissa87 added a commit to alvarezmelissa87/kibana that referenced this pull request Feb 28, 2020
* remove obsolete legacy server deps

* licensePreRoutingFactory uses licensing plugin rather than legacy xpack

* move schemas to dir in routes

* use NP license check method for license check

* store license data in plugin for passing to check

* create server plugin files in NP plugin dir

* remove dependency on legacy xpack plugin

* add sample data links first step

* move all server dirs from legacy to np dir

* fix requiredPlugin spaces name and update import routes

* delete unnecessary files and add sample data links

* update license and privilege check tests

* add routeInit types
alvarezmelissa87 added a commit that referenced this pull request Feb 28, 2020
* remove obsolete legacy server deps

* licensePreRoutingFactory uses licensing plugin rather than legacy xpack

* move schemas to dir in routes

* use NP license check method for license check

* store license data in plugin for passing to check

* create server plugin files in NP plugin dir

* remove dependency on legacy xpack plugin

* add sample data links first step

* move all server dirs from legacy to np dir

* fix requiredPlugin spaces name and update import routes

* delete unnecessary files and add sample data links

* update license and privilege check tests

* add routeInit types
@alvarezmelissa87 alvarezmelissa87 deleted the ml-np-server-cutover-step-one branch February 28, 2020 04:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:NP Migration :ml release_note:skip Skip the PR/issue when compiling release notes v7.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants