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] Changing shared module setup function parameters #70589

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ export class DataRecognizer {
// takes a module config id, an optional jobPrefix and the request object
// creates all of the jobs, datafeeds and savedObjects listed in the module config.
// if any of the savedObjects already exist, they will not be overwritten.
async setupModuleItems(
async setup(
moduleId: string,
jobPrefix?: string,
groups?: string[],
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/ml/server/routes/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function getModule(context: RequestHandlerContext, moduleId: string) {
}
}

function saveModuleItems(
function setup(
context: RequestHandlerContext,
moduleId: string,
prefix?: string,
Expand All @@ -57,7 +57,7 @@ function saveModuleItems(
context.ml!.mlClient.callAsCurrentUser,
context.core.savedObjects.client
);
return dr.setupModuleItems(
return dr.setup(
moduleId,
prefix,
groups,
Expand Down Expand Up @@ -438,7 +438,7 @@ export function dataRecognizer({ router, mlLicense }: RouteInitialization) {
estimateModelMemory,
} = request.body as TypeOf<typeof setupModuleBodySchema>;

const result = await saveModuleItems(
const result = await setup(
context,
moduleId,
prefix,
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/ml/server/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
export * from '../common/types/anomalies';
export * from '../common/types/anomaly_detection_jobs';
export * from './lib/capabilities/errors';
export { ModuleSetupPayload } from './shared_services/providers/modules';
23 changes: 20 additions & 3 deletions x-pack/plugins/ml/server/shared_services/providers/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
*/

import { LegacyAPICaller, KibanaRequest, SavedObjectsClientContract } from 'kibana/server';
import { TypeOf } from '@kbn/config-schema';
import { DataRecognizer } from '../../models/data_recognizer';
import { SharedServicesChecks } from '../shared_services';
import { setupModuleBodySchema } from '../../routes/schemas/modules';

export type ModuleSetupPayload = { moduleId: string } & TypeOf<typeof setupModuleBodySchema>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
export type ModuleSetupPayload = { moduleId: string } & TypeOf<typeof setupModuleBodySchema>;
export type ModuleSetupPayload = TypeOf<typeof moduleIdParamSchema> & TypeOf<typeof setupModuleBodySchema>;


export interface ModulesProvider {
modulesProvider(
Expand All @@ -17,7 +21,7 @@ export interface ModulesProvider {
recognize: DataRecognizer['findMatches'];
getModule: DataRecognizer['getModule'];
listModules: DataRecognizer['listModules'];
setupModuleItems: DataRecognizer['setupModuleItems'];
setup(payload: ModuleSetupPayload): ReturnType<DataRecognizer['setup']>;
};
}

Expand Down Expand Up @@ -52,11 +56,24 @@ export function getModulesProvider({

return dr.listModules();
},
async setupModuleItems(...args) {
async setup(payload: ModuleSetupPayload) {
isFullLicense();
await hasMlCapabilities(['canCreateJob']);

return dr.setupModuleItems(...args);
return dr.setup(
payload.moduleId,
payload.prefix,
payload.groups,
payload.indexPatternName,
payload.query,
payload.useDedicatedIndex,
payload.startDatafeed,
payload.start,
payload.end,
payload.jobOverrides,
payload.datafeedOverrides,
payload.estimateModelMemory
);
},
};
},
Expand Down