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

[Backport 2.x] update create detector page and detector detail page to add custom result index lifecycle management settings #771

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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;
}
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
Loading