Skip to content

Commit 7fd0ad2

Browse files
committed
Merge remote-tracking branch 'upstream/master' into 81738
2 parents e66c610 + 5e183dd commit 7fd0ad2

File tree

30 files changed

+3324
-312
lines changed

30 files changed

+3324
-312
lines changed

src/dev/build/tasks/patch_native_modules_task.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,30 @@ const packages: Package[] = [
4646
destinationPath: 'node_modules/re2/build/Release/re2.node',
4747
extractMethod: 'gunzip',
4848
archives: {
49-
darwin: {
49+
'darwin-x64': {
5050
url: 'https://github.com/uhop/node-re2/releases/download/1.15.4/darwin-x64-72.gz',
5151
sha256: '983106049bb86e21b7f823144b2b83e3f1408217401879b3cde0312c803512c9',
5252
},
53-
linux: {
53+
'linux-x64': {
5454
url: 'https://github.com/uhop/node-re2/releases/download/1.15.4/linux-x64-72.gz',
5555
sha256: '8b6692037f7b0df24dabc9c9b039038d1c3a3110f62121616b406c482169710a',
5656
},
57-
win32: {
57+
58+
// ARM build is currently done manually as Github Actions used in upstream project
59+
// do not natively support an ARM target.
60+
61+
// From a AWS Graviton instance:
62+
// * checkout the node-re2 project,
63+
// * install Node using the same minor used by Kibana
64+
// * npm install, which will also create a build
65+
// * gzip -c build/Release/re2.node > linux-arm64-72.gz
66+
// * upload to kibana-ci-proxy-cache bucket
67+
'linux-arm64': {
68+
url:
69+
'https://storage.googleapis.com/kibana-ci-proxy-cache/node-re2/uhop/node-re2/releases/download/1.15.4/linux-arm64-72.gz',
70+
sha256: '5942353ec9cf46a39199818d474f7af137cfbb1bc5727047fe22f31f36602a7e',
71+
},
72+
'win32-x64': {
5873
url: 'https://github.com/uhop/node-re2/releases/download/1.15.4/win32-x64-72.gz',
5974
sha256: '0a6991e693577160c3e9a3f196bd2518368c52d920af331a1a183313e0175604',
6075
},
@@ -84,7 +99,7 @@ async function patchModule(
8499
`Can't patch ${pkg.name}'s native module, we were expecting version ${pkg.version} and found ${installedVersion}`
85100
);
86101
}
87-
const platformName = platform.getName();
102+
const platformName = platform.getNodeArch();
88103
const archive = pkg.archives[platformName];
89104
const archiveName = path.basename(archive.url);
90105
const downloadPath = config.resolveFromRepo(DOWNLOAD_DIRECTORY, pkg.name, archiveName);

x-pack/plugins/ml/common/types/capabilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export function getPluginPrivileges() {
123123
catalogue: [],
124124
savedObject: {
125125
all: [],
126-
read: ['ml-job'],
126+
read: [ML_SAVED_OBJECT_TYPE],
127127
},
128128
api: apmUserMlCapabilitiesKeys.map((k) => `ml:${k}`),
129129
ui: apmUserMlCapabilitiesKeys,

x-pack/plugins/ml/common/types/saved_objects.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,12 @@ export interface InitializeSavedObjectResponse {
2727
success: boolean;
2828
error?: any;
2929
}
30+
31+
export interface DeleteJobCheckResponse {
32+
[jobId: string]: DeleteJobPermission;
33+
}
34+
35+
export interface DeleteJobPermission {
36+
canDelete: boolean;
37+
canUntag: boolean;
38+
}

x-pack/plugins/ml/server/lib/spaces_utils.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import { Legacy } from 'kibana';
88
import { KibanaRequest } from '../../../../../src/core/server';
99
import { SpacesPluginStart } from '../../../spaces/server';
10+
import { PLUGIN_ID } from '../../common/constants/app';
1011

1112
export type RequestFacade = KibanaRequest | Legacy.Request;
1213

@@ -22,19 +23,34 @@ export function spacesUtilsProvider(
2223
const space = await (await getSpacesPlugin()).spacesService.getActiveSpace(
2324
request instanceof KibanaRequest ? request : KibanaRequest.from(request)
2425
);
25-
return space.disabledFeatures.includes('ml') === false;
26+
return space.disabledFeatures.includes(PLUGIN_ID) === false;
2627
}
2728

28-
async function getAllSpaces(): Promise<string[] | null> {
29+
async function getAllSpaces() {
2930
if (getSpacesPlugin === undefined) {
3031
return null;
3132
}
3233
const client = (await getSpacesPlugin()).spacesService.createSpacesClient(
3334
request instanceof KibanaRequest ? request : KibanaRequest.from(request)
3435
);
35-
const spaces = await client.getAll();
36+
return await client.getAll();
37+
}
38+
39+
async function getAllSpaceIds(): Promise<string[] | null> {
40+
const spaces = await getAllSpaces();
41+
if (spaces === null) {
42+
return null;
43+
}
3644
return spaces.map((s) => s.id);
3745
}
3846

39-
return { isMlEnabledInSpace, getAllSpaces };
47+
async function getMlSpaceIds(): Promise<string[] | null> {
48+
const spaces = await getAllSpaces();
49+
if (spaces === null) {
50+
return null;
51+
}
52+
return spaces.filter((s) => s.disabledFeatures.includes(PLUGIN_ID) === false).map((s) => s.id);
53+
}
54+
55+
return { isMlEnabledInSpace, getAllSpaces, getAllSpaceIds, getMlSpaceIds };
4056
}

x-pack/plugins/ml/server/models/data_recognizer/data_recognizer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,9 @@ export class DataRecognizer {
10951095
job.config.analysis_limits.model_memory_limit = modelMemoryLimit;
10961096
}
10971097
} catch (error) {
1098-
mlLog.warn(`Data recognizer could not estimate model memory limit ${error.body}`);
1098+
mlLog.warn(
1099+
`Data recognizer could not estimate model memory limit ${JSON.stringify(error.body)}`
1100+
);
10991101
}
11001102
}
11011103

x-pack/plugins/ml/server/plugin.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,10 @@ export class MlServerPlugin
178178
notificationRoutes(routeInit);
179179
resultsServiceRoutes(routeInit);
180180
jobValidationRoutes(routeInit, this.version);
181-
savedObjectsRoutes(routeInit);
181+
savedObjectsRoutes(routeInit, {
182+
getSpaces,
183+
resolveMlCapabilities,
184+
});
182185
systemRoutes(routeInit, {
183186
getSpaces,
184187
cloud: plugins.cloud,

x-pack/plugins/ml/server/routes/apidoc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150
"AssignJobsToSpaces",
151151
"RemoveJobsFromSpaces",
152152
"JobsSpaces",
153+
"DeleteJobCheck",
153154

154155
"TrainedModels",
155156
"GetTrainedModel",

x-pack/plugins/ml/server/routes/saved_objects.ts

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@
55
*/
66

77
import { wrapError } from '../client/error_wrapper';
8-
import { RouteInitialization } from '../types';
8+
import { RouteInitialization, SavedObjectsRouteDeps } from '../types';
99
import { checksFactory, repairFactory } from '../saved_objects';
10-
import { jobsAndSpaces, repairJobObjects } from './schemas/saved_objects';
10+
import { jobsAndSpaces, repairJobObjects, jobTypeSchema } from './schemas/saved_objects';
11+
import { jobIdsSchema } from './schemas/job_service_schema';
1112

1213
/**
1314
* Routes for job saved object management
1415
*/
15-
export function savedObjectsRoutes({ router, routeGuard }: RouteInitialization) {
16+
export function savedObjectsRoutes(
17+
{ router, routeGuard }: RouteInitialization,
18+
{ getSpaces, resolveMlCapabilities }: SavedObjectsRouteDeps
19+
) {
1620
/**
1721
* @apiGroup JobSavedObjects
1822
*
@@ -220,4 +224,50 @@ export function savedObjectsRoutes({ router, routeGuard }: RouteInitialization)
220224
}
221225
})
222226
);
227+
228+
/**
229+
* @apiGroup JobSavedObjects
230+
*
231+
* @api {get} /api/ml/saved_objects/delete_job_check Check whether user can delete a job
232+
* @apiName DeleteJobCheck
233+
* @apiDescription Check the user's ability to delete jobs. Returns whether they are able
234+
* to fully delete the job and whether they are able to remove it from
235+
* the current space.
236+
*
237+
* @apiSchema (body) jobIdsSchema (params) jobTypeSchema
238+
*
239+
*/
240+
router.post(
241+
{
242+
path: '/api/ml/saved_objects/can_delete_job/{jobType}',
243+
validate: {
244+
params: jobTypeSchema,
245+
body: jobIdsSchema,
246+
},
247+
options: {
248+
tags: ['access:ml:canGetJobs', 'access:ml:canGetDataFrameAnalytics'],
249+
},
250+
},
251+
routeGuard.fullLicenseAPIGuard(async ({ request, response, jobSavedObjectService, client }) => {
252+
try {
253+
const { jobType } = request.params;
254+
const { jobIds }: { jobIds: string[] } = request.body;
255+
256+
const { canDeleteJobs } = checksFactory(client, jobSavedObjectService);
257+
const body = await canDeleteJobs(
258+
request,
259+
jobType,
260+
jobIds,
261+
getSpaces !== undefined,
262+
resolveMlCapabilities
263+
);
264+
265+
return response.ok({
266+
body,
267+
});
268+
} catch (e) {
269+
return response.customError(wrapError(e));
270+
}
271+
})
272+
);
223273
}

x-pack/plugins/ml/server/routes/schemas/saved_objects.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ export const jobsAndSpaces = schema.object({
1313
});
1414

1515
export const repairJobObjects = schema.object({ simulate: schema.maybe(schema.boolean()) });
16+
17+
export const jobTypeSchema = schema.object({
18+
jobType: schema.string(),
19+
});

x-pack/plugins/ml/server/saved_objects/authorization.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import { KibanaRequest } from 'kibana/server';
88
import type { SecurityPluginSetup } from '../../../security/server';
9+
import { ML_SAVED_OBJECT_TYPE } from '../../common/types/saved_objects';
910

1011
export function authorizationProvider(authorization: SecurityPluginSetup['authz']) {
1112
async function authorizationCheck(request: KibanaRequest) {
@@ -18,7 +19,7 @@ export function authorizationProvider(authorization: SecurityPluginSetup['authz'
1819
request
1920
);
2021
const createMLJobAuthorizationAction = authorization.actions.savedObject.get(
21-
'ml-job',
22+
ML_SAVED_OBJECT_TYPE,
2223
'create'
2324
);
2425
const canCreateGlobally = (

0 commit comments

Comments
 (0)