[Metrics Alerts] Handle invalid KQL in filterQuery#119557
[Metrics Alerts] Handle invalid KQL in filterQuery#119557Zacqary merged 8 commits intoelastic:mainfrom
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? |
miltonhultgren
left a comment
There was a problem hiding this comment.
LGTM, just a few code clarity questions 👍🏼
|
|
||
| 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.
Nit: For me a name like INVALID_QUERY_MARKER would be more clear.
There was a problem hiding this comment.
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"?
| kueryExpression: string, | ||
| indexPattern: DataViewBase | ||
| indexPattern: DataViewBase, | ||
| swallowErrors: boolean = true |
There was a problem hiding this comment.
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.
| metric: string[]; | ||
| }; | ||
| } = {}; | ||
| } & { filterQuery?: string[] } = {}; |
There was a problem hiding this comment.
NIt: Can this type live as part of the ValidationResult type?
| 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.
I'm wondering if there is any benefit to having two symbols for this?
| const redundantFilterGroupBy = useMemo(() => { | ||
| if (!alertParams.filterQuery || !groupByFilterTestPatterns) return []; | ||
| const { filterQuery } = alertParams; | ||
| if (typeof filterQuery !== 'string' || !groupByFilterTestPatterns) return []; |
There was a problem hiding this comment.
Nit: I'd expect to compare filterQuery to QUERY_INVALID here instead (TypeScript should ensure it's a string in any other case)
| }, | ||
| }); | ||
|
|
||
| if (!params.filterQuery && params.filterQueryText) { |
There was a problem hiding this comment.
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 <Zacqary@users.noreply.github.com>
* [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 <Zacqary@users.noreply.github.com>
|
@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:
filterQueryvalidation to Metric Threshold and Inventory alerts on the frontend. If the KQL query bar is invalid, the alert cannot be saved.filterQuerythat makes it to the backend, for backwards compatibility. The frontend previously sent an emptyfilterQueryto the backend, but because the alert executor can also access thefilterQueryText, it will validate thefilterQueryTextbefore evaluating anything and send an error alert if the query is invalid.Checklist