-
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] NP: migrate server #58680
[ML] NP: migrate server #58680
Conversation
Pinging @elastic/ml-ui (:ml) |
return response.customError(wrapError(error)); | ||
const { getPrivileges } = privilegesProvider( | ||
context.ml!.mlClient.callAsCurrentUser, | ||
cachedLicenseCheckResult, |
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'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.
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 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(); |
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.
commented code can be removed
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.
609be5c4c218d1feed4b249158c438ce7c30f99d
}: RouteInitialization) { | ||
export function systemRoutes({ getLicenseCheckResults, router, spacesPlugin, cloud }: any) { | ||
let cachedLicenseCheckResult: LicenseCheckResult; | ||
// const { isSecurityDisabled } = getLicenseCheckResults(); |
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.
commented code can be removed
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.
609be5c4c218d1feed4b249158c438ce7c30f99d
x-pack/plugins/ml/server/plugin.ts
Outdated
let sampleLinksInitialized = false; | ||
|
||
plugins.features.registerFeature({ | ||
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.
all 'ml' strings in this file could be PLUGIN_ID
from types.ts
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 - added in 609be5c4c218d1feed4b249158c438ce7c30f99d
x-pack/plugins/ml/server/types.ts
Outdated
import { LicensingPluginSetup } from '../../licensing/server'; | ||
import { SpacesPluginSetup } from '../../spaces/server'; | ||
|
||
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.
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)
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 in 609be5c4c218d1feed4b249158c438ce7c30f99d
x-pack/plugins/ml/server/plugin.ts
Outdated
}; | ||
}); | ||
|
||
const routeInit = { |
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 should have a type so we can use it in each route.
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 in 609be5c4c218d1feed4b249158c438ce7c30f99d
x-pack/plugins/ml/server/plugin.ts
Outdated
}; | ||
|
||
annotationRoutes({ | ||
...routeInit, |
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 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,
});
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 idea - used the second idea of having an 'additional dependencies' second parameter where applicable. 609be5c4c218d1feed4b249158c438ce7c30f99d
x-pack/plugins/ml/server/plugin.ts
Outdated
if (isEnabled === true && plugins.home) { | ||
if ( | ||
this.licenseCheckResults.type && | ||
['platinum', 'trial'].includes(this.licenseCheckResults.type) |
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 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
.
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 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']; |
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.
See other comment regarding moving this into a common constants file. Could be done in the follow-up to fix the licensing checks.
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.
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'; |
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.
Are all these commented out lines for the RouteInitialization
needed in all the routes files?
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.
RouteInitialization
could be reused for my requested change.
#58680 (comment)
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.
Done in 609be5c4c218d1feed4b249158c438ce7c30f99d
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) { |
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.
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)
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.
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?
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.
@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
x-pack/plugins/ml/server/types.ts
Outdated
features: FeaturesPluginSetup; | ||
home: HomeServerPluginSetup; | ||
licensing: LicensingPluginSetup; | ||
security: 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.
this should be SecurityPluginSetup
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.
609be5c4c218d1feed4b249158c438ce7c30f99d
x-pack/plugins/ml/server/types.ts
Outdated
} | ||
|
||
export interface PluginsSetup { | ||
cloud: 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.
this should be CloudSetup
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.
609be5c4c218d1feed4b249158c438ce7c30f99d
x-pack/legacy/plugins/ml/kibana.json
Outdated
@@ -3,6 +3,7 @@ | |||
"version": "0.0.1", | |||
"kibanaVersion": "kibana", | |||
"configPath": ["ml"], | |||
"requiredPlugins": ["licensing"], | |||
"server": true, | |||
"ui": 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.
This file doesn't do anything in legacy. I would remove it completely.
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 609be5c4c218d1feed4b249158c438ce7c30f99d
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 |
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 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.
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 edits LGTM!
609be5c
to
2560317
Compare
retest |
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.
No major issues spotted 👍
makeMlUsageCollector(plugins.usageCollection, core.savedObjects); | ||
}); | ||
|
||
plugins.licensing.license$.subscribe(async license => { |
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.
Not a huge concern, but you should unsubscribe from this observable in the stop
phase.
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.
Oh good catch - added to checklist 👍
// 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, |
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.
How did this work before / what is the approach to solving this in the follow up?
2560317
to
53c2b6f
Compare
53c2b6f
to
3a872d5
Compare
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
* 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
* 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
Summary
Migrate legacy server to NP.
Create server plugin/index for
ml
inx-pack/plugins
Move all
legacy/server
files toplugins/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 toisEnabled
for now as the NP license check returns false forisAvailable
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.