mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[ResponseOps][Alerting] Elasticsearch query rule type allows SIZE: 0, but flags as error on re-edit (#142225)
* Fixing es query bug * Updating threshold * Adding isNil to another check
This commit is contained in:
parent
c7b742c567
commit
b542f7b520
4 changed files with 42 additions and 4 deletions
|
@ -158,6 +158,20 @@ describe('expression params validation', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('if size property is 0 should not return error message', () => {
|
||||
const initialParams: EsQueryAlertParams<SearchType.esQuery> = {
|
||||
index: ['test'],
|
||||
esQuery: `{\n \"query\":{\n \"match_all\" : {}\n }\n`,
|
||||
size: 0,
|
||||
timeWindowSize: 1,
|
||||
timeWindowUnit: 's',
|
||||
threshold: [0],
|
||||
timeField: '',
|
||||
excludeHitsFromPreviousRun: true,
|
||||
};
|
||||
expect(validateExpression(initialParams).errors.size.length).toBe(0);
|
||||
});
|
||||
|
||||
test('if size property is > 10000 should return proper error message', () => {
|
||||
const initialParams: EsQueryAlertParams<SearchType.esQuery> = {
|
||||
index: ['test'],
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { defaultsDeep } from 'lodash';
|
||||
import { defaultsDeep, isNil } from 'lodash';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { ValidationResult, builtInComparators } from '@kbn/triggers-actions-ui-plugin/public';
|
||||
import { EsQueryAlertParams, ExpressionErrors } from './types';
|
||||
|
@ -63,7 +63,7 @@ export const validateExpression = (ruleParams: EsQueryAlertParams): ValidationRe
|
|||
);
|
||||
}
|
||||
|
||||
if (!size) {
|
||||
if (isNil(size)) {
|
||||
errors.size.push(
|
||||
i18n.translate('xpack.stackAlerts.esQuery.ui.validation.error.requiredSizeText', {
|
||||
defaultMessage: 'Size is required.',
|
||||
|
|
|
@ -140,4 +140,27 @@ describe('threshold expression', () => {
|
|||
wrapper.update();
|
||||
expect(wrapper.find('input[data-test-subj="alertThresholdInput"]').length).toEqual(1);
|
||||
});
|
||||
|
||||
it('is valid when the threshold value is 0', () => {
|
||||
const onChangeSelectedThreshold = jest.fn();
|
||||
const onChangeSelectedThresholdComparator = jest.fn();
|
||||
const wrapper = shallow(
|
||||
<ThresholdExpression
|
||||
thresholdComparator={'>'}
|
||||
threshold={[0]}
|
||||
errors={{ threshold0: [], threshold1: [] }}
|
||||
onChangeSelectedThreshold={onChangeSelectedThreshold}
|
||||
onChangeSelectedThresholdComparator={onChangeSelectedThresholdComparator}
|
||||
/>
|
||||
);
|
||||
expect(wrapper.find('[data-test-subj="alertThresholdInput"]')).toMatchInlineSnapshot(`
|
||||
<EuiFieldNumber
|
||||
data-test-subj="alertThresholdInput"
|
||||
isInvalid={false}
|
||||
min={0}
|
||||
onChange={[Function]}
|
||||
value={0}
|
||||
/>
|
||||
`);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -17,6 +17,7 @@ import {
|
|||
EuiFieldNumber,
|
||||
EuiText,
|
||||
} from '@elastic/eui';
|
||||
import { isNil } from 'lodash';
|
||||
import { builtInComparators } from '../constants';
|
||||
import { Comparator } from '../types';
|
||||
import { IErrorObject } from '../../types';
|
||||
|
@ -145,14 +146,14 @@ export const ThresholdExpression = ({
|
|||
) : null}
|
||||
<EuiFlexItem grow={false}>
|
||||
<EuiFormRow
|
||||
isInvalid={errors[`threshold${i}`]?.length > 0 || !threshold[i]}
|
||||
isInvalid={errors[`threshold${i}`]?.length > 0 || isNil(threshold[i])}
|
||||
error={errors[`threshold${i}`]}
|
||||
>
|
||||
<EuiFieldNumber
|
||||
data-test-subj="alertThresholdInput"
|
||||
min={0}
|
||||
value={!threshold || threshold[i] === undefined ? '' : threshold[i]}
|
||||
isInvalid={errors[`threshold${i}`]?.length > 0 || !threshold[i]}
|
||||
isInvalid={errors[`threshold${i}`]?.length > 0 || isNil(threshold[i])}
|
||||
onChange={(e) => {
|
||||
const { value } = e.target;
|
||||
const thresholdVal = value !== '' ? parseFloat(value) : undefined;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue