Skip to content
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

Merged

Conversation

maryam-saeidi
Copy link
Member

@maryam-saeidi maryam-saeidi commented Jul 28, 2023

Closes #159017

Summary

This PR is related to this comment. Previously, we had both fitlerQueryText (unparsed KQL expression) and filterQuery (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 removed filterQuery and renamed fitlerQueryText to filterQuery to avoid confusion and parsed the filterQuery when needed.

After this change, you should only see filterQuery in the AAD and the rule definition with the user's value.

Rule definition Alert document
image image

🧪 How to test

  • Create a new threshold rule and add a filter for it
  • Make sure that all the rule functionalities that use filter work as expected
    • Preview
    • Rule execution
    • Saved data in rule definition and alert document
  • Add an invalid filter query by editing the rule and make sure the validation works as expected (filter should be invalid state and save button should not work)

@maryam-saeidi maryam-saeidi self-assigned this Jul 28, 2023
@apmmachine
Copy link
Contributor

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • /oblt-deploy-serverless : Deploy a serverless Kibana instance using the Observability test environments.
  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@maryam-saeidi maryam-saeidi added the release_note:skip Skip the PR/issue when compiling release notes label Jul 28, 2023
@maryam-saeidi maryam-saeidi marked this pull request as ready for review July 29, 2023 05:10
@maryam-saeidi maryam-saeidi requested a review from a team as a code owner July 29, 2023 05:10
@@ -22,7 +22,7 @@ import { MetricExpression } from '../../types';
import { validateMetricThreshold } from '../validation';

export default {
title: 'infra/alerting/CustomEquationEditor',
title: 'app/Alerts/CustomEquationEditor',
Copy link
Member Author

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)

@maryam-saeidi maryam-saeidi added the Team: Actionable Observability - DEPRECATED For Observability Alerting and SLOs use "Team:obs-ux-management", for AIops "Team:obs-knowledge" label Jul 31, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/actionable-observability (Team: Actionable Observability)

@fkanout fkanout self-requested a review July 31, 2023 13:12
Copy link
Contributor

@fkanout fkanout left a 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 !
Screenshot 2023-07-31 at 15 56 41
Screenshot 2023-07-31 at 15 57 43

@@ -25,7 +26,13 @@ const getParsedFilterQuery: (filterQuery: string | undefined) => Array<Record<st
filterQuery
) => {
if (!filterQuery) return [];
return [JSON.parse(filterQuery)];

try {
Copy link
Contributor

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?

Copy link
Member Author

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,
Copy link
Member

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.

Copy link
Member

@simianhacker simianhacker Aug 1, 2023

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Member

@simianhacker simianhacker left a 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?

@simianhacker simianhacker self-requested a review August 1, 2023 16:13
Copy link
Member

@simianhacker simianhacker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
observability 1.0MB 1.0MB -264.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
observability 58.5KB 58.7KB +201.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @maryam-saeidi

@maryam-saeidi maryam-saeidi merged commit d0d3127 into elastic:main Aug 2, 2023
@kibanamachine kibanamachine added v8.10.0 backport:skip This commit does not require backporting labels Aug 2, 2023
return undefined;
}
return errorMessage;
kbnBuildEsQuery(undefined, [{ query: value, language: 'kuery' }], []);
Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team: Actionable Observability - DEPRECATED For Observability Alerting and SLOs use "Team:obs-ux-management", for AIops "Team:obs-knowledge" v8.10.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[AO] Compile the KQL expression on the server.
7 participants