Skip to content

Commit

Permalink
update create detector page and detector detail page to add custom re…
Browse files Browse the repository at this point in the history
…sult index lifecycle management settings (#770)

* add custom result index lifecycle management conditions

Signed-off-by: Jackie Han <[email protected]>

* update create detector page and detector detail page to add custom result index lifecycle management settings

Signed-off-by: Jackie Han <[email protected]>

* code formatting update

Signed-off-by: Jackie Han <[email protected]>

* add more tests

Signed-off-by: Jackie Han <[email protected]>

---------

Signed-off-by: Jackie Han <[email protected]>
  • Loading branch information
jackiehanyang authored Jun 5, 2024
1 parent 1eebf24 commit 1080d60
Show file tree
Hide file tree
Showing 14 changed files with 792 additions and 4 deletions.
3 changes: 3 additions & 0 deletions public/models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
EuiFormRow,
EuiCheckbox,
EuiIcon,
EuiFieldNumber,
} from '@elastic/eui';
import { Field, FieldProps } from 'formik';
import React, { useState } from 'react';
Expand All @@ -31,7 +32,9 @@ import {
isInvalid,
getError,
validateCustomResultIndex,
validatePositiveInteger,
} from '../../../../utils/utils';
import { FormattedFormRow } from '../../../../components/FormattedFormRow/FormattedFormRow';

interface CustomResultIndexProps {
isEdit: boolean;
Expand Down Expand Up @@ -86,7 +89,7 @@ function CustomResultIndex(props: CustomResultIndexProps) {
<EuiFlexItem>
<EuiCallOut
data-test-subj="cannotEditResultIndexCallout"
title="You can't change the custom result index after you create the detector. You can manage the result index with the Index Management plugin."
title="You can't change the custom result index after creating the detector. You can manage the result index using the following three settings inside Anomaly Detection plugin or with the Index Management plugin."
color="warning"
iconType="alert"
size="s"
Expand Down Expand Up @@ -115,6 +118,121 @@ function CustomResultIndex(props: CustomResultIndexProps) {
</EuiFlexGroup>
)}
</Field>

{enabled ? (<Field
name="resultIndexMinAge"
validate={enabled ? validatePositiveInteger : null}
>
{({ field, form }: FieldProps) => (
<EuiFlexGroup>
<EuiFlexItem style={{ maxWidth: '70%' }}>
<FormattedFormRow
fullWidth
title="Max Index Age"
hint={[
`This setting would define a specific threshold for the age of an index. When this threshold is surpassed, a rollover will be triggered automatically.`,
]}
isInvalid={isInvalid(field.name, form)}
error={getError(field.name, form)}
>
<EuiFlexGroup gutterSize="s" alignItems="center">
<EuiFlexItem grow={false}>
<EuiFieldNumber
name="resultIndexMinAge"
id="resultIndexMinAge"
data-test-subj="resultIndexMinAge"
min={1}
{...field}
/>
</EuiFlexItem>
<EuiFlexItem>
<EuiText>
<p className="minutes">days</p>
</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
</FormattedFormRow>
</EuiFlexItem>
</EuiFlexGroup>
)}
</Field>) : null}

{enabled ? (<Field
name="resultIndexMinSize"
validate={enabled ? validatePositiveInteger : null}
>
{({ field, form }: FieldProps) => (
<EuiFlexGroup>
<EuiFlexItem style={{ maxWidth: '70%' }}>
<FormattedFormRow
fullWidth
title="Max Index Size"
hint={[
`This setting would define a specific threshold for the size of an index. When this threshold is surpassed, a rollover will be triggered automatically.`,
]}
isInvalid={isInvalid(field.name, form)}
error={getError(field.name, form)}
>
<EuiFlexGroup gutterSize="s" alignItems="center">
<EuiFlexItem grow={false}>
<EuiFieldNumber
name="resultIndexMinSize"
id="resultIndexMinSize"
placeholder="Max index size"
data-test-subj="resultIndexMinSize"
min={1000}
{...field}
/>
</EuiFlexItem>
<EuiFlexItem>
<EuiText>
<p className="minutes">MB</p>
</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
</FormattedFormRow>
</EuiFlexItem>
</EuiFlexGroup>
)}
</Field>) : null}

{enabled ? (<Field
name="resultIndexTtl"
validate={enabled ? validatePositiveInteger : null}
>
{({ field, form }: FieldProps) => (
<EuiFlexGroup>
<EuiFlexItem style={{ maxWidth: '70%' }}>
<FormattedFormRow
fullWidth
title="Index TTL"
hint={[
`This setting would define the duration after which an index is considered expired and eligible for deletion.`,
]}
isInvalid={isInvalid(field.name, form)}
error={getError(field.name, form)}
>
<EuiFlexGroup gutterSize="s" alignItems="center">
<EuiFlexItem grow={false}>
<EuiFieldNumber
name="resultIndexTtl"
id="resultIndexTtl"
data-test-subj="resultIndexTtl"
min={1}
{...field}
/>
</EuiFlexItem>
<EuiFlexItem>
<EuiText>
<p className="minutes">days</p>
</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
</FormattedFormRow>
</EuiFlexItem>
</EuiFlexGroup>
)}
</Field>) : null}
</ContentPanel>
);
}
Expand Down
3 changes: 3 additions & 0 deletions public/pages/DefineDetector/containers/DefineDetector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions public/pages/DefineDetector/models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ export interface DetectorDefinitionFormikValues {
timeField: string;
interval: number;
windowDelay: number;
resultIndexMinAge?: number;
resultIndexMinSize?: number;
resultIndexTtl?:number;
}
8 changes: 8 additions & 0 deletions public/pages/DefineDetector/utils/__tests__/helpers.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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", () => {
Expand Down
3 changes: 3 additions & 0 deletions public/pages/DefineDetector/utils/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@ export const INITIAL_DETECTOR_DEFINITION_VALUES: DetectorDefinitionFormikValues
interval: 10,
windowDelay: 1,
resultIndex: undefined,
resultIndexMinAge: 7,
resultIndexMinSize: 51200,
resultIndexTtl: 60,
};
6 changes: 6 additions & 0 deletions public/pages/DefineDetector/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
}

Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 1080d60

Please sign in to comment.