Skip to content

Commit dd18220

Browse files
authored
[ML] Transforms: API schemas and integration tests (#75164)
- Adds schema definitions to transform API endpoints and adds API integration tests. - The type definitions based on the schema definitions can be used on the client side too. - Adds apidoc documentation.
1 parent cbcd1eb commit dd18220

File tree

127 files changed

+3098
-1362
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+3098
-1362
lines changed

x-pack/plugins/ml/common/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
export { SearchResponse7 } from './types/es_client';
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { SearchResponse, ShardsResponse } from 'elasticsearch';
8+
9+
// The types specified in `@types/elasticsearch` are out of date and still have `total: number`.
10+
interface SearchResponse7Hits<T> {
11+
hits: SearchResponse<T>['hits']['hits'];
12+
max_score: number;
13+
total: {
14+
value: number;
15+
relation: string;
16+
};
17+
}
18+
export interface SearchResponse7<T = any> {
19+
took: number;
20+
timed_out: boolean;
21+
_scroll_id?: string;
22+
_shards: ShardsResponse;
23+
hits: SearchResponse7Hits<T>;
24+
aggregations?: any;
25+
}

x-pack/plugins/ml/public/application/components/data_grid/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export {
1919
DataGridItem,
2020
EsSorting,
2121
RenderCellValue,
22-
SearchResponse7,
2322
UseDataGridReturnType,
2423
UseIndexDataReturnType,
2524
} from './types';

x-pack/plugins/ml/public/application/components/data_grid/types.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

77
import { Dispatch, SetStateAction } from 'react';
8-
import { SearchResponse } from 'elasticsearch';
98

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

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

46-
// The types specified in `@types/elasticsearch` are out of date and still have `total: number`.
47-
export interface SearchResponse7 extends SearchResponse<any> {
48-
hits: SearchResponse<any>['hits'] & {
49-
total: {
50-
value: number;
51-
relation: string;
52-
};
53-
};
54-
}
55-
5645
export interface UseIndexDataReturnType
5746
extends Pick<
5847
UseDataGridReturnType,

x-pack/plugins/ml/public/application/data_frame_analytics/common/get_index_data.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7+
import type { SearchResponse7 } from '../../../../common/types/es_client';
78
import { extractErrorMessage } from '../../../../common/util/errors';
89

9-
import { EsSorting, SearchResponse7, UseDataGridReturnType } from '../../components/data_grid';
10+
import { EsSorting, UseDataGridReturnType } from '../../components/data_grid';
1011
import { ml } from '../../services/ml_api_service';
1112

1213
import { isKeywordAndTextType } from '../common/fields';

x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_creation/hooks/use_index_data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import {
2222
useDataGrid,
2323
useRenderCellValue,
2424
EsSorting,
25-
SearchResponse7,
2625
UseIndexDataReturnType,
2726
} from '../../../../components/data_grid';
27+
import type { SearchResponse7 } from '../../../../../../common/types/es_client';
2828
import { extractErrorMessage } from '../../../../../../common/util/errors';
2929
import { INDEX_STATUS } from '../../../common/analytics';
3030
import { ml } from '../../../../services/ml_api_service';
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { TransformMessage } from '../types/messages';
8+
9+
export type GetTransformsAuditMessagesResponseSchema = TransformMessage[];
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { schema, TypeOf } from '@kbn/config-schema';
8+
9+
import { TRANSFORM_STATE } from '../constants';
10+
11+
export const transformIdsSchema = schema.arrayOf(
12+
schema.object({
13+
id: schema.string(),
14+
})
15+
);
16+
17+
export type TransformIdsSchema = TypeOf<typeof transformIdsSchema>;
18+
19+
export const transformStateSchema = schema.oneOf([
20+
schema.literal(TRANSFORM_STATE.ABORTING),
21+
schema.literal(TRANSFORM_STATE.FAILED),
22+
schema.literal(TRANSFORM_STATE.INDEXING),
23+
schema.literal(TRANSFORM_STATE.STARTED),
24+
schema.literal(TRANSFORM_STATE.STOPPED),
25+
schema.literal(TRANSFORM_STATE.STOPPING),
26+
]);
27+
28+
export const indexPatternTitleSchema = schema.object({
29+
/** Title of the index pattern for which to return stats. */
30+
indexPatternTitle: schema.string(),
31+
});
32+
33+
export type IndexPatternTitleSchema = TypeOf<typeof indexPatternTitleSchema>;
34+
35+
export const transformIdParamSchema = schema.object({
36+
transformId: schema.string(),
37+
});
38+
39+
export type TransformIdParamSchema = TypeOf<typeof transformIdParamSchema>;
40+
41+
export interface ResponseStatus {
42+
success: boolean;
43+
error?: any;
44+
}
45+
46+
export interface CommonResponseStatusSchema {
47+
[key: string]: ResponseStatus;
48+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { schema, TypeOf } from '@kbn/config-schema';
8+
9+
import { transformStateSchema, ResponseStatus } from './common';
10+
11+
export const deleteTransformsRequestSchema = schema.object({
12+
/**
13+
* Delete Transform & Destination Index
14+
*/
15+
transformsInfo: schema.arrayOf(
16+
schema.object({
17+
id: schema.string(),
18+
state: transformStateSchema,
19+
})
20+
),
21+
deleteDestIndex: schema.maybe(schema.boolean()),
22+
deleteDestIndexPattern: schema.maybe(schema.boolean()),
23+
forceDelete: schema.maybe(schema.boolean()),
24+
});
25+
26+
export type DeleteTransformsRequestSchema = TypeOf<typeof deleteTransformsRequestSchema>;
27+
28+
export interface DeleteTransformStatus {
29+
transformDeleted: ResponseStatus;
30+
destIndexDeleted?: ResponseStatus;
31+
destIndexPatternDeleted?: ResponseStatus;
32+
destinationIndex?: string | undefined;
33+
}
34+
35+
export interface DeleteTransformsResponseSchema {
36+
[key: string]: DeleteTransformStatus;
37+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { schema, TypeOf } from '@kbn/config-schema';
8+
9+
export const fieldHistogramsRequestSchema = schema.object({
10+
/** Query to match documents in the index. */
11+
query: schema.any(),
12+
/** The fields to return histogram data. */
13+
fields: schema.arrayOf(schema.any()),
14+
/** Number of documents to be collected in the sample processed on each shard, or -1 for no sampling. */
15+
samplerShardSize: schema.number(),
16+
});
17+
18+
export type FieldHistogramsRequestSchema = TypeOf<typeof fieldHistogramsRequestSchema>;
19+
export type FieldHistogramsResponseSchema = any[];

0 commit comments

Comments
 (0)