From 05919333c3d71de030ebd3a3d7901a096e7ec4f1 Mon Sep 17 00:00:00 2001 From: Jackie Han Date: Sat, 1 Jun 2024 17:36:59 -0700 Subject: [PATCH 1/4] add custom result index lifecycle management conditions Signed-off-by: Jackie Han --- .../CustomResultIndex/CustomResultIndex.tsx | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/public/pages/DefineDetector/components/CustomResultIndex/CustomResultIndex.tsx b/public/pages/DefineDetector/components/CustomResultIndex/CustomResultIndex.tsx index 5b2afb73..972018a1 100644 --- a/public/pages/DefineDetector/components/CustomResultIndex/CustomResultIndex.tsx +++ b/public/pages/DefineDetector/components/CustomResultIndex/CustomResultIndex.tsx @@ -21,6 +21,7 @@ import { EuiFormRow, EuiCheckbox, EuiIcon, + EuiFieldNumber, } from '@elastic/eui'; import { Field, FieldProps } from 'formik'; import React, { useState } from 'react'; @@ -31,7 +32,9 @@ import { isInvalid, getError, validateCustomResultIndex, + validatePositiveInteger, } from '../../../../utils/utils'; +import { FormattedFormRow } from '../../../../components/FormattedFormRow/FormattedFormRow'; interface CustomResultIndexProps { isEdit: boolean; @@ -112,6 +115,114 @@ function CustomResultIndex(props: CustomResultIndexProps) { ) : null} + + {enabled ? ( + + {({ field, form }: FieldProps) => ( + + + + + + + + +

days

+
+
+
+
+
+ )} +
+ ) : null} + + {enabled ? ( + + {({ field, form }: FieldProps) => ( + + + + + + + + +

MB

+
+
+
+
+
+ )} +
+ ) : null} + + {enabled ? ( + + {({ field, form }: FieldProps) => ( + + + + + + + + +

days

+
+
+
+
+
+ )} +
+ ) : null} )} From 23b7a06fd3727fa6e7a34a8e43f6cb479c2b2de5 Mon Sep 17 00:00:00 2001 From: Jackie Han Date: Wed, 5 Jun 2024 14:57:40 -0700 Subject: [PATCH 2/4] update create detector page and detector detail page to add custom result index lifecycle management settings Signed-off-by: Jackie Han --- public/models/interfaces.ts | 3 + .../CustomResultIndex/CustomResultIndex.tsx | 219 +++++++++--------- .../containers/DefineDetector.tsx | 3 + .../pages/DefineDetector/models/interfaces.ts | 3 + .../utils/__tests__/helpers.test.tsx | 8 + .../pages/DefineDetector/utils/constants.tsx | 3 + public/pages/DefineDetector/utils/helpers.ts | 6 + .../DetectorConfig.test.tsx.snap | 204 ++++++++++++++++ .../DetectorDefinitionFields.tsx | 18 ++ .../DetectorDefinitionFields.test.tsx.snap | 204 ++++++++++++++++ .../ReviewAndCreate.test.tsx.snap | 204 ++++++++++++++++ public/pages/ReviewAndCreate/utils/helpers.ts | 3 + public/redux/reducers/__tests__/utils.ts | 5 +- 13 files changed, 776 insertions(+), 107 deletions(-) diff --git a/public/models/interfaces.ts b/public/models/interfaces.ts index 3d836207..4fb6d75b 100644 --- a/public/models/interfaces.ts +++ b/public/models/interfaces.ts @@ -187,6 +187,9 @@ export type Detector = { timeField: string; indices: string[]; resultIndex?: string; + resultIndexMinAge?: number; + resultIndexMinSize?: number; + resultIndexTtl?: number; filterQuery: { [key: string]: any }; featureAttributes: FeatureAttributes[]; windowDelay: { period: Schedule }; diff --git a/public/pages/DefineDetector/components/CustomResultIndex/CustomResultIndex.tsx b/public/pages/DefineDetector/components/CustomResultIndex/CustomResultIndex.tsx index 972018a1..993bf901 100644 --- a/public/pages/DefineDetector/components/CustomResultIndex/CustomResultIndex.tsx +++ b/public/pages/DefineDetector/components/CustomResultIndex/CustomResultIndex.tsx @@ -89,7 +89,7 @@ function CustomResultIndex(props: CustomResultIndexProps) { ) : null} + + )} + - {enabled ? ( - - {({ field, form }: FieldProps) => ( - - - - - - - - -

days

-
-
-
-
-
- )} -
- ) : null} + {enabled ? ( + {({ field, form }: FieldProps) => ( + + + + + + + + + +

days

+
+
+
+
+
+
+ )} +
) : null} - {enabled ? ( - - {({ field, form }: FieldProps) => ( - - - - - - - - -

MB

-
-
-
-
+ {enabled ? ( + {({ field, form }: FieldProps) => ( + + + + + + + + + +

MB

+
- )} -
- ) : null} + + +
+ + )} +
) : null} - {enabled ? ( - - {({ field, form }: FieldProps) => ( - - - - - - - - -

days

-
-
-
-
-
- )} -
- ) : null} + {enabled ? ( + {({ field, form }: FieldProps) => ( + + + + + + + + + +

days

+
+
+
+
+
)} -
+ ) : null} ); } diff --git a/public/pages/DefineDetector/containers/DefineDetector.tsx b/public/pages/DefineDetector/containers/DefineDetector.tsx index 66a357fd..8c57a383 100644 --- a/public/pages/DefineDetector/containers/DefineDetector.tsx +++ b/public/pages/DefineDetector/containers/DefineDetector.tsx @@ -225,6 +225,9 @@ export const DefineDetector = (props: DefineDetectorProps) => { formikProps.setFieldTouched('timeField'); formikProps.setFieldTouched('interval'); formikProps.setFieldTouched('windowDelay'); + formikProps.setFieldTouched('resultIndexMinAge'); + formikProps.setFieldTouched('resultIndexMinSize'); + formikProps.setFieldTouched('resultIndexTtl'); formikProps.validateForm().then((errors) => { if (isEmpty(errors)) { if (props.isEdit) { diff --git a/public/pages/DefineDetector/models/interfaces.ts b/public/pages/DefineDetector/models/interfaces.ts index 87748494..d8b7f8e3 100644 --- a/public/pages/DefineDetector/models/interfaces.ts +++ b/public/pages/DefineDetector/models/interfaces.ts @@ -22,4 +22,7 @@ export interface DetectorDefinitionFormikValues { timeField: string; interval: number; windowDelay: number; + resultIndexMinAge?: number; + resultIndexMinSize?: number; + resultIndexTtl?:number; } diff --git a/public/pages/DefineDetector/utils/__tests__/helpers.test.tsx b/public/pages/DefineDetector/utils/__tests__/helpers.test.tsx index fe6c3943..c461f2cc 100644 --- a/public/pages/DefineDetector/utils/__tests__/helpers.test.tsx +++ b/public/pages/DefineDetector/utils/__tests__/helpers.test.tsx @@ -40,6 +40,10 @@ describe('detectorDefinitionToFormik', () => { timeField: randomDetector.timeField, interval: randomDetector.detectionInterval.period.interval, windowDelay: randomDetector.windowDelay.period.interval, + resultIndex: randomDetector.resultIndex, + resultIndexMinAge: randomDetector.resultIndexMinAge, + resultIndexMinSize: randomDetector.resultIndexMinSize, + resultIndexTtl: randomDetector.resultIndexTtl, }); }); test('should return if detector does not have metadata', () => { @@ -56,6 +60,10 @@ describe('detectorDefinitionToFormik', () => { timeField: randomDetector.timeField, interval: randomDetector.detectionInterval.period.interval, windowDelay: randomDetector.windowDelay.period.interval, + resultIndex: randomDetector.resultIndex, + resultIndexMinAge: randomDetector.resultIndexMinAge, + resultIndexMinSize: randomDetector.resultIndexMinSize, + resultIndexTtl: randomDetector.resultIndexTtl, }); }); test("upgrade old detector's filters to include filter type", () => { diff --git a/public/pages/DefineDetector/utils/constants.tsx b/public/pages/DefineDetector/utils/constants.tsx index 3a9cc06c..17ce70a9 100644 --- a/public/pages/DefineDetector/utils/constants.tsx +++ b/public/pages/DefineDetector/utils/constants.tsx @@ -44,4 +44,7 @@ export const INITIAL_DETECTOR_DEFINITION_VALUES: DetectorDefinitionFormikValues interval: 10, windowDelay: 1, resultIndex: undefined, + resultIndexMinAge: 7, + resultIndexMinSize: 51200, + resultIndexTtl: 60, }; diff --git a/public/pages/DefineDetector/utils/helpers.ts b/public/pages/DefineDetector/utils/helpers.ts index f9e9ae45..777c7441 100644 --- a/public/pages/DefineDetector/utils/helpers.ts +++ b/public/pages/DefineDetector/utils/helpers.ts @@ -45,6 +45,9 @@ export function detectorDefinitionToFormik( timeField: ad.timeField, interval: get(ad, 'detectionInterval.period.interval', 10), windowDelay: get(ad, 'windowDelay.period.interval', 0), + resultIndexMinAge: get(ad, 'resultIndexMinAge', 7), + resultIndexMinSize:get(ad, 'resultIndexMinSize', 51200), + resultIndexTtl: get(ad, 'resultIndexTtl', 60), }; } @@ -119,6 +122,9 @@ export function formikToDetectorDefinition( windowDelay: { period: { interval: values.windowDelay, unit: UNITS.MINUTES }, }, + resultIndexMinAge: values.resultIndexMinAge, + resultIndexMinSize: values.resultIndexMinSize, + resultIndexTtl: values.resultIndexTtl, } as Detector; return detectorBody; diff --git a/public/pages/DetectorConfig/containers/__tests__/__snapshots__/DetectorConfig.test.tsx.snap b/public/pages/DetectorConfig/containers/__tests__/__snapshots__/DetectorConfig.test.tsx.snap index 6580e900..a728093c 100644 --- a/public/pages/DetectorConfig/containers/__tests__/__snapshots__/DetectorConfig.test.tsx.snap +++ b/public/pages/DetectorConfig/containers/__tests__/__snapshots__/DetectorConfig.test.tsx.snap @@ -430,6 +430,108 @@ exports[` spec renders the component 1`] = ` +
+
+
+ +
+
+
+

+ 7 +

+
+
+
+
+
+
+
+ +
+
+
+

+ 51200 +

+
+
+
+
+
+
+
+ +
+
+
+

+ 60 +

+
+
+
+
@@ -1604,6 +1706,108 @@ exports[` spec renders the component with 2 custom and 1 simpl +
+
+
+ +
+
+
+

+ 7 +

+
+
+
+
+
+
+
+ +
+
+
+

+ 51200 +

+
+
+
+
+
+
+
+ +
+
+
+

+ 60 +

+
+
+
+
diff --git a/public/pages/ReviewAndCreate/components/DetectorDefinitionFields/DetectorDefinitionFields.tsx b/public/pages/ReviewAndCreate/components/DetectorDefinitionFields/DetectorDefinitionFields.tsx index 710b6c51..096c41a6 100644 --- a/public/pages/ReviewAndCreate/components/DetectorDefinitionFields/DetectorDefinitionFields.tsx +++ b/public/pages/ReviewAndCreate/components/DetectorDefinitionFields/DetectorDefinitionFields.tsx @@ -217,6 +217,24 @@ export const DetectorDefinitionFields = ( description={get(props, 'detector.resultIndex', '-')} /> + + + + + + + + + ); diff --git a/public/pages/ReviewAndCreate/components/__tests__/__snapshots__/DetectorDefinitionFields.test.tsx.snap b/public/pages/ReviewAndCreate/components/__tests__/__snapshots__/DetectorDefinitionFields.test.tsx.snap index 1dd16f3f..4552d3f7 100644 --- a/public/pages/ReviewAndCreate/components/__tests__/__snapshots__/DetectorDefinitionFields.test.tsx.snap +++ b/public/pages/ReviewAndCreate/components/__tests__/__snapshots__/DetectorDefinitionFields.test.tsx.snap @@ -342,6 +342,108 @@ exports[` spec renders the component in create mode (no ID +
+
+
+ +
+
+
+

+ - +

+
+
+
+
+
+
+
+ +
+
+
+

+ - +

+
+
+
+
+
+
+
+ +
+
+
+

+ - +

+
+
+
+
@@ -760,6 +862,108 @@ exports[` spec renders the component in edit mode (with ID +
+
+
+ +
+
+
+

+ - +

+
+
+
+
+
+
+
+ +
+
+
+

+ - +

+
+
+
+
+
+
+
+ +
+
+
+

+ - +

+
+
+
+
diff --git a/public/pages/ReviewAndCreate/containers/__tests__/__snapshots__/ReviewAndCreate.test.tsx.snap b/public/pages/ReviewAndCreate/containers/__tests__/__snapshots__/ReviewAndCreate.test.tsx.snap index 7f09ec44..b723fc9b 100644 --- a/public/pages/ReviewAndCreate/containers/__tests__/__snapshots__/ReviewAndCreate.test.tsx.snap +++ b/public/pages/ReviewAndCreate/containers/__tests__/__snapshots__/ReviewAndCreate.test.tsx.snap @@ -396,6 +396,108 @@ exports[` spec renders the component, validation loading 1`] +
+
+
+ +
+
+
+

+ - +

+
+
+
+
+
+
+
+ +
+
+
+

+ - +

+
+
+
+
+
+
+
+ +
+
+
+

+ - +

+
+
+
+
@@ -1388,6 +1490,108 @@ exports[`issue in detector validation issues in feature query 1`] = ` +
+
+
+ +
+
+
+

+ - +

+
+
+
+
+
+
+
+ +
+
+
+

+ - +

+
+
+
+
+
+
+
+ +
+
+
+

+ - +

+
+
+
+
diff --git a/public/pages/ReviewAndCreate/utils/helpers.ts b/public/pages/ReviewAndCreate/utils/helpers.ts index c21040ed..eb0671d6 100644 --- a/public/pages/ReviewAndCreate/utils/helpers.ts +++ b/public/pages/ReviewAndCreate/utils/helpers.ts @@ -59,6 +59,9 @@ export function formikToDetector(values: CreateDetectorFormikValues): Detector { categoryField: !isEmpty(values?.categoryField) ? values.categoryField : undefined, + resultIndexMinAge: resultIndex && resultIndex.trim().length > 0 ? values.resultIndexMinAge : undefined, + resultIndexMinSize: resultIndex && resultIndex.trim().length > 0 ? values.resultIndexMinSize : undefined, + resultIndexTtl: resultIndex && resultIndex.trim().length > 0 ? values.resultIndexTtl : undefined, } as Detector; // Optionally add detection date range diff --git a/public/redux/reducers/__tests__/utils.ts b/public/redux/reducers/__tests__/utils.ts index 797d5036..1b5502cf 100644 --- a/public/redux/reducers/__tests__/utils.ts +++ b/public/redux/reducers/__tests__/utils.ts @@ -119,7 +119,10 @@ export const getRandomDetector = ( curState: DETECTOR_STATE.INIT, stateError: '', shingleSize: DEFAULT_SHINGLE_SIZE, - resultIndex: isEmpty(customResultIndex) ? undefined : customResultIndex + resultIndex: isEmpty(customResultIndex) ? undefined : customResultIndex, + resultIndexMinAge: 7, + resultIndexMinSize: 51200, + resultIndexTtl: 60, }; }; From 9807a80ab6554dd2f7bf874b05035d3be84e2857 Mon Sep 17 00:00:00 2001 From: Jackie Han Date: Wed, 5 Jun 2024 15:00:36 -0700 Subject: [PATCH 3/4] code formatting update Signed-off-by: Jackie Han --- .../components/CustomResultIndex/CustomResultIndex.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/pages/DefineDetector/components/CustomResultIndex/CustomResultIndex.tsx b/public/pages/DefineDetector/components/CustomResultIndex/CustomResultIndex.tsx index 993bf901..b34a657b 100644 --- a/public/pages/DefineDetector/components/CustomResultIndex/CustomResultIndex.tsx +++ b/public/pages/DefineDetector/components/CustomResultIndex/CustomResultIndex.tsx @@ -115,7 +115,7 @@ function CustomResultIndex(props: CustomResultIndexProps) { ) : null} - + )} From 2eaa7abaf2b60410a20bbcf1fc8c2d0525360a95 Mon Sep 17 00:00:00 2001 From: Jackie Han Date: Wed, 5 Jun 2024 16:34:18 -0700 Subject: [PATCH 4/4] add more tests Signed-off-by: Jackie Han --- .../CustomResultIndex/CustomResultIndex.tsx | 2 +- .../__snapshots__/DetectorConfig.test.tsx.snap | 12 ++++++------ .../DetectorDefinitionFields.tsx | 6 +++--- .../__tests__/DetectorDefinitionFields.test.tsx | 8 ++++++++ .../DetectorDefinitionFields.test.tsx.snap | 16 ++++++++-------- .../__snapshots__/ReviewAndCreate.test.tsx.snap | 12 ++++++------ 6 files changed, 32 insertions(+), 24 deletions(-) diff --git a/public/pages/DefineDetector/components/CustomResultIndex/CustomResultIndex.tsx b/public/pages/DefineDetector/components/CustomResultIndex/CustomResultIndex.tsx index b34a657b..55e53297 100644 --- a/public/pages/DefineDetector/components/CustomResultIndex/CustomResultIndex.tsx +++ b/public/pages/DefineDetector/components/CustomResultIndex/CustomResultIndex.tsx @@ -180,7 +180,7 @@ function CustomResultIndex(props: CustomResultIndexProps) { id="resultIndexMinSize" placeholder="Max index size" data-test-subj="resultIndexMinSize" - min={1} + min={1000} {...field} /> diff --git a/public/pages/DetectorConfig/containers/__tests__/__snapshots__/DetectorConfig.test.tsx.snap b/public/pages/DetectorConfig/containers/__tests__/__snapshots__/DetectorConfig.test.tsx.snap index a728093c..98e4475c 100644 --- a/public/pages/DetectorConfig/containers/__tests__/__snapshots__/DetectorConfig.test.tsx.snap +++ b/public/pages/DetectorConfig/containers/__tests__/__snapshots__/DetectorConfig.test.tsx.snap @@ -458,7 +458,7 @@ exports[` spec renders the component 1`] = `

- 7 + 7 Days

@@ -492,7 +492,7 @@ exports[` spec renders the component 1`] = `

- 51200 + 51200 MB

@@ -526,7 +526,7 @@ exports[` spec renders the component 1`] = `

- 60 + 60 Days

@@ -1734,7 +1734,7 @@ exports[` spec renders the component with 2 custom and 1 simpl

- 7 + 7 Days

@@ -1768,7 +1768,7 @@ exports[` spec renders the component with 2 custom and 1 simpl

- 51200 + 51200 MB

@@ -1802,7 +1802,7 @@ exports[` spec renders the component with 2 custom and 1 simpl

- 60 + 60 Days

diff --git a/public/pages/ReviewAndCreate/components/DetectorDefinitionFields/DetectorDefinitionFields.tsx b/public/pages/ReviewAndCreate/components/DetectorDefinitionFields/DetectorDefinitionFields.tsx index 096c41a6..ccdc50e5 100644 --- a/public/pages/ReviewAndCreate/components/DetectorDefinitionFields/DetectorDefinitionFields.tsx +++ b/public/pages/ReviewAndCreate/components/DetectorDefinitionFields/DetectorDefinitionFields.tsx @@ -220,19 +220,19 @@ export const DetectorDefinitionFields = ( diff --git a/public/pages/ReviewAndCreate/components/__tests__/DetectorDefinitionFields.test.tsx b/public/pages/ReviewAndCreate/components/__tests__/DetectorDefinitionFields.test.tsx index 04573140..b19d03a6 100644 --- a/public/pages/ReviewAndCreate/components/__tests__/DetectorDefinitionFields.test.tsx +++ b/public/pages/ReviewAndCreate/components/__tests__/DetectorDefinitionFields.test.tsx @@ -54,6 +54,10 @@ const testDetector = { }, ], }, + resultIndex: 'opensearch-ad-plugin-result-test', + resultIndexMinAge: 7, + resultIndexMinSize: 51200, + resultIndexTtl: 60, } as Detector; describe(' spec', () => { @@ -80,6 +84,10 @@ describe(' spec', () => { getByText('test-description'); getByText('test-timefield'); getByText('1 Minutes'); + getByText('opensearch-ad-plugin-result-test'); + getByText('7 Days'); + getByText('51200 MB'); + getByText('60 Days'); expect(queryByText('test-id')).toBeNull(); }); test('renders the component in edit mode (with ID)', () => { diff --git a/public/pages/ReviewAndCreate/components/__tests__/__snapshots__/DetectorDefinitionFields.test.tsx.snap b/public/pages/ReviewAndCreate/components/__tests__/__snapshots__/DetectorDefinitionFields.test.tsx.snap index 4552d3f7..5597ffb1 100644 --- a/public/pages/ReviewAndCreate/components/__tests__/__snapshots__/DetectorDefinitionFields.test.tsx.snap +++ b/public/pages/ReviewAndCreate/components/__tests__/__snapshots__/DetectorDefinitionFields.test.tsx.snap @@ -336,7 +336,7 @@ exports[` spec renders the component in create mode (no ID

- - + opensearch-ad-plugin-result-test

@@ -370,7 +370,7 @@ exports[` spec renders the component in create mode (no ID

- - + 7 Days

@@ -404,7 +404,7 @@ exports[` spec renders the component in create mode (no ID

- - + 51200 MB

@@ -438,7 +438,7 @@ exports[` spec renders the component in create mode (no ID

- - + 60 Days

@@ -856,7 +856,7 @@ exports[` spec renders the component in edit mode (with ID

- - + opensearch-ad-plugin-result-test

@@ -890,7 +890,7 @@ exports[` spec renders the component in edit mode (with ID

- - + 7 Days

@@ -924,7 +924,7 @@ exports[` spec renders the component in edit mode (with ID

- - + 51200 MB

@@ -958,7 +958,7 @@ exports[` spec renders the component in edit mode (with ID

- - + 60 Days

diff --git a/public/pages/ReviewAndCreate/containers/__tests__/__snapshots__/ReviewAndCreate.test.tsx.snap b/public/pages/ReviewAndCreate/containers/__tests__/__snapshots__/ReviewAndCreate.test.tsx.snap index b723fc9b..f257fde9 100644 --- a/public/pages/ReviewAndCreate/containers/__tests__/__snapshots__/ReviewAndCreate.test.tsx.snap +++ b/public/pages/ReviewAndCreate/containers/__tests__/__snapshots__/ReviewAndCreate.test.tsx.snap @@ -424,7 +424,7 @@ exports[` spec renders the component, validation loading 1`]

- - + - Days

@@ -458,7 +458,7 @@ exports[` spec renders the component, validation loading 1`]

- - + - MB

@@ -492,7 +492,7 @@ exports[` spec renders the component, validation loading 1`]

- - + - Days

@@ -1518,7 +1518,7 @@ exports[`issue in detector validation issues in feature query 1`] = `

- - + - Days

@@ -1552,7 +1552,7 @@ exports[`issue in detector validation issues in feature query 1`] = `

- - + - MB

@@ -1586,7 +1586,7 @@ exports[`issue in detector validation issues in feature query 1`] = `

- - + - Days