Skip to content

Commit

Permalink
Apply KQL validation with leadingWildcard as true
Browse files Browse the repository at this point in the history
  • Loading branch information
maryam-saeidi committed Aug 9, 2024
1 parent dc8ee2f commit cf3e014
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
valueActionVariableDescription,
viewInAppUrlActionVariableDescription,
} from './translations';
import { oneOfLiterals } from './utils';
import { oneOfLiterals, validateKQLStringFilter } from './utils';
import {
createCustomThresholdExecutor,
CustomThresholdLocators,
Expand All @@ -57,11 +57,9 @@ export const searchConfigurationSchema = schema.object({
index: schema.oneOf([schema.string(), dataViewSpecSchema]),
query: schema.object({
language: schema.string(),
query: schema.string(),
// TODO Enable KQL validation: https://github.com/elastic/kibana/issues/190029
// query: schema.string({
// validate: validateKQLStringFilter,
// }),
query: schema.string({
validate: validateKQLStringFilter,
}),
}),
filter: schema.maybe(
schema.arrayOf(
Expand Down Expand Up @@ -105,11 +103,9 @@ export function thresholdRuleType(
name: schema.string(),
aggType: schema.literal('count'),
filter: schema.maybe(
schema.string()
// TODO Enable KQL validation: https://github.com/elastic/kibana/issues/190029
// schema.string({
// validate: validateKQLStringFilter,
// })
schema.string({
validate: validateKQLStringFilter,
})
),
field: schema.never(),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ export const validateKQLStringFilter = (value: string) => {
}

try {
kbnBuildEsQuery(undefined, [{ query: value, language: 'kuery' }], []);
kbnBuildEsQuery(undefined, [{ query: value, language: 'kuery' }], [], {
allowLeadingWildcards: true,
queryStringOptions: {},
ignoreFilterIfFieldNotInIndex: true,
});
} catch (e) {
return i18n.translate('xpack.observability.customThreshold.rule.schema.invalidFilterQuery', {
defaultMessage: `filterQuery must be a valid KQL filter (error: ${e.message})`,
Expand Down

0 comments on commit cf3e014

Please sign in to comment.