[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:
doakalexi 2022-10-10 10:34:09 -04:00 committed by GitHub
parent c7b742c567
commit b542f7b520
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 4 deletions

View file

@ -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'],

View file

@ -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.',