Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.11] [ResponseOps] Elasticsearch query rule with ES|QL threshold va…
…lidation (elastic#170463) (elastic#170481) # Backport This will backport the following commits from `main` to `8.11`: - [[ResponseOps] Elasticsearch query rule with ES|QL threshold validation (elastic#170463)](elastic#170463) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Alexi Doak","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-11-02T20:00:13Z","message":"[ResponseOps] Elasticsearch query rule with ES|QL threshold validation (elastic#170463)\n\nResolves https://github.com/elastic/kibana/issues/170360\r\n\r\n## Summary\r\n\r\nWe should be throwing an error if a user tries to create an ESQL es\r\nquery rule where `thresholdCompartor != '>'` or `threshold != 0` or\r\n`timeField` is not defined.\r\n\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\n### To verify\r\n\r\n- Go to [dev tools](http://localhost:5601/app/dev_tools#/console)\r\n- Run the following and edit thresholdComparator, threshold, or\r\ntimeField and verify that you see errors thrown.\r\n```\r\nPOST kbn:/api/alerting/rule\r\n{\r\n \"params\": {\r\n \"searchType\": \"esqlQuery\",\r\n \"esqlQuery\": {\r\n \"esql\": \"\"\"from kibana_sample_data_logs\r\n| keep bytes, clientip, host, geo.dest\r\n| where geo.dest != \"GB\"\r\n| stats sumbytes = sum(bytes) by clientip, host\r\n| WHERE sumbytes > 5000\r\n| sort sumbytes desc\r\n| limit 10\"\"\"\r\n },\r\n \"timeWindowSize\": 1,\r\n \"timeWindowUnit\": \"d\",\r\n \"thresholdComparator\": \"<\",\r\n \"threshold\": [\r\n 1000\r\n ],\r\n \"size\": 10,\r\n \"timeField\": \"date\"\r\n },\r\n \"consumer\": \"stackAlerts\",\r\n \"rule_type_id\": \".es-query\",\r\n \"schedule\": {\r\n \"interval\": \"5d\"\r\n },\r\n \"name\": \"test rule\"\r\n}\r\n```","sha":"0e7798a4024b6f9f60700e60101868960172796d","branchLabelMapping":{"^v8.12.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","Team:ResponseOps","v8.11.0","v8.12.0"],"number":170463,"url":"https://github.com/elastic/kibana/pull/170463","mergeCommit":{"message":"[ResponseOps] Elasticsearch query rule with ES|QL threshold validation (elastic#170463)\n\nResolves https://github.com/elastic/kibana/issues/170360\r\n\r\n## Summary\r\n\r\nWe should be throwing an error if a user tries to create an ESQL es\r\nquery rule where `thresholdCompartor != '>'` or `threshold != 0` or\r\n`timeField` is not defined.\r\n\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\n### To verify\r\n\r\n- Go to [dev tools](http://localhost:5601/app/dev_tools#/console)\r\n- Run the following and edit thresholdComparator, threshold, or\r\ntimeField and verify that you see errors thrown.\r\n```\r\nPOST kbn:/api/alerting/rule\r\n{\r\n \"params\": {\r\n \"searchType\": \"esqlQuery\",\r\n \"esqlQuery\": {\r\n \"esql\": \"\"\"from kibana_sample_data_logs\r\n| keep bytes, clientip, host, geo.dest\r\n| where geo.dest != \"GB\"\r\n| stats sumbytes = sum(bytes) by clientip, host\r\n| WHERE sumbytes > 5000\r\n| sort sumbytes desc\r\n| limit 10\"\"\"\r\n },\r\n \"timeWindowSize\": 1,\r\n \"timeWindowUnit\": \"d\",\r\n \"thresholdComparator\": \"<\",\r\n \"threshold\": [\r\n 1000\r\n ],\r\n \"size\": 10,\r\n \"timeField\": \"date\"\r\n },\r\n \"consumer\": \"stackAlerts\",\r\n \"rule_type_id\": \".es-query\",\r\n \"schedule\": {\r\n \"interval\": \"5d\"\r\n },\r\n \"name\": \"test rule\"\r\n}\r\n```","sha":"0e7798a4024b6f9f60700e60101868960172796d"}},"sourceBranch":"main","suggestedTargetBranches":["8.11"],"targetPullRequestStates":[{"branch":"8.11","label":"v8.11.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.12.0","labelRegex":"^v8.12.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/170463","number":170463,"mergeCommit":{"message":"[ResponseOps] Elasticsearch query rule with ES|QL threshold validation (elastic#170463)\n\nResolves https://github.com/elastic/kibana/issues/170360\r\n\r\n## Summary\r\n\r\nWe should be throwing an error if a user tries to create an ESQL es\r\nquery rule where `thresholdCompartor != '>'` or `threshold != 0` or\r\n`timeField` is not defined.\r\n\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\n### To verify\r\n\r\n- Go to [dev tools](http://localhost:5601/app/dev_tools#/console)\r\n- Run the following and edit thresholdComparator, threshold, or\r\ntimeField and verify that you see errors thrown.\r\n```\r\nPOST kbn:/api/alerting/rule\r\n{\r\n \"params\": {\r\n \"searchType\": \"esqlQuery\",\r\n \"esqlQuery\": {\r\n \"esql\": \"\"\"from kibana_sample_data_logs\r\n| keep bytes, clientip, host, geo.dest\r\n| where geo.dest != \"GB\"\r\n| stats sumbytes = sum(bytes) by clientip, host\r\n| WHERE sumbytes > 5000\r\n| sort sumbytes desc\r\n| limit 10\"\"\"\r\n },\r\n \"timeWindowSize\": 1,\r\n \"timeWindowUnit\": \"d\",\r\n \"thresholdComparator\": \"<\",\r\n \"threshold\": [\r\n 1000\r\n ],\r\n \"size\": 10,\r\n \"timeField\": \"date\"\r\n },\r\n \"consumer\": \"stackAlerts\",\r\n \"rule_type_id\": \".es-query\",\r\n \"schedule\": {\r\n \"interval\": \"5d\"\r\n },\r\n \"name\": \"test rule\"\r\n}\r\n```","sha":"0e7798a4024b6f9f60700e60101868960172796d"}}]}] BACKPORT--> Co-authored-by: Alexi Doak <[email protected]>
- Loading branch information