[ML] Adding get records endpoint wrapper (#58500) (#58574)

This commit is contained in:
James Gowdy 2020-02-26 12:41:36 +00:00 committed by GitHub
parent e8ebaeb59a
commit 94fb794386
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 1 deletions

View file

@ -451,6 +451,18 @@ export const elasticsearchJsPlugin = (Client, config, components) => {
method: 'POST',
});
ml.records = ca({
url: {
fmt: '/_ml/anomaly_detectors/<%=jobId%>/results/records',
req: {
jobId: {
type: 'string',
},
},
},
method: 'POST',
});
ml.buckets = ca({
urls: [
{

View file

@ -376,11 +376,57 @@ export function jobRoutes({ xpackMainPlugin, router }: RouteInitialization) {
})
);
/**
* @apiGroup AnomalyDetectors
*
* @api {post} /api/ml/anomaly_detectors/:jobId/results/records Retrieves anomaly records for a job.
* @apiName GetRecords
* @apiDescription Retrieves anomaly records for a job.
*
* @apiParam {String} jobId Job ID.
*
* @apiSuccess {Number} count
* @apiSuccess {Object[]} records
*/
router.post(
{
path: '/api/ml/anomaly_detectors/{jobId}/results/records',
validate: {
params: schema.object({
jobId: schema.string(),
}),
body: schema.object({
desc: schema.maybe(schema.boolean()),
end: schema.maybe(schema.string()),
exclude_interim: schema.maybe(schema.boolean()),
'page.from': schema.maybe(schema.number()),
'page.size': schema.maybe(schema.number()),
record_score: schema.maybe(schema.number()),
sort: schema.maybe(schema.string()),
start: schema.maybe(schema.string()),
}),
},
},
licensePreRoutingFactory(xpackMainPlugin, async (context, request, response) => {
try {
const results = await context.ml!.mlClient.callAsCurrentUser('ml.records', {
jobId: request.params.jobId,
...request.body,
});
return response.ok({
body: results,
});
} catch (e) {
return response.customError(wrapError(e));
}
})
);
/**
* @apiGroup AnomalyDetectors
*
* @api {post} /api/ml/anomaly_detectors/:jobId/results/buckets Obtain bucket scores for the specified job ID
* @apiName GetOverallBuckets
* @apiName GetBuckets
* @apiDescription The get buckets API presents a chronological view of the records, grouped by bucket.
*
* @apiParam {String} jobId Job ID.

View file

@ -31,6 +31,8 @@
"DeleteAnomalyDetectorsJob",
"ValidateAnomalyDetector",
"ForecastAnomalyDetector",
"GetRecords",
"GetBuckets",
"GetOverallBuckets",
"GetCategories",
"FileDataVisualizer",