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 job validation routes #57644

Conversation

alvarezmelissa87
Copy link
Contributor

@alvarezmelissa87 alvarezmelissa87 commented Feb 14, 2020

Summary

Related meta issue: #49743

Updates all job validation routes to use new platform router and replaces use of legacy elasticsearchPlugin in callWithInternalUserFactory with NP's context.core.elasticsearch.adminClient.callAsInternalUser

Also fixes type in migration doc.

Checklist

Delete any items that are not applicable to this PR.

@alvarezmelissa87 alvarezmelissa87 requested review from a team as code owners February 14, 2020 01:02
@alvarezmelissa87 alvarezmelissa87 self-assigned this Feb 14, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

@peteharverson peteharverson mentioned this pull request Feb 14, 2020
78 tasks
@alvarezmelissa87 alvarezmelissa87 changed the title [ML] New Platform server shim: update job validation routes WIP [ML] New Platform server shim: update job validation routes Feb 14, 2020
Copy link
Contributor

@pgayvallet pgayvallet left a comment

Choose a reason for hiding this comment

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

LGTM for platform, some nits and comments

EDIT: did not see this was a WIP. just some nits and comments then!

Comment on lines 11 to 12
callAsCurrentUser: IScopedClusterClient['callAsCurrentUser'],
callAsInternalUser: IScopedClusterClient['callAsInternalUser'],
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: Should use APICaller interface instead (same in other .d.ts file)

import { APICaller } from 'src/core/server';

export function estimateBucketSpanFactory(
  callAsCurrentUser: APICaller,
  callAsInternalUser: APICaller,

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 f0bac33e423d5a570bfa2ba8157a9d1e677c6afb

export function polledDataCheckerFactory(callWithRequest) {
export function polledDataCheckerFactory(callAsInternalUser) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it normal that callWithRequest was renamed to callAsInternalUser? shouldn't it be callAsCurrentUser instead? Or did the behavior change? (same question on some other files)

Copy link
Contributor Author

@alvarezmelissa87 alvarezmelissa87 Feb 14, 2020

Choose a reason for hiding this comment

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

Yep, you're right - I was thinking callAsInternalUser was getting passed in but it is callAsCurrentUser. I'll update it. Good catch 👌
Fixed in f0bac33e423d5a570bfa2ba8157a9d1e677c6afb

Comment on lines 7 to 8
import { CallAPIOptions } from 'kibana/server';
import { IScopedClusterClient } from 'src/core/server';
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: kibana/server and src/core/server are the same alias. Use only one import line.

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 f0bac33e423d5a570bfa2ba8157a9d1e677c6afb

import { anomalyDetectionJobSchema } from './anomaly_detectors_schema';

export const estimateBucketSpanSchema = {
aggTypes: schema.arrayOf(schema.nullable(schema.string())),
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: don't know the functional domain, but schema.arrayOf(schema.nullable(schema.string())) looks strange to me. can/should it really accept something like ['foo', null, 'bar', null] ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines 135 to 142
validate: {
body: schema.object(anomalyDetectionJobSchema),
},
Copy link
Contributor

Choose a reason for hiding this comment

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

(Already present before the PR, but) is there any reason the anomalyDetectionJobSchema is not already wrapped with a schema.object()? I see that some are and some aren't in x-pack/legacy/plugins/ml/server/new_platform/anomaly_detectors_schema.ts

* Routes for job validation
*/
export function jobValidationRoutes({ config, xpackMainPlugin, router }: RouteInitialization) {
function calculateModelMemoryLimit(context: RequestHandlerContext, payload: any) {
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: the handler calling that seems to have a proper body validation schema. Could probably get rid of the any signature here

type youWillNameThatBetterThanMePayload = TypeOf<typeof schema.object(modelMemoryLimitSchema)>

Copy link
Contributor Author

@alvarezmelissa87 alvarezmelissa87 Feb 14, 2020

Choose a reason for hiding this comment

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

This I did not know about and it is beautiful. I thank you 🙏
Updated in f0bac33e423d5a570bfa2ba8157a9d1e677c6afb

@alvarezmelissa87 alvarezmelissa87 force-pushed the ml-new-platform-job-validation-routes branch from 4e3fb2f to 728fa12 Compare February 14, 2020 15:56
@alvarezmelissa87 alvarezmelissa87 changed the title WIP [ML] New Platform server shim: update job validation routes [ML] New Platform server shim: update job validation routes Feb 14, 2020
Copy link
Contributor

@walterra walterra left a comment

Choose a reason for hiding this comment

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

LGTM

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.

LGTM

@alvarezmelissa87 alvarezmelissa87 force-pushed the ml-new-platform-job-validation-routes branch from c60bb3c to 6814dd8 Compare February 18, 2020 14:40
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

  • 💛 Build #26970 was flaky c60bb3c6666f8b614a18a0e04a7bdc1a5fa3a284
  • 💔 Build #26936 failed f0bac33e423d5a570bfa2ba8157a9d1e677c6afb
  • 💔 Build #26719 failed 4e3fb2f93d23208c6198c47c671f698c40879a5e

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

alvarezmelissa87 added a commit to alvarezmelissa87/kibana that referenced this pull request Feb 18, 2020
…57644)

* wip: convert jobValidation routes to NP

* fix typo in np migration docs

* replace legacy es plugin with callAsInternalUser from context

* add schema info for job validation routes

* update types and schema for job + cardinality validation

* update bucketSpanEstimator test

* update job validation schema
alvarezmelissa87 added a commit that referenced this pull request Feb 18, 2020
…57874)

* wip: convert jobValidation routes to NP

* fix typo in np migration docs

* replace legacy es plugin with callAsInternalUser from context

* add schema info for job validation routes

* update types and schema for job + cardinality validation

* update bucketSpanEstimator test

* update job validation schema
@alvarezmelissa87 alvarezmelissa87 deleted the ml-new-platform-job-validation-routes branch February 18, 2020 18: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 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants