-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Metrics Alerts] Handle invalid KQL in filterQuery #119557
Conversation
Reverting a change where I imported some We can avoid this by using async imports, but converting all the uses of |
@elasticmachine merge upstream |
I have no idea why the page load bundle size is ballooning. I moved all new imports to |
@elastic/kibana-operations Can you see anything in this PR that would cause the bundle to blow up? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just a few code clarity questions 👍🏼
@@ -70,6 +70,7 @@ import { useKibanaContextForPlugin } from '../../../hooks/use_kibana'; | |||
|
|||
import { ExpressionChart } from './expression_chart'; | |||
const FILTER_TYPING_DEBOUNCE_MS = 500; | |||
export const QUERY_INVALID = Symbol('QUERY_INVALID'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: For me a name like INVALID_QUERY_MARKER
would be more clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to use unique symbol
type and export that type to the other places where this is the value being passed in? So it's not "any symbol"?
@@ -10,7 +10,8 @@ import { esKuery } from '../../../../../src/plugins/data/public'; | |||
|
|||
export const convertKueryToElasticSearchQuery = ( | |||
kueryExpression: string, | |||
indexPattern: DataViewBase | |||
indexPattern: DataViewBase, | |||
swallowErrors: boolean = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can convert this to a small helper instead and use composition for the same effect?
I think it's more clear at call site to read something like this instead:
tryOrFallback(convertKueryToElasticSearchQuery(kuery, indexPatterns), '')
This leaves the places that should throw more clear also by not sending the magic boolean into them.
@@ -34,9 +37,17 @@ export function validateMetricThreshold({ | |||
}; | |||
metric: string[]; | |||
}; | |||
} = {}; | |||
} & { filterQuery?: string[] } = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIt: Can this type live as part of the ValidationResult type?
@@ -42,6 +42,7 @@ import { ExpressionChart } from './expression_chart'; | |||
import { useKibanaContextForPlugin } from '../../../hooks/use_kibana'; | |||
|
|||
const FILTER_TYPING_DEBOUNCE_MS = 500; | |||
export const QUERY_INVALID = Symbol('QUERY_INVALID'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if there is any benefit to having two symbols for this?
@@ -281,15 +286,16 @@ export const Expressions: React.FC<Props> = (props) => { | |||
}, [alertParams.groupBy]); | |||
|
|||
const redundantFilterGroupBy = useMemo(() => { | |||
if (!alertParams.filterQuery || !groupByFilterTestPatterns) return []; | |||
const { filterQuery } = alertParams; | |||
if (typeof filterQuery !== 'string' || !groupByFilterTestPatterns) return []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I'd expect to compare filterQuery to QUERY_INVALID here instead (TypeScript should ensure it's a string in any other case)
@@ -74,6 +75,25 @@ export const createInventoryMetricThresholdExecutor = (libs: InfraBackendLibs) = | |||
}, | |||
}); | |||
|
|||
if (!params.filterQuery && params.filterQueryText) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth wrapping this in a function that calls out it's handling old alerts that didn't have the new guard
@elasticmachine merge upstream |
💚 Build Succeeded
Metrics [docs]Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: |
* [Metrics Alerts] Handle invalid KQL in filterQuery * Add test for malformed KQL, fix existing KQL tests * Revert @kbn/es-query imports
* [Metrics Alerts] Handle invalid KQL in filterQuery * Add test for malformed KQL, fix existing KQL tests * Revert @kbn/es-query imports
* [Metrics Alerts] Handle invalid KQL in filterQuery * Add test for malformed KQL, fix existing KQL tests * Revert @kbn/es-query imports Co-authored-by: Zacqary Adam Xeper <[email protected]>
* [Metrics Alerts] Handle invalid KQL in filterQuery * Add test for malformed KQL, fix existing KQL tests * Revert @kbn/es-query imports Co-authored-by: Zacqary Adam Xeper <[email protected]>
@Zacqary I was looking into this PR and I need a few clarifications.
Let's clarify the correct terminology here, because it gets a bit confusing. @jasonrhodes What are your thoughts? |
* [Metrics Alerts] Handle invalid KQL in filterQuery * Add test for malformed KQL, fix existing KQL tests * Revert @kbn/es-query imports
Summary
Closes #119416
This PR will:
filterQuery
validation to Metric Threshold and Inventory alerts on the frontend. If the KQL query bar is invalid, the alert cannot be saved.filterQuery
that makes it to the backend, for backwards compatibility. The frontend previously sent an emptyfilterQuery
to the backend, but because the alert executor can also access thefilterQueryText
, it will validate thefilterQueryText
before evaluating anything and send an error alert if the query is invalid.Checklist