-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Custom threshold] Use percent unit if all metrics are percent (#179841)
Closes #171121 ## Summary Now, for multiple aggregations, the unit will be changed to percent if all metrics are percent. https://github.com/elastic/kibana/assets/12370520/37cc6bd0-b75d-4dba-8529-b40f9fb41ba2
- Loading branch information
1 parent
cc840e2
commit 1e0ebaa
Showing
5 changed files
with
195 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 0 additions & 93 deletions
93
...ility/public/components/custom_threshold/helpers/adjust_threshold_based_on_format.test.ts
This file was deleted.
Oops, something went wrong.
182 changes: 182 additions & 0 deletions
182
..._solution/observability/public/components/custom_threshold/helpers/threshold_unit.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { | ||
Aggregators, | ||
CustomThresholdExpressionMetric, | ||
} from '../../../../common/custom_threshold_rule/types'; | ||
import { convertToApiThreshold } from './threshold_unit'; | ||
|
||
describe('convertToApiThreshold', () => { | ||
test('previous: nonPercent, next: percent -> threshold / 100', () => { | ||
const previous: CustomThresholdExpressionMetric[] = [ | ||
{ | ||
name: 'A', | ||
aggType: Aggregators.COUNT, | ||
}, | ||
]; | ||
const next: CustomThresholdExpressionMetric[] = [ | ||
{ | ||
name: 'A', | ||
field: 'system.cpu.system.pct', | ||
aggType: Aggregators.AVERAGE, | ||
}, | ||
]; | ||
const threshold: number[] = [100]; | ||
const expectedThreshold: number[] = [1]; | ||
|
||
expect(convertToApiThreshold(previous, next, threshold)).toEqual(expectedThreshold); | ||
}); | ||
|
||
test('previous: percent, next: nonPercent -> threshold * 100', () => { | ||
const previous: CustomThresholdExpressionMetric[] = [ | ||
{ | ||
name: 'A', | ||
field: 'system.cpu.system.pct', | ||
aggType: Aggregators.AVERAGE, | ||
}, | ||
]; | ||
const next: CustomThresholdExpressionMetric[] = [ | ||
{ | ||
name: 'A', | ||
aggType: Aggregators.COUNT, | ||
}, | ||
]; | ||
const threshold: number[] = [1]; | ||
const expectedThreshold: number[] = [100]; | ||
|
||
expect(convertToApiThreshold(previous, next, threshold)).toEqual(expectedThreshold); | ||
}); | ||
|
||
test('previous: percent, next: percent -> no threshold change', () => { | ||
const previous: CustomThresholdExpressionMetric[] = [ | ||
{ | ||
name: 'A', | ||
field: 'system.cpu.system.pct', | ||
aggType: Aggregators.AVERAGE, | ||
}, | ||
]; | ||
const next: CustomThresholdExpressionMetric[] = [ | ||
{ | ||
name: 'A', | ||
field: 'system.cpu.total.norm.pct', | ||
aggType: Aggregators.AVERAGE, | ||
}, | ||
]; | ||
const threshold: number[] = [1]; | ||
|
||
expect(convertToApiThreshold(previous, next, threshold)).toEqual(threshold); | ||
}); | ||
|
||
test('previous: nonPercent, next: nonPercent -> no threshold change', () => { | ||
const previous: CustomThresholdExpressionMetric[] = [ | ||
{ | ||
name: 'A', | ||
field: 'host.disk.read.bytes', | ||
aggType: Aggregators.AVERAGE, | ||
}, | ||
]; | ||
const next: CustomThresholdExpressionMetric[] = [ | ||
{ | ||
name: 'A', | ||
aggType: Aggregators.COUNT, | ||
}, | ||
]; | ||
const threshold: number[] = [100]; | ||
|
||
expect(convertToApiThreshold(previous, next, threshold)).toEqual(threshold); | ||
}); | ||
|
||
test('multiple metrics (previous: one percent, next: one percent) -> no threshold change', () => { | ||
const previous: CustomThresholdExpressionMetric[] = [ | ||
{ | ||
name: 'A', | ||
field: 'host.disk.read.bytes', | ||
aggType: Aggregators.AVERAGE, | ||
}, | ||
{ | ||
name: 'B', | ||
field: 'system.cpu.system.pct', | ||
aggType: Aggregators.AVERAGE, | ||
}, | ||
]; | ||
const next: CustomThresholdExpressionMetric[] = [ | ||
{ | ||
name: 'A', | ||
aggType: Aggregators.COUNT, | ||
}, | ||
{ | ||
name: 'B', | ||
field: 'system.cpu.system.pct', | ||
aggType: Aggregators.AVERAGE, | ||
}, | ||
]; | ||
const threshold: number[] = [100]; | ||
|
||
expect(convertToApiThreshold(previous, next, threshold)).toEqual(threshold); | ||
}); | ||
|
||
test('multiple metrics (previous: ALL percent, next: some percent) -> threshold * 100', () => { | ||
const previous: CustomThresholdExpressionMetric[] = [ | ||
{ | ||
name: 'A', | ||
field: 'system.cpu.user.pct', | ||
aggType: Aggregators.AVERAGE, | ||
}, | ||
{ | ||
name: 'B', | ||
field: 'system.cpu.system.pct', | ||
aggType: Aggregators.AVERAGE, | ||
}, | ||
]; | ||
const next: CustomThresholdExpressionMetric[] = [ | ||
{ | ||
name: 'A', | ||
aggType: Aggregators.COUNT, | ||
}, | ||
{ | ||
name: 'B', | ||
field: 'system.cpu.system.pct', | ||
aggType: Aggregators.AVERAGE, | ||
}, | ||
]; | ||
const threshold: number[] = [1]; | ||
const expectedThreshold: number[] = [100]; | ||
|
||
expect(convertToApiThreshold(previous, next, threshold)).toEqual(expectedThreshold); | ||
}); | ||
|
||
test('multiple metrics (previous: some percent, next: ALL percent) -> threshold / 100', () => { | ||
const previous: CustomThresholdExpressionMetric[] = [ | ||
{ | ||
name: 'A', | ||
aggType: Aggregators.COUNT, | ||
}, | ||
{ | ||
name: 'B', | ||
field: 'system.cpu.system.pct', | ||
aggType: Aggregators.AVERAGE, | ||
}, | ||
]; | ||
const next: CustomThresholdExpressionMetric[] = [ | ||
{ | ||
name: 'A', | ||
field: 'system.cpu.user.pct', | ||
aggType: Aggregators.AVERAGE, | ||
}, | ||
{ | ||
name: 'B', | ||
field: 'system.cpu.system.pct', | ||
aggType: Aggregators.AVERAGE, | ||
}, | ||
]; | ||
const threshold: number[] = [100]; | ||
const expectedThreshold: number[] = [1]; | ||
|
||
expect(convertToApiThreshold(previous, next, threshold)).toEqual(expectedThreshold); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters