forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML] Transforms: Improve percentiles agg validation (elastic#197816)
## Summary Resolves elastic#138874 The Transforms percentiles aggregation now uses a ComboBox to define percentiles. https://github.com/user-attachments/assets/f30de65e-3555-4643-963b-821877e7b166 a few more validation cases: https://github.com/user-attachments/assets/79339c4e-36d2-465c-bc93-c47e1f442a87 ### Checklist - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- Loading branch information
Showing
14 changed files
with
335 additions
and
55 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
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
146 changes: 146 additions & 0 deletions
146
...pp/sections/create_transform/components/step_define/common/percentiles_agg/config.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,146 @@ | ||
/* | ||
* 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 { getPercentilesAggConfig } from './config'; | ||
import type { IPivotAggsConfigPercentiles } from './types'; | ||
import { PERCENTILES_AGG_DEFAULT_PERCENTS } from '../../../../../../common'; | ||
|
||
describe('percentiles agg config', () => { | ||
let config: IPivotAggsConfigPercentiles; | ||
|
||
beforeEach(() => { | ||
config = getPercentilesAggConfig({ | ||
agg: 'percentiles', | ||
aggName: 'test-agg', | ||
field: ['test-field'], | ||
dropDownName: 'test-agg', | ||
}); | ||
}); | ||
|
||
describe('#setUiConfigFromEs', () => { | ||
test('sets field and percents from ES config', () => { | ||
// act | ||
config.setUiConfigFromEs({ | ||
field: 'test-field', | ||
percents: [10, 20, 30], | ||
}); | ||
|
||
// assert | ||
expect(config.field).toEqual('test-field'); | ||
expect(config.aggConfig).toEqual({ percents: [10, 20, 30] }); | ||
}); | ||
}); | ||
|
||
describe('#getEsAggConfig', () => { | ||
test('returns null for invalid config', () => { | ||
// arrange | ||
config.aggConfig.percents = [150]; // invalid percentile value | ||
|
||
// act and assert | ||
expect(config.getEsAggConfig()).toBeNull(); | ||
}); | ||
|
||
test('returns valid config', () => { | ||
// arrange | ||
config.field = 'test-field'; | ||
config.aggConfig.percents = [10, 20, 30]; | ||
|
||
// act and assert | ||
expect(config.getEsAggConfig()).toEqual({ | ||
field: 'test-field', | ||
percents: [10, 20, 30], | ||
}); | ||
}); | ||
|
||
test('returns default percents if none specified', () => { | ||
// arrange | ||
config.field = 'test-field'; | ||
|
||
// act and assert | ||
expect(config.getEsAggConfig()).toEqual({ | ||
field: 'test-field', | ||
percents: PERCENTILES_AGG_DEFAULT_PERCENTS, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('#isValid', () => { | ||
test('returns false for percentiles out of range', () => { | ||
// arrange | ||
config.aggConfig.percents = [150]; | ||
|
||
// act and assert | ||
expect(config.isValid()).toBeFalsy(); | ||
expect(config.aggConfig.errors).toContain('PERCENTILE_OUT_OF_RANGE'); | ||
}); | ||
|
||
test('returns false for invalid number format', () => { | ||
// arrrange | ||
config.aggConfig.pendingPercentileInput = 'invalid'; | ||
|
||
// act and assert | ||
expect(config.isValid()).toBeFalsy(); | ||
expect(config.aggConfig.errors).toContain('INVALID_FORMAT'); | ||
}); | ||
|
||
test('returns true for valid percents', () => { | ||
// arrange | ||
config.aggConfig.percents = [10, 20, 30]; | ||
|
||
// act and assert | ||
expect(config.isValid()).toBeTruthy(); | ||
expect(config.aggConfig.errors).toBeUndefined(); | ||
}); | ||
|
||
test('validates pending input along with existing percents', () => { | ||
// arrange | ||
config.aggConfig.percents = [10, 20, 30]; | ||
config.aggConfig.pendingPercentileInput = '50'; | ||
|
||
// act and assert | ||
expect(config.isValid()).toBeTruthy(); | ||
expect(config.aggConfig.errors).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe('#getErrorMessages', () => { | ||
test('returns undefined when there are no errors', () => { | ||
// arrange | ||
config.aggConfig.errors = undefined; | ||
|
||
// act and assert | ||
expect(config.getErrorMessages?.()).toBeUndefined(); | ||
}); | ||
|
||
test('returns undefined when errors array is empty', () => { | ||
// arrange | ||
config.aggConfig.errors = []; | ||
|
||
// act and assert | ||
expect(config.getErrorMessages?.()).toBeUndefined(); | ||
}); | ||
|
||
test('returns translated messages for single error', () => { | ||
// arrange | ||
config.aggConfig.errors = ['PERCENTILE_OUT_OF_RANGE']; | ||
|
||
// act and assert | ||
expect(config.getErrorMessages?.()).toEqual(['Percentiles must be between 0 and 100']); | ||
}); | ||
|
||
test('returns translated messages for multiple errors', () => { | ||
// arrange | ||
config.aggConfig.errors = ['PERCENTILE_OUT_OF_RANGE', 'INVALID_FORMAT']; | ||
|
||
// act and assert | ||
expect(config.getErrorMessages?.()).toEqual([ | ||
'Percentiles must be between 0 and 100', | ||
'Percentile must be a valid number', | ||
]); | ||
}); | ||
}); | ||
}); |
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
10 changes: 10 additions & 0 deletions
10
.../app/sections/create_transform/components/step_define/common/percentiles_agg/constants.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,10 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export const MAX_PERCENTILE_PRECISION = 17; | ||
export const MAX_PERCENTILE_VALUE = 100; | ||
export const MIN_PERCENTILE_VALUE = 0; |
Oops, something went wrong.