Skip to content

Commit

Permalink
fix results service schema (#57217)
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarezmelissa87 committed Feb 11, 2020
1 parent 3610c8f commit 8e1edf1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ const criteriaFieldSchema = schema.object({
export const anomaliesTableDataSchema = {
jobIds: schema.arrayOf(schema.string()),
criteriaFields: schema.arrayOf(criteriaFieldSchema),
influencers: schema.arrayOf(schema.maybe(schema.string())),
influencers: schema.arrayOf(
schema.maybe(schema.object({ fieldName: schema.string(), fieldValue: schema.any() }))
),
aggregationInterval: schema.string(),
threshold: schema.number(),
earliestMs: schema.number(),
Expand All @@ -26,6 +28,23 @@ export const anomaliesTableDataSchema = {
influencersFilterQuery: schema.maybe(schema.any()),
};

export const categoryDefinitionSchema = {
jobId: schema.maybe(schema.string()),
categoryId: schema.string(),
};

export const maxAnomalyScoreSchema = {
jobIds: schema.arrayOf(schema.string()),
earliestMs: schema.number(),
latestMs: schema.number(),
};

export const categoryExamplesSchema = {
jobId: schema.string(),
categoryIds: schema.arrayOf(schema.string()),
maxExamples: schema.number(),
};

export const partitionFieldValuesSchema = {
jobId: schema.string(),
searchTerm: schema.maybe(schema.any()),
Expand Down
24 changes: 8 additions & 16 deletions x-pack/legacy/plugins/ml/server/routes/results_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import { wrapError } from '../client/error_wrapper';
import { RouteInitialization } from '../new_platform/plugin';
import {
anomaliesTableDataSchema,
categoryDefinitionSchema,
categoryExamplesSchema,
maxAnomalyScoreSchema,
partitionFieldValuesSchema,
} from '../new_platform/results_service_schema';
import { resultsServiceProvider } from '../models/results_service';
Expand Down Expand Up @@ -83,7 +86,7 @@ export function resultsServiceRoutes({ xpackMainPlugin, router }: RouteInitializ
{
path: '/api/ml/results/anomalies_table_data',
validate: {
body: schema.object({ ...anomaliesTableDataSchema }),
body: schema.object(anomaliesTableDataSchema),
},
},
licensePreRoutingFactory(xpackMainPlugin, async (context, request, response) => {
Expand All @@ -110,10 +113,7 @@ export function resultsServiceRoutes({ xpackMainPlugin, router }: RouteInitializ
{
path: '/api/ml/results/category_definition',
validate: {
body: schema.object({
jobId: schema.maybe(schema.string()),
categoryId: schema.string(),
}),
body: schema.object(categoryDefinitionSchema),
},
},
licensePreRoutingFactory(xpackMainPlugin, async (context, request, response) => {
Expand All @@ -140,11 +140,7 @@ export function resultsServiceRoutes({ xpackMainPlugin, router }: RouteInitializ
{
path: '/api/ml/results/max_anomaly_score',
validate: {
body: schema.object({
jobIds: schema.arrayOf(schema.string()),
earliestMs: schema.number(),
latestMs: schema.number(),
}),
body: schema.object(maxAnomalyScoreSchema),
},
},
licensePreRoutingFactory(xpackMainPlugin, async (context, request, response) => {
Expand All @@ -171,11 +167,7 @@ export function resultsServiceRoutes({ xpackMainPlugin, router }: RouteInitializ
{
path: '/api/ml/results/category_examples',
validate: {
body: schema.object({
jobId: schema.string(),
categoryIds: schema.arrayOf(schema.string()),
maxExamples: schema.number(),
}),
body: schema.object(categoryExamplesSchema),
},
},
licensePreRoutingFactory(xpackMainPlugin, async (context, request, response) => {
Expand All @@ -202,7 +194,7 @@ export function resultsServiceRoutes({ xpackMainPlugin, router }: RouteInitializ
{
path: '/api/ml/results/partition_fields_values',
validate: {
body: schema.object({ ...partitionFieldValuesSchema }),
body: schema.object(partitionFieldValuesSchema),
},
},
licensePreRoutingFactory(xpackMainPlugin, async (context, request, response) => {
Expand Down

0 comments on commit 8e1edf1

Please sign in to comment.