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] string_utils cleanup. (elastic#71092) (elastic#71253)
- Converts string_utils to TypeScript. - Removes sortByKey() from string_utils, we no longer make use of it. - Fixes elastic#69499, stringMatch() was defined twice, now moved to string_utils. - Fixes elastic#69498, OMIT_FIELDS was defined twice, now moved to common/constants/field_types.ts.
- Loading branch information
Showing
10 changed files
with
53 additions
and
132 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
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
21 changes: 0 additions & 21 deletions
21
x-pack/plugins/ml/public/application/util/string_utils.d.ts
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -4,18 +4,20 @@ | |
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { CustomUrlAnomalyRecordDoc } from '../../../common/types/custom_urls'; | ||
import { Detector } from '../../../common/types/anomaly_detection_jobs'; | ||
|
||
import { | ||
replaceStringTokens, | ||
detectorToString, | ||
sortByKey, | ||
toLocaleString, | ||
mlEscape, | ||
escapeForElasticsearchQuery, | ||
} from './string_utils'; | ||
|
||
describe('ML - string utils', () => { | ||
describe('replaceStringTokens', () => { | ||
const testRecord = { | ||
const testRecord: CustomUrlAnomalyRecordDoc = { | ||
job_id: 'test_job', | ||
result_type: 'record', | ||
probability: 0.0191711, | ||
|
@@ -30,6 +32,10 @@ describe('ML - string utils', () => { | |
testfield1: 'test$tring=[+-?]', | ||
testfield2: '{<()>}', | ||
testfield3: 'host=\\\\[email protected]', | ||
earliest: '0', | ||
latest: '0', | ||
is_interim: false, | ||
initial_record_score: 0, | ||
}; | ||
|
||
test('returns correct values without URI encoding', () => { | ||
|
@@ -68,17 +74,17 @@ describe('ML - string utils', () => { | |
|
||
describe('detectorToString', () => { | ||
test('returns the correct descriptions for detectors', () => { | ||
const detector1 = { | ||
const detector1: Detector = { | ||
function: 'count', | ||
}; | ||
|
||
const detector2 = { | ||
const detector2: Detector = { | ||
function: 'count', | ||
by_field_name: 'airline', | ||
use_null: false, | ||
}; | ||
|
||
const detector3 = { | ||
const detector3: Detector = { | ||
function: 'mean', | ||
field_name: 'CPUUtilization', | ||
partition_field_name: 'region', | ||
|
@@ -95,50 +101,6 @@ describe('ML - string utils', () => { | |
}); | ||
}); | ||
|
||
describe('sortByKey', () => { | ||
const obj = { | ||
zebra: 'stripes', | ||
giraffe: 'neck', | ||
elephant: 'trunk', | ||
}; | ||
|
||
const valueComparator = function (value: string) { | ||
return value; | ||
}; | ||
|
||
test('returns correct ordering with default comparator', () => { | ||
const result = sortByKey(obj, false); | ||
const keys = Object.keys(result); | ||
expect(keys[0]).toBe('elephant'); | ||
expect(keys[1]).toBe('giraffe'); | ||
expect(keys[2]).toBe('zebra'); | ||
}); | ||
|
||
test('returns correct ordering with default comparator and order reversed', () => { | ||
const result = sortByKey(obj, true); | ||
const keys = Object.keys(result); | ||
expect(keys[0]).toBe('zebra'); | ||
expect(keys[1]).toBe('giraffe'); | ||
expect(keys[2]).toBe('elephant'); | ||
}); | ||
|
||
test('returns correct ordering with comparator', () => { | ||
const result = sortByKey(obj, false, valueComparator); | ||
const keys = Object.keys(result); | ||
expect(keys[0]).toBe('giraffe'); | ||
expect(keys[1]).toBe('zebra'); | ||
expect(keys[2]).toBe('elephant'); | ||
}); | ||
|
||
test('returns correct ordering with comparator and order reversed', () => { | ||
const result = sortByKey(obj, true, valueComparator); | ||
const keys = Object.keys(result); | ||
expect(keys[0]).toBe('elephant'); | ||
expect(keys[1]).toBe('zebra'); | ||
expect(keys[2]).toBe('giraffe'); | ||
}); | ||
}); | ||
|
||
describe('toLocaleString', () => { | ||
test('returns correct comma placement for large numbers', () => { | ||
expect(toLocaleString(1)).toBe('1'); | ||
|
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