Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] Transforms: API schemas and integration tests #75164

Merged
merged 53 commits into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
2a2c3f3
[ML] Transform list API integration test.
walterra Aug 12, 2020
3bdeb4f
[ML] Get single transform API integration test.
walterra Aug 18, 2020
3c5eaf2
[ML] Transform stats API integration test.
walterra Aug 18, 2020
9f3643a
[ML] Transform preview API integration test.
walterra Aug 18, 2020
ed353b0
[ML] Transform update API integration test.
walterra Aug 19, 2020
9a657b1
[ML] Fix flakyness.
walterra Aug 19, 2020
9de6d56
[ML] WIP: API schemas and API integration tests for starting transforms.
walterra Aug 20, 2020
53240e8
[ML] Delete tmp utility file.
walterra Aug 20, 2020
a2014c0
[Ml] Fix to import types only of schema based definitions and not bre…
walterra Aug 20, 2020
ddb8a0a
[ML] Fix types and tests imports.
walterra Aug 20, 2020
251787a
[ML] Fix imports.
walterra Aug 21, 2020
130d389
[ML] Fix delete transforms endpoint.
walterra Aug 21, 2020
c980a1a
[ML] Fix start transforms API tests.
walterra Aug 21, 2020
41b9e46
[ML] Stabilize tests. Adds stop API integration tests.
walterra Aug 21, 2020
d5c9732
[ML] Type related fixes.
walterra Aug 21, 2020
367ae78
[ML] Stabilize tests.
walterra Aug 22, 2020
b79763a
[ML] Stabilize tests.
walterra Aug 24, 2020
fb95487
[ML] Improve types for transforms API endpoint.
walterra Aug 26, 2020
1a1f7e7
[ML] Improve types for transforms stats API endpoint.
walterra Aug 26, 2020
da88f4f
[ML] More API schemas.
walterra Aug 27, 2020
5770291
[ML] Fix source index name.
walterra Aug 27, 2020
572ff97
[ML] Fix imports.
walterra Aug 27, 2020
e907bf8
[ML] Fix import to avoid breaking the optimizer.
walterra Aug 27, 2020
15850c2
[ML] API schema for update transform endpoint.
walterra Aug 31, 2020
df55fa5
[ML] API schema for audit messages transform endpoint.
walterra Aug 31, 2020
2c3223d
[ML] Add API docs.
walterra Aug 31, 2020
6398c95
[ML] Fix apidoc config.
walterra Aug 31, 2020
e6ccf1d
[ML] Fix TS projects.
walterra Aug 31, 2020
794d2d0
[ML] Revert script changes.
walterra Aug 31, 2020
15649c1
[ML] Extend time to wait for updated message.
walterra Sep 1, 2020
f3fda76
[ML] Make e2e transform ids more unique.
walterra Sep 1, 2020
082527a
[ML] Delete all transform notification indices as part of cleanup.
walterra Sep 1, 2020
0776ed3
Merge branch 'master' into ml-transforms-api-tests
walterra Sep 7, 2020
7fbd278
[ML] Infer type for IndexPatternTitleSchema.
walterra Sep 7, 2020
a35ea1e
[ML] Simplify mock.
walterra Sep 7, 2020
cfe297f
[ML] Improve types for guardApiRoute.
walterra Sep 7, 2020
8b22029
[ML] Refactor transform client API.
walterra Sep 8, 2020
c7e7144
Merge branch 'master' into ml-transforms-api-tests
walterra Sep 9, 2020
5cfce0b
Merge branch 'master' into ml-transforms-api-tests
walterra Sep 9, 2020
894b1f8
[ML] Fix type guards.
walterra Sep 9, 2020
e434c4f
[ML] Use TRANSFORM_STATE instead of raw strings.
walterra Sep 10, 2020
7725de8
Merge branch 'master' into ml-transforms-api-tests
walterra Sep 10, 2020
7329dea
[ML] Fix types.
walterra Sep 10, 2020
b63d86d
[ML] Extend stats assertions.
walterra Sep 10, 2020
c47f2b0
[ML] Fix error toasts.
walterra Sep 10, 2020
28ad1f2
[ML] Extend transforms assertions.
walterra Sep 10, 2020
2320fbc
[ML] Text tweak.
walterra Sep 10, 2020
efcf9b3
[ML] Extend stop transforms assertions.
walterra Sep 10, 2020
c6f388f
[ML] Extend transforms assertions.
walterra Sep 10, 2020
cd3703a
[ML] Better transforms ids.
walterra Sep 10, 2020
221c920
[ML] Add comment to clarify destructuring.
walterra Sep 10, 2020
00bdc3b
Merge branch 'master' into ml-transforms-api-tests
walterra Sep 14, 2020
67b32a8
Merge branch 'master' into ml-transforms-api-tests
walterra Sep 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions x-pack/plugins/ml/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* 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.
*/

export { SearchResponse7 } from './types/es_client';
25 changes: 25 additions & 0 deletions x-pack/plugins/ml/common/types/es_client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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 { SearchResponse, ShardsResponse } from 'elasticsearch';

// The types specified in `@types/elasticsearch` are out of date and still have `total: number`.
interface SearchResponse7Hits<T> {
hits: SearchResponse<T>['hits']['hits'];
max_score: number;
total: {
value: number;
relation: string;
};
}
export interface SearchResponse7<T = any> {
took: number;
timed_out: boolean;
_scroll_id?: string;
_shards: ShardsResponse;
hits: SearchResponse7Hits<T>;
aggregations?: any;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export {
DataGridItem,
EsSorting,
RenderCellValue,
SearchResponse7,
UseDataGridReturnType,
UseIndexDataReturnType,
} from './types';
11 changes: 0 additions & 11 deletions x-pack/plugins/ml/public/application/components/data_grid/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import { Dispatch, SetStateAction } from 'react';
import { SearchResponse } from 'elasticsearch';

import { EuiDataGridPaginationProps, EuiDataGridSorting, EuiDataGridColumn } from '@elastic/eui';

Expand Down Expand Up @@ -43,16 +42,6 @@ export type EsSorting = Dictionary<{
order: 'asc' | 'desc';
}>;

// The types specified in `@types/elasticsearch` are out of date and still have `total: number`.
export interface SearchResponse7 extends SearchResponse<any> {
hits: SearchResponse<any>['hits'] & {
total: {
value: number;
relation: string;
};
};
}

export interface UseIndexDataReturnType
extends Pick<
UseDataGridReturnType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/

import type { SearchResponse7 } from '../../../../common/types/es_client';
import { getErrorMessage } from '../../../../common/util/errors';

import { EsSorting, SearchResponse7, UseDataGridReturnType } from '../../components/data_grid';
import { EsSorting, UseDataGridReturnType } from '../../components/data_grid';
import { ml } from '../../services/ml_api_service';

import { isKeywordAndTextType } from '../common/fields';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import {
useDataGrid,
useRenderCellValue,
EsSorting,
SearchResponse7,
UseIndexDataReturnType,
} from '../../../../components/data_grid';
import type { SearchResponse7 } from '../../../../../../common/types/es_client';
import { getErrorMessage } from '../../../../../../common/util/errors';
import { INDEX_STATUS } from '../../../common/analytics';
import { ml } from '../../../../services/ml_api_service';
Expand Down
9 changes: 9 additions & 0 deletions x-pack/plugins/transform/common/api_schemas/audit_messages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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 { TransformMessage } from '../types/messages';

export type GetTransformsAuditMessagesResponseSchema = TransformMessage[];
48 changes: 48 additions & 0 deletions x-pack/plugins/transform/common/api_schemas/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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, TypeOf } from '@kbn/config-schema';

import { TRANSFORM_STATE } from '../constants';

export const transformIdsSchema = schema.arrayOf(
schema.object({
id: schema.string(),
})
);

export type TransformIdsSchema = TypeOf<typeof transformIdsSchema>;

export const transformStateSchema = schema.oneOf([
schema.literal(TRANSFORM_STATE.ABORTING),
schema.literal(TRANSFORM_STATE.FAILED),
schema.literal(TRANSFORM_STATE.INDEXING),
schema.literal(TRANSFORM_STATE.STARTED),
schema.literal(TRANSFORM_STATE.STOPPED),
schema.literal(TRANSFORM_STATE.STOPPING),
]);

export const indexPatternTitleSchema = schema.object({
/** Title of the index pattern for which to return stats. */
indexPatternTitle: schema.string(),
});

export type IndexPatternTitleSchema = TypeOf<typeof indexPatternTitleSchema>;

export const transformIdParamSchema = schema.object({
transformId: schema.string(),
});

export type TransformIdParamSchema = TypeOf<typeof transformIdParamSchema>;

export interface ResponseStatus {
success: boolean;
error?: any;
}

export interface CommonResponseStatusSchema {
[key: string]: ResponseStatus;
}
37 changes: 37 additions & 0 deletions x-pack/plugins/transform/common/api_schemas/delete_transforms.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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, TypeOf } from '@kbn/config-schema';

import { transformStateSchema, ResponseStatus } from './common';

export const deleteTransformsRequestSchema = schema.object({
/**
* Delete Transform & Destination Index
*/
transformsInfo: schema.arrayOf(
schema.object({
id: schema.string(),
state: transformStateSchema,
})
),
deleteDestIndex: schema.maybe(schema.boolean()),
deleteDestIndexPattern: schema.maybe(schema.boolean()),
forceDelete: schema.maybe(schema.boolean()),
});

export type DeleteTransformsRequestSchema = TypeOf<typeof deleteTransformsRequestSchema>;

export interface DeleteTransformStatus {
transformDeleted: ResponseStatus;
destIndexDeleted?: ResponseStatus;
destIndexPatternDeleted?: ResponseStatus;
destinationIndex?: string | undefined;
}

export interface DeleteTransformsResponseSchema {
[key: string]: DeleteTransformStatus;
}
19 changes: 19 additions & 0 deletions x-pack/plugins/transform/common/api_schemas/field_histograms.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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, TypeOf } from '@kbn/config-schema';

export const fieldHistogramsRequestSchema = schema.object({
/** Query to match documents in the index. */
query: schema.any(),
/** The fields to return histogram data. */
fields: schema.arrayOf(schema.any()),
/** Number of documents to be collected in the sample processed on each shard, or -1 for no sampling. */
samplerShardSize: schema.number(),
});

export type FieldHistogramsRequestSchema = TypeOf<typeof fieldHistogramsRequestSchema>;
export type FieldHistogramsResponseSchema = any[];
13 changes: 13 additions & 0 deletions x-pack/plugins/transform/common/api_schemas/start_transforms.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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 { TypeOf } from '@kbn/config-schema';

import { transformIdsSchema, CommonResponseStatusSchema } from './common';

export const startTransformsRequestSchema = transformIdsSchema;
export type StartTransformsRequestSchema = TypeOf<typeof startTransformsRequestSchema>;
export type StartTransformsResponseSchema = CommonResponseStatusSchema;
19 changes: 19 additions & 0 deletions x-pack/plugins/transform/common/api_schemas/stop_transforms.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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, TypeOf } from '@kbn/config-schema';

import { transformStateSchema, CommonResponseStatusSchema } from './common';

export const stopTransformsRequestSchema = schema.arrayOf(
schema.object({
id: schema.string(),
state: transformStateSchema,
})
);

export type StopTransformsRequestSchema = TypeOf<typeof stopTransformsRequestSchema>;
export type StopTransformsResponseSchema = CommonResponseStatusSchema;
127 changes: 127 additions & 0 deletions x-pack/plugins/transform/common/api_schemas/transforms.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* 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, TypeOf } from '@kbn/config-schema';

import type { ES_FIELD_TYPES } from '../../../../../src/plugins/data/common';

import type { Dictionary } from '../types/common';
import type { PivotAggDict } from '../types/pivot_aggs';
import type { PivotGroupByDict } from '../types/pivot_group_by';
import type { TransformId, TransformPivotConfig } from '../types/transform';

import { transformStateSchema } from './common';

// GET transforms
export const getTransformsRequestSchema = schema.arrayOf(
schema.object({
id: schema.string(),
state: transformStateSchema,
})
);

export type GetTransformsRequestSchema = TypeOf<typeof getTransformsRequestSchema>;

export interface GetTransformsResponseSchema {
count: number;
transforms: TransformPivotConfig[];
}

// schemas shared by parts of the preview, create and update endpoint
export const destSchema = schema.object({
index: schema.string(),
pipeline: schema.maybe(schema.string()),
});
export const pivotSchema = schema.object({
group_by: schema.any(),
aggregations: schema.any(),
});
export const settingsSchema = schema.object({
max_page_search_size: schema.maybe(schema.number()),
// The default value is null, which disables throttling.
docs_per_second: schema.maybe(schema.nullable(schema.number())),
});
export const sourceSchema = schema.object({
index: schema.oneOf([schema.string(), schema.arrayOf(schema.string())]),
query: schema.maybe(schema.recordOf(schema.string(), schema.any())),
});
export const syncSchema = schema.object({
time: schema.object({
delay: schema.maybe(schema.string()),
field: schema.string(),
}),
});

// PUT transforms/{transformId}
export const putTransformsRequestSchema = schema.object({
description: schema.maybe(schema.string()),
dest: destSchema,
frequency: schema.maybe(schema.string()),
pivot: pivotSchema,
settings: schema.maybe(settingsSchema),
source: sourceSchema,
sync: schema.maybe(syncSchema),
});

export interface PutTransformsRequestSchema extends TypeOf<typeof putTransformsRequestSchema> {
pivot: {
group_by: PivotGroupByDict;
aggregations: PivotAggDict;
};
}

interface TransformCreated {
transform: TransformId;
}
interface TransformCreatedError {
id: TransformId;
error: any;
}
export interface PutTransformsResponseSchema {
transformsCreated: TransformCreated[];
errors: TransformCreatedError[];
}

// POST transforms/_preview
export const postTransformsPreviewRequestSchema = schema.object({
pivot: pivotSchema,
source: sourceSchema,
});

export interface PostTransformsPreviewRequestSchema
extends TypeOf<typeof postTransformsPreviewRequestSchema> {
pivot: {
group_by: PivotGroupByDict;
aggregations: PivotAggDict;
};
}

interface EsMappingType {
type: ES_FIELD_TYPES;
}

export type PreviewItem = Dictionary<any>;
export type PreviewData = PreviewItem[];
export type PreviewMappingsProperties = Dictionary<EsMappingType>;

export interface PostTransformsPreviewResponseSchema {
generated_dest_index: {
mappings: {
_meta: {
_transform: {
transform: string;
version: { create: string };
creation_date_in_millis: number;
};
created_by: string;
};
properties: PreviewMappingsProperties;
};
settings: { index: { number_of_shards: string; auto_expand_replicas: string } };
aliases: Record<string, any>;
};
preview: PreviewData;
}
21 changes: 21 additions & 0 deletions x-pack/plugins/transform/common/api_schemas/transforms_stats.ts
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 { TypeOf } from '@kbn/config-schema';

import { TransformStats } from '../types/transform_stats';

import { getTransformsRequestSchema } from './transforms';

export const getTransformsStatsRequestSchema = getTransformsRequestSchema;

export type GetTransformsRequestSchema = TypeOf<typeof getTransformsStatsRequestSchema>;

export interface GetTransformsStatsResponseSchema {
node_failures?: object;
count: number;
transforms: TransformStats[];
}
Loading