mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[AO] Fix custom equations to support repeating the same variable (#166482)
## Summary This PR fixes #166476 by fixing a bug where you can't repeat a variable twice in the equation. This PR changes the code that converts the variables from `A` to `params.A` by changing a `replace` to a `replaceAll`. The work around would be to duplicate the aggregation that needs to be repeated so it has a unique variable name. ### Checklist - [X] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
172de682c5
commit
ca1df9ec4f
6 changed files with 9 additions and 9 deletions
|
@ -74,6 +74,6 @@ export const createCustomMetricsAggregations = (
|
|||
const convertEquationToPainless = (bucketsPath: { [id: string]: string }, equation?: string) => {
|
||||
const workingEquation = equation || Object.keys(bucketsPath).join(' + ');
|
||||
return Object.keys(bucketsPath).reduce((acc, key) => {
|
||||
return acc.replace(key, `params.${key}`);
|
||||
return acc.replaceAll(key, `params.${key}`);
|
||||
}, workingEquation);
|
||||
};
|
||||
|
|
|
@ -74,6 +74,6 @@ export const createCustomMetricsAggregations = (
|
|||
const convertEquationToPainless = (bucketsPath: { [id: string]: string }, equation?: string) => {
|
||||
const workingEquation = equation || Object.keys(bucketsPath).join(' + ');
|
||||
return Object.keys(bucketsPath).reduce((acc, key) => {
|
||||
return acc.replace(key, `params.${key}`);
|
||||
return acc.replaceAll(key, `params.${key}`);
|
||||
}, workingEquation);
|
||||
};
|
||||
|
|
|
@ -94,7 +94,7 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
{ name: 'A', field: 'system.network.in.bytes', aggType: Aggregators.AVERAGE },
|
||||
{ name: 'B', field: 'system.network.out.bytes', aggType: Aggregators.AVERAGE },
|
||||
],
|
||||
equation: 'A / B ',
|
||||
equation: '(A + A) / (B + B)',
|
||||
},
|
||||
],
|
||||
alertOnNoData: true,
|
||||
|
@ -187,7 +187,7 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
{ name: 'A', field: 'system.network.in.bytes', aggType: Aggregators.AVERAGE },
|
||||
{ name: 'B', field: 'system.network.out.bytes', aggType: Aggregators.AVERAGE },
|
||||
],
|
||||
equation: 'A / B ',
|
||||
equation: '(A + A) / (B + B)',
|
||||
},
|
||||
],
|
||||
alertOnNoData: true,
|
||||
|
|
|
@ -153,7 +153,7 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
{ name: 'A', aggType: 'count', filter: 'event.dataset: "apache2.error"' },
|
||||
{ name: 'B', aggType: 'count' },
|
||||
],
|
||||
equation: '(A / B) * 100',
|
||||
equation: '((A + A) / (B + B)) * 100',
|
||||
label: 'apache2 error ratio',
|
||||
} as CustomMetricExpressionParams,
|
||||
],
|
||||
|
@ -187,7 +187,7 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
{ name: 'A', aggType: 'count', filter: 'event.dataset: "apache2.error"' },
|
||||
{ name: 'B', aggType: 'count' },
|
||||
],
|
||||
equation: '(A / B) * 100',
|
||||
equation: '((A + A) / (B + B)) * 100',
|
||||
currentValue: 36.195262024407754,
|
||||
timestamp: '2021-10-19T00:53:59.997Z',
|
||||
shouldFire: true,
|
||||
|
|
|
@ -134,7 +134,7 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
{ name: 'A', aggregation: 'avg', field: 'system.cpu.user.pct' },
|
||||
{ name: 'B', aggregation: 'avg', field: 'system.cpu.user.pct' },
|
||||
],
|
||||
equation: '(A + B) * 100',
|
||||
equation: '((A + A + B + B) / 2) * 100',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
|
|
@ -95,7 +95,7 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
{ name: 'A', field: 'system.network.in.bytes', aggType: Aggregators.AVERAGE },
|
||||
{ name: 'B', field: 'system.network.out.bytes', aggType: Aggregators.AVERAGE },
|
||||
],
|
||||
equation: 'A / B ',
|
||||
equation: '((A + A) / (B + B))',
|
||||
},
|
||||
],
|
||||
alertOnNoData: true,
|
||||
|
@ -186,7 +186,7 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
{ name: 'A', field: 'system.network.in.bytes', aggType: Aggregators.AVERAGE },
|
||||
{ name: 'B', field: 'system.network.out.bytes', aggType: Aggregators.AVERAGE },
|
||||
],
|
||||
equation: 'A / B ',
|
||||
equation: '((A + A) / (B + B))',
|
||||
},
|
||||
],
|
||||
alertOnNoData: true,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue