-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…58222) * update fieldsService routes to use NP router * fix file name typo * add routes names for docs
- Loading branch information
1 parent
d07f36a
commit 1fbd460
Showing
7 changed files
with
137 additions
and
54 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
x-pack/legacy/plugins/ml/server/models/fields_service/fields_service.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,21 @@ | ||
/* | ||
* 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 fieldsServiceProvider( | ||
callAsCurrentUser: APICaller | ||
): { | ||
getCardinalityOfFields: ( | ||
index: string[] | string, | ||
fieldNames: string[], | ||
query: any, | ||
timeFieldName: string, | ||
earliestMs: number, | ||
latestMs: number | ||
) => Promise<any>; | ||
getTimeFieldRange: (index: string[] | string, timeFieldName: string, query: any) => Promise<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
File renamed without changes.
22 changes: 22 additions & 0 deletions
22
x-pack/legacy/plugins/ml/server/new_platform/fields_service_schema.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,22 @@ | ||
/* | ||
* 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'; | ||
|
||
export const getCardinalityOfFieldsSchema = schema.object({ | ||
index: schema.oneOf([schema.string(), schema.arrayOf(schema.string())]), | ||
fieldNames: schema.maybe(schema.arrayOf(schema.string())), | ||
query: schema.maybe(schema.any()), | ||
timeFieldName: schema.maybe(schema.string()), | ||
earliestMs: schema.maybe(schema.oneOf([schema.number(), schema.string()])), | ||
latestMs: schema.maybe(schema.oneOf([schema.number(), schema.string()])), | ||
}); | ||
|
||
export const getTimeFieldRangeSchema = schema.object({ | ||
index: schema.oneOf([schema.string(), schema.arrayOf(schema.string())]), | ||
timeFieldName: schema.maybe(schema.string()), | ||
query: schema.maybe(schema.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 was deleted.
Oops, something went wrong.
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,86 @@ | ||
/* | ||
* 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 { RequestHandlerContext } from 'src/core/server'; | ||
import { licensePreRoutingFactory } from '../new_platform/licence_check_pre_routing_factory'; | ||
import { wrapError } from '../client/error_wrapper'; | ||
import { RouteInitialization } from '../new_platform/plugin'; | ||
import { | ||
getCardinalityOfFieldsSchema, | ||
getTimeFieldRangeSchema, | ||
} from '../new_platform/fields_service_schema'; | ||
import { fieldsServiceProvider } from '../models/fields_service'; | ||
|
||
function getCardinalityOfFields(context: RequestHandlerContext, payload: any) { | ||
const fs = fieldsServiceProvider(context.ml!.mlClient.callAsCurrentUser); | ||
const { index, fieldNames, query, timeFieldName, earliestMs, latestMs } = payload; | ||
return fs.getCardinalityOfFields(index, fieldNames, query, timeFieldName, earliestMs, latestMs); | ||
} | ||
|
||
function getTimeFieldRange(context: RequestHandlerContext, payload: any) { | ||
const fs = fieldsServiceProvider(context.ml!.mlClient.callAsCurrentUser); | ||
const { index, timeFieldName, query } = payload; | ||
return fs.getTimeFieldRange(index, timeFieldName, query); | ||
} | ||
|
||
/** | ||
* Routes for fields service | ||
*/ | ||
export function fieldsService({ xpackMainPlugin, router }: RouteInitialization) { | ||
/** | ||
* @apiGroup FieldsService | ||
* | ||
* @api {post} /api/ml/fields_service/field_cardinality Get cardinality of fields | ||
* @apiName GetCardinalityOfFields | ||
* @apiDescription Returns the cardinality of one or more fields. Returns an Object whose keys are the names of the fields, with values equal to the cardinality of the field | ||
*/ | ||
router.post( | ||
{ | ||
path: '/api/ml/fields_service/field_cardinality', | ||
validate: { | ||
body: getCardinalityOfFieldsSchema, | ||
}, | ||
}, | ||
licensePreRoutingFactory(xpackMainPlugin, async (context, request, response) => { | ||
try { | ||
const resp = await getCardinalityOfFields(context, request.body); | ||
|
||
return response.ok({ | ||
body: resp, | ||
}); | ||
} catch (e) { | ||
return response.customError(wrapError(e)); | ||
} | ||
}) | ||
); | ||
|
||
/** | ||
* @apiGroup FieldsService | ||
* | ||
* @api {post} /api/ml/fields_service/time_field_range Get time field range | ||
* @apiName GetTimeFieldRange | ||
* @apiDescription Returns the timefield range for the given index | ||
*/ | ||
router.post( | ||
{ | ||
path: '/api/ml/fields_service/time_field_range', | ||
validate: { | ||
body: getTimeFieldRangeSchema, | ||
}, | ||
}, | ||
licensePreRoutingFactory(xpackMainPlugin, async (context, request, response) => { | ||
try { | ||
const resp = await getTimeFieldRange(context, request.body); | ||
|
||
return response.ok({ | ||
body: resp, | ||
}); | ||
} catch (e) { | ||
return response.customError(wrapError(e)); | ||
} | ||
}) | ||
); | ||
} |