forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML] New Platform server shim: update job audit messages routes (elas…
…tic#57925) * migrate all job audit messages routes to NP * update types and add missing api names from validation
- Loading branch information
1 parent
71bda5f
commit 664d6a4
Showing
7 changed files
with
116 additions
and
46 deletions.
There are no files selected for viewing
File renamed without changes.
14 changes: 14 additions & 0 deletions
14
x-pack/legacy/plugins/ml/server/models/job_audit_messages/job_audit_messages.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { APICaller } from 'src/core/server'; | ||
|
||
export function jobAuditMessagesProvider( | ||
callAsCurrentUser: APICaller | ||
): { | ||
getJobAuditMessages: (jobId?: string, from?: string) => any; | ||
getAuditMessagesSummary: (jobIds?: string[]) => any; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 0 additions & 40 deletions
40
x-pack/legacy/plugins/ml/server/routes/job_audit_messages.js
This file was deleted.
Oops, something went wrong.
81 changes: 81 additions & 0 deletions
81
x-pack/legacy/plugins/ml/server/routes/job_audit_messages.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { schema } from '@kbn/config-schema'; | ||
import { licensePreRoutingFactory } from '../new_platform/licence_check_pre_routing_factory'; | ||
import { wrapError } from '../client/error_wrapper'; | ||
import { RouteInitialization } from '../new_platform/plugin'; | ||
import { jobAuditMessagesProvider } from '../models/job_audit_messages'; | ||
|
||
/** | ||
* Routes for job audit message routes | ||
*/ | ||
export function jobAuditMessagesRoutes({ xpackMainPlugin, router }: RouteInitialization) { | ||
/** | ||
* @apiGroup JobAuditMessages | ||
* | ||
* @api {get} /api/ml/job_audit_messages/messages/:jobId Get audit messages | ||
* @apiName GetJobAuditMessages | ||
* @apiDescription Returns audit messages for specified job ID | ||
*/ | ||
router.get( | ||
{ | ||
path: '/api/ml/job_audit_messages/messages/{jobId}', | ||
validate: { | ||
params: schema.object({ jobId: schema.maybe(schema.string()) }), | ||
query: schema.maybe(schema.object({ from: schema.maybe(schema.any()) })), | ||
}, | ||
}, | ||
licensePreRoutingFactory(xpackMainPlugin, async (context, request, response) => { | ||
try { | ||
const { getJobAuditMessages } = jobAuditMessagesProvider( | ||
context.ml!.mlClient.callAsCurrentUser | ||
); | ||
const { jobId } = request.params; | ||
const { from } = request.query; | ||
const resp = await getJobAuditMessages(jobId, from); | ||
|
||
return response.ok({ | ||
body: resp, | ||
}); | ||
} catch (e) { | ||
return response.customError(wrapError(e)); | ||
} | ||
}) | ||
); | ||
|
||
/** | ||
* @apiGroup JobAuditMessages | ||
* | ||
* @api {get} /api/ml/results/anomalies_table_data Get all audit messages | ||
* @apiName GetAllJobAuditMessages | ||
* @apiDescription Returns all audit messages | ||
*/ | ||
router.get( | ||
{ | ||
path: '/api/ml/job_audit_messages/messages', | ||
validate: { | ||
params: schema.object({ jobId: schema.maybe(schema.string()) }), | ||
query: schema.maybe(schema.object({ from: schema.maybe(schema.any()) })), | ||
}, | ||
}, | ||
licensePreRoutingFactory(xpackMainPlugin, async (context, request, response) => { | ||
try { | ||
const { getJobAuditMessages } = jobAuditMessagesProvider( | ||
context.ml!.mlClient.callAsCurrentUser | ||
); | ||
const { from } = request.query; | ||
const resp = await getJobAuditMessages(undefined, from); | ||
|
||
return response.ok({ | ||
body: resp, | ||
}); | ||
} catch (e) { | ||
return response.customError(wrapError(e)); | ||
} | ||
}) | ||
); | ||
} |