-
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.
[ML] Move shared transform to common location.
- Loading branch information
Showing
26 changed files
with
209 additions
and
151 deletions.
There are no files selected for viewing
File renamed without changes.
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
23 changes: 23 additions & 0 deletions
23
x-pack/legacy/plugins/ml/public/data_frame/common/transform_list.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,23 @@ | ||
/* | ||
* 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 { DataFrameTransformId, DataFrameTransformPivotConfig } from './transform'; | ||
import { DataFrameTransformStats } from './transform_stats'; | ||
|
||
// Used to pass on attribute names to table columns | ||
export enum DataFrameTransformListColumn { | ||
configDestIndex = 'config.dest.index', | ||
configSourceIndex = 'config.source.index', | ||
description = 'config.description', | ||
id = 'id', | ||
} | ||
|
||
export interface DataFrameTransformListRow { | ||
id: DataFrameTransformId; | ||
config: DataFrameTransformPivotConfig; | ||
mode?: string; // added property on client side to allow filtering by this field | ||
stats: DataFrameTransformStats; | ||
} |
27 changes: 27 additions & 0 deletions
27
x-pack/legacy/plugins/ml/public/data_frame/common/transform_stats.test.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,27 @@ | ||
/* | ||
* 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 mockDataFrameTransformListRow from './__mocks__/data_frame_transform_list_row.json'; | ||
|
||
import { DataFrameTransformListRow } from './transform_list'; | ||
import { isCompletedBatchTransform, DATA_FRAME_TRANSFORM_STATE } from './transform_stats'; | ||
|
||
describe('Data Frame: isCompletedBatchTransform()', () => { | ||
test('isCompletedBatchTransform()', () => { | ||
// check the transform config/state against the conditions | ||
// that will be used by isCompletedBatchTransform() | ||
// followed by a call to isCompletedBatchTransform() itself | ||
const row = mockDataFrameTransformListRow as DataFrameTransformListRow; | ||
expect(row.stats.checkpointing.last.checkpoint === 1).toBe(true); | ||
expect(row.config.sync === undefined).toBe(true); | ||
expect(row.stats.state === DATA_FRAME_TRANSFORM_STATE.STOPPED).toBe(true); | ||
expect(isCompletedBatchTransform(mockDataFrameTransformListRow)).toBe(true); | ||
|
||
// adapt the mock config to resemble a non-completed transform. | ||
row.stats.checkpointing.last.checkpoint = 0; | ||
expect(isCompletedBatchTransform(mockDataFrameTransformListRow)).toBe(false); | ||
}); | ||
}); |
94 changes: 94 additions & 0 deletions
94
x-pack/legacy/plugins/ml/public/data_frame/common/transform_stats.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,94 @@ | ||
/* | ||
* 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 { idx } from '@kbn/elastic-idx'; | ||
|
||
import { DataFrameTransformId } from './transform'; | ||
import { DataFrameTransformListRow } from './transform_list'; | ||
|
||
// reflects https://github.com/elastic/elasticsearch/blob/master/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/transforms/DataFrameTransformStats.java#L243 | ||
export enum DATA_FRAME_TRANSFORM_STATE { | ||
ABORTING = 'aborting', | ||
FAILED = 'failed', | ||
INDEXING = 'indexing', | ||
STARTED = 'started', | ||
STOPPED = 'stopped', | ||
STOPPING = 'stopping', | ||
} | ||
|
||
export enum DATA_FRAME_MODE { | ||
BATCH = 'batch', | ||
CONTINUOUS = 'continuous', | ||
} | ||
|
||
export interface DataFrameTransformStats { | ||
id: DataFrameTransformId; | ||
checkpointing: { | ||
last: { | ||
checkpoint: number; | ||
timestamp_millis?: number; | ||
}; | ||
next?: { | ||
checkpoint: number; | ||
checkpoint_progress?: { | ||
total_docs: number; | ||
docs_remaining: number; | ||
percent_complete: number; | ||
}; | ||
}; | ||
operations_behind: number; | ||
}; | ||
node?: { | ||
id: string; | ||
name: string; | ||
ephemeral_id: string; | ||
transport_address: string; | ||
attributes: Record<string, any>; | ||
}; | ||
stats: { | ||
documents_indexed: number; | ||
documents_processed: number; | ||
index_failures: number; | ||
index_time_in_ms: number; | ||
index_total: number; | ||
pages_processed: number; | ||
search_failures: number; | ||
search_time_in_ms: number; | ||
search_total: number; | ||
trigger_count: number; | ||
}; | ||
reason?: string; | ||
state: DATA_FRAME_TRANSFORM_STATE; | ||
} | ||
|
||
export function isDataFrameTransformStats(arg: any): arg is DataFrameTransformStats { | ||
return ( | ||
typeof arg === 'object' && | ||
arg !== null && | ||
{}.hasOwnProperty.call(arg, 'state') && | ||
Object.values(DATA_FRAME_TRANSFORM_STATE).includes(arg.state) | ||
); | ||
} | ||
|
||
export function getTransformProgress(item: DataFrameTransformListRow) { | ||
if (isCompletedBatchTransform(item)) { | ||
return 100; | ||
} | ||
|
||
const progress = idx(item, _ => _.stats.checkpointing.next.checkpoint_progress.percent_complete); | ||
|
||
return progress !== undefined ? Math.round(progress) : undefined; | ||
} | ||
|
||
export function isCompletedBatchTransform(item: DataFrameTransformListRow) { | ||
// If `checkpoint=1`, `sync` is missing from the config and state is stopped, | ||
// then this is a completed batch data frame transform. | ||
return ( | ||
item.stats.checkpointing.last.checkpoint === 1 && | ||
item.config.sync === undefined && | ||
item.stats.state === DATA_FRAME_TRANSFORM_STATE.STOPPED | ||
); | ||
} |
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 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 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 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 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 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 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 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 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
Oops, something went wrong.