-
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 job validation routes #57644
[ML] New Platform server shim: update job validation routes #57644
Conversation
Pinging @elastic/ml-ui (: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.
LGTM for platform, some nits and comments
EDIT: did not see this was a WIP. just some nits and comments then!
callAsCurrentUser: IScopedClusterClient['callAsCurrentUser'], | ||
callAsInternalUser: IScopedClusterClient['callAsInternalUser'], |
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.
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,
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 f0bac33e423d5a570bfa2ba8157a9d1e677c6afb
export function polledDataCheckerFactory(callWithRequest) { | ||
export function polledDataCheckerFactory(callAsInternalUser) { |
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.
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)
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.
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
import { CallAPIOptions } from 'kibana/server'; | ||
import { IScopedClusterClient } from 'src/core/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.
NIT: kibana/server
and src/core/server
are the same alias. Use only one import line.
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 f0bac33e423d5a570bfa2ba8157a9d1e677c6afb
import { anomalyDetectionJobSchema } from './anomaly_detectors_schema'; | ||
|
||
export const estimateBucketSpanSchema = { | ||
aggTypes: schema.arrayOf(schema.nullable(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.
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]
?
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.
Yep - so this was based on the BucketEstimatorData
type interface (https://github.com/elastic/kibana/blob/master/x-pack/legacy/plugins/ml/public/application/services/ml_api_service/index.d.ts#L48) used to define the type of data sent to the bucket span estimator endpoint.
validate: { | ||
body: schema.object(anomalyDetectionJobSchema), | ||
}, |
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.
(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) { |
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.
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)>
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 I did not know about and it is beautiful. I thank you 🙏
Updated in f0bac33e423d5a570bfa2ba8157a9d1e677c6afb
4e3fb2f
to
728fa12
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.
LGTM
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
c60bb3c
to
6814dd8
Compare
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
…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
…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
Summary
Related meta issue: #49743
Updates all job validation routes to use new platform router and replaces use of legacy
elasticsearchPlugin
incallWithInternalUserFactory
with NP'scontext.core.elasticsearch.adminClient.callAsInternalUser
Also fixes type in migration doc.
Checklist
Delete any items that are not applicable to this PR.