-
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
[AO] Compile the KQL expression on the server #162701
[AO] Compile the KQL expression on the server #162701
Conversation
🤖 GitHub commentsExpand to view the GitHub comments
Just comment with:
|
@@ -22,7 +22,7 @@ import { MetricExpression } from '../../types'; | |||
import { validateMetricThreshold } from '../validation'; | |||
|
|||
export default { | |||
title: 'infra/alerting/CustomEquationEditor', | |||
title: 'app/Alerts/CustomEquationEditor', |
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.
Storybook is not working properly, created a separate ticket for fixing it (#162720)
Pinging @elastic/actionable-observability (Team: Actionable Observability) |
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.
Tested locally, and the rule has been evaluated correctly, fires alerts, and the filterQuery data are available in the alert and the rule doc thanks @maryam-saeidi !
@@ -25,7 +26,13 @@ const getParsedFilterQuery: (filterQuery: string | undefined) => Array<Record<st | |||
filterQuery | |||
) => { | |||
if (!filterQuery) return []; | |||
return [JSON.parse(filterQuery)]; | |||
|
|||
try { |
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.
@maryam-saeidi, this is where compile the filterQuery
on the server side instead of convertKueryToElasticSearchQuery
in the frontend, right?
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.
Right
@@ -132,7 +132,7 @@ export function thresholdRuleType( | |||
groupBy: schema.maybe(schema.oneOf([schema.string(), schema.arrayOf(schema.string())])), | |||
filterQuery: schema.maybe( | |||
schema.string({ | |||
validate: validateIsStringElasticsearchJSONFilter, | |||
validate: validateKQLStringFilter, |
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.
@kdelemme We should add this to our schemas for anywhere we accept KQL.
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.
@maryam-saeidi Can we add this to the filter
attribute of the customCriterion.customMetrics
object as well?
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.
Sure :)
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.
Done!
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.
Everything looks good code-wise and functionality. Can we add the validateKQLStringFilter
to the schema for the customCriterion.customMetrics
for the filter
attributes?
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
💚 Build Succeeded
Metrics [docs]Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: |
return undefined; | ||
} | ||
return errorMessage; | ||
kbnBuildEsQuery(undefined, [{ query: value, language: 'kuery' }], []); |
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 asked about the differences between fromKueryExpression
and kbnBuildEsQuery
, here is the answer: (link)
I don’t think there is a difference. buildEsQuery calls those methods under the hood
It’s what you get when you call fromKueryExpression, and what you pass to toElasticsearchQuery
Closes #159017
Summary
This PR is related to this comment. Previously, we had both
fitlerQueryText
(unparsed KQL expression) andfilterQuery
(stringified JSON representation of the KQL expression). This makes the JSON body for creating a rule via the API confusing, as @simianhacker pointed out. In this PR, I've removedfilterQuery
and renamedfitlerQueryText
tofilterQuery
to avoid confusion and parsed thefilterQuery
when needed.After this change, you should only see
filterQuery
in the AAD and the rule definition with the user's value.🧪 How to test