Skip to content

Commit

Permalink
[8.x] [Obx-ux-mgmt][Alerting]Mismatch between preview chart and rule …
Browse files Browse the repository at this point in the history
…execution regarding wildcards (#201553) (#201733)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Obx-ux-mgmt][Alerting]Mismatch between preview chart and rule
execution regarding wildcards
(#201553)](#201553)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Faisal
Kanout","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-26T09:33:55Z","message":"[Obx-ux-mgmt][Alerting]Mismatch
between preview chart and rule execution regarding wildcards
(#201553)\n\n## Summary\r\nIt fixes #186624 by making the preview chat
represent the wildcard\r\ncorrectly. The missing use case was when
passing the query without \" \"\r\n\r\n\r\n|Tested
cases|Note|\r\n|---|---|\r\n|<img width=\"596\" alt=\"Screenshot
2024-11-25 at 12 04
14\"\r\nsrc=\"https://github.com/user-attachments/assets/8140d175-9ff3-4d1a-ac72-baf1e7878326\">|<img\r\nwidth=\"594\"
alt=\"Screenshot 2024-11-25 at 12 04
27\"\r\nsrc=\"https://github.com/user-attachments/assets/cf0eeb97-0fe7-4509-b4db-c8e4b54e0def\">We\r\ncan't
show \"NoData\" in this case. I tested the same formula in Lens
and\r\ngot the same results. It's not ideal, but at least we don't have
any\r\ndata/bars that could mislead the user|\r\n\r\n\r\n|<img
width=\"596\" alt=\"Screenshot 2024-11-25 at 11 59
53\"\r\nsrc=\"https://github.com/user-attachments/assets/cc128bd7-f4aa-403a-8c0a-398b36694064\">||\r\n|<img
width=\"596\" alt=\"Screenshot 2024-11-25 at 11 59
41\"\r\nsrc=\"https://github.com/user-attachments/assets/7f4ae425-6c3b-4067-ab45-0e8282ddd901\">||\r\n|<img
width=\"596\" alt=\"Screenshot 2024-11-25 at 11 59
28\"\r\nsrc=\"https://github.com/user-attachments/assets/e2e6dfde-834a-4921-8471-a7270bbd2f9c\">||\r\n|<img
width=\"596\" alt=\"Screenshot 2024-11-25 at 11 59
08\"\r\nsrc=\"https://github.com/user-attachments/assets/6ffc641d-b043-4740-897f-5d4e94adda41\">||\r\n|<img
width=\"596\" alt=\"Screenshot 2024-11-25 at 11 58
58\"\r\nsrc=\"https://github.com/user-attachments/assets/5122e9df-b392-4785-8a2b-5219c818dfed\">||","sha":"f0c8fde12469a9d827a4f4cb8498f3210b400ce2","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:fix","Feature:Alerting","v9.0.0","backport:prev-minor","ci:project-deploy-observability","Team:obs-ux-management","v8.18.0"],"title":"[Obx-ux-mgmt][Alerting]Mismatch
between preview chart and rule execution regarding
wildcards","number":201553,"url":"https://github.com/elastic/kibana/pull/201553","mergeCommit":{"message":"[Obx-ux-mgmt][Alerting]Mismatch
between preview chart and rule execution regarding wildcards
(#201553)\n\n## Summary\r\nIt fixes #186624 by making the preview chat
represent the wildcard\r\ncorrectly. The missing use case was when
passing the query without \" \"\r\n\r\n\r\n|Tested
cases|Note|\r\n|---|---|\r\n|<img width=\"596\" alt=\"Screenshot
2024-11-25 at 12 04
14\"\r\nsrc=\"https://github.com/user-attachments/assets/8140d175-9ff3-4d1a-ac72-baf1e7878326\">|<img\r\nwidth=\"594\"
alt=\"Screenshot 2024-11-25 at 12 04
27\"\r\nsrc=\"https://github.com/user-attachments/assets/cf0eeb97-0fe7-4509-b4db-c8e4b54e0def\">We\r\ncan't
show \"NoData\" in this case. I tested the same formula in Lens
and\r\ngot the same results. It's not ideal, but at least we don't have
any\r\ndata/bars that could mislead the user|\r\n\r\n\r\n|<img
width=\"596\" alt=\"Screenshot 2024-11-25 at 11 59
53\"\r\nsrc=\"https://github.com/user-attachments/assets/cc128bd7-f4aa-403a-8c0a-398b36694064\">||\r\n|<img
width=\"596\" alt=\"Screenshot 2024-11-25 at 11 59
41\"\r\nsrc=\"https://github.com/user-attachments/assets/7f4ae425-6c3b-4067-ab45-0e8282ddd901\">||\r\n|<img
width=\"596\" alt=\"Screenshot 2024-11-25 at 11 59
28\"\r\nsrc=\"https://github.com/user-attachments/assets/e2e6dfde-834a-4921-8471-a7270bbd2f9c\">||\r\n|<img
width=\"596\" alt=\"Screenshot 2024-11-25 at 11 59
08\"\r\nsrc=\"https://github.com/user-attachments/assets/6ffc641d-b043-4740-897f-5d4e94adda41\">||\r\n|<img
width=\"596\" alt=\"Screenshot 2024-11-25 at 11 58
58\"\r\nsrc=\"https://github.com/user-attachments/assets/5122e9df-b392-4785-8a2b-5219c818dfed\">||","sha":"f0c8fde12469a9d827a4f4cb8498f3210b400ce2"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/201553","number":201553,"mergeCommit":{"message":"[Obx-ux-mgmt][Alerting]Mismatch
between preview chart and rule execution regarding wildcards
(#201553)\n\n## Summary\r\nIt fixes #186624 by making the preview chat
represent the wildcard\r\ncorrectly. The missing use case was when
passing the query without \" \"\r\n\r\n\r\n|Tested
cases|Note|\r\n|---|---|\r\n|<img width=\"596\" alt=\"Screenshot
2024-11-25 at 12 04
14\"\r\nsrc=\"https://github.com/user-attachments/assets/8140d175-9ff3-4d1a-ac72-baf1e7878326\">|<img\r\nwidth=\"594\"
alt=\"Screenshot 2024-11-25 at 12 04
27\"\r\nsrc=\"https://github.com/user-attachments/assets/cf0eeb97-0fe7-4509-b4db-c8e4b54e0def\">We\r\ncan't
show \"NoData\" in this case. I tested the same formula in Lens
and\r\ngot the same results. It's not ideal, but at least we don't have
any\r\ndata/bars that could mislead the user|\r\n\r\n\r\n|<img
width=\"596\" alt=\"Screenshot 2024-11-25 at 11 59
53\"\r\nsrc=\"https://github.com/user-attachments/assets/cc128bd7-f4aa-403a-8c0a-398b36694064\">||\r\n|<img
width=\"596\" alt=\"Screenshot 2024-11-25 at 11 59
41\"\r\nsrc=\"https://github.com/user-attachments/assets/7f4ae425-6c3b-4067-ab45-0e8282ddd901\">||\r\n|<img
width=\"596\" alt=\"Screenshot 2024-11-25 at 11 59
28\"\r\nsrc=\"https://github.com/user-attachments/assets/e2e6dfde-834a-4921-8471-a7270bbd2f9c\">||\r\n|<img
width=\"596\" alt=\"Screenshot 2024-11-25 at 11 59
08\"\r\nsrc=\"https://github.com/user-attachments/assets/6ffc641d-b043-4740-897f-5d4e94adda41\">||\r\n|<img
width=\"596\" alt=\"Screenshot 2024-11-25 at 11 58
58\"\r\nsrc=\"https://github.com/user-attachments/assets/5122e9df-b392-4785-8a2b-5219c818dfed\">||","sha":"f0c8fde12469a9d827a4f4cb8498f3210b400ce2"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Faisal Kanout <[email protected]>
  • Loading branch information
kibanamachine and fkanout authored Nov 26, 2024
1 parent 9681162 commit ce65421
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,32 @@ const useCases = [
sourceField: '',
},
],
[
{
aggType: Aggregators.COUNT,
field: '',
filter: `container.name:container's name-1`,
name: '',
},
{
operation: 'count',
operationWithField: `count(kql='container.name:container\\'s name-1')`,
sourceField: '',
},
],
[
{
aggType: Aggregators.COUNT,
field: '',
filter: 'host.name: host-*',
name: '',
},
{
operation: 'count',
operationWithField: `count(kql='host.name: host-*')`,
sourceField: '',
},
],
[
{
aggType: Aggregators.CARDINALITY,
Expand Down Expand Up @@ -136,7 +162,7 @@ const useCases = [
},
{
operation: 'counter_rate',
operationWithField: `counter_rate(max(system.network.in.bytes), kql='host.name : foo')`,
operationWithField: `counter_rate(max(system.network.in.bytes), kql='host.name : "foo"')`,
sourceField: 'system.network.in.bytes',
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ export interface LensOperation {
}

export const getLensOperationFromRuleMetric = (metric: GenericMetric): LensOperation => {
const { aggType, field, filter } = metric;
const { aggType, field, filter = '' } = metric;
let operation: string = aggType;
const operationArgs: string[] = [];
const aggFilter = JSON.stringify(filter || '').replace(/"|\\/g, '');
const escapedFilter = filter.replace(/'/g, "\\'");

if (aggType === Aggregators.RATE) {
return {
operation: 'counter_rate',
operationWithField: `counter_rate(max(${field}), kql='${aggFilter}')`,
operationWithField: `counter_rate(max(${field}), kql='${escapedFilter}')`,
sourceField: field || '',
};
}
Expand All @@ -45,8 +45,7 @@ export const getLensOperationFromRuleMetric = (metric: GenericMetric): LensOpera
operationArgs.push('percentile=99');
}

if (aggFilter) operationArgs.push(`kql='${aggFilter}'`);

if (escapedFilter) operationArgs.push(`kql='${escapedFilter}'`);
return {
operation,
operationWithField: `${operation}(${operationArgs.join(', ')})`,
Expand Down

0 comments on commit ce65421

Please sign in to comment.