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.
Reapply "[Security Solution] [Attack discovery] Output chunking / ref…
…inement, LangGraph migration, and evaluation improvements (elastic#195669)" (elastic#196440) elastic#195669 + elastic#196381 This reverts commit dbe6d82. --------- Co-authored-by: Alex Szabo <[email protected]>
- Loading branch information
Showing
190 changed files
with
8,378 additions
and
2,148 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
28 changes: 28 additions & 0 deletions
28
...es/kbn-elastic-assistant-common/impl/alerts/helpers/get_raw_data_or_default/index.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,28 @@ | ||
/* | ||
* 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 { getRawDataOrDefault } from '.'; | ||
|
||
describe('getRawDataOrDefault', () => { | ||
it('returns the raw data when it is valid', () => { | ||
const rawData = { | ||
field1: [1, 2, 3], | ||
field2: ['a', 'b', 'c'], | ||
}; | ||
|
||
expect(getRawDataOrDefault(rawData)).toEqual(rawData); | ||
}); | ||
|
||
it('returns an empty object when the raw data is invalid', () => { | ||
const rawData = { | ||
field1: [1, 2, 3], | ||
field2: 'invalid', | ||
}; | ||
|
||
expect(getRawDataOrDefault(rawData)).toEqual({}); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
...ackages/kbn-elastic-assistant-common/impl/alerts/helpers/get_raw_data_or_default/index.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,13 @@ | ||
/* | ||
* 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 { isRawDataValid } from '../is_raw_data_valid'; | ||
import type { MaybeRawData } from '../types'; | ||
|
||
/** Returns the raw data if it valid, or a default if it's not */ | ||
export const getRawDataOrDefault = (rawData: MaybeRawData): Record<string, unknown[]> => | ||
isRawDataValid(rawData) ? rawData : {}; |
51 changes: 51 additions & 0 deletions
51
...packages/kbn-elastic-assistant-common/impl/alerts/helpers/is_raw_data_valid/index.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,51 @@ | ||
/* | ||
* 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 { isRawDataValid } from '.'; | ||
|
||
describe('isRawDataValid', () => { | ||
it('returns true for valid raw data', () => { | ||
const rawData = { | ||
field1: [1, 2, 3], // the Fields API may return a number array | ||
field2: ['a', 'b', 'c'], // the Fields API may return a string array | ||
}; | ||
|
||
expect(isRawDataValid(rawData)).toBe(true); | ||
}); | ||
|
||
it('returns true when a field array is empty', () => { | ||
const rawData = { | ||
field1: [1, 2, 3], // the Fields API may return a number array | ||
field2: ['a', 'b', 'c'], // the Fields API may return a string array | ||
field3: [], // the Fields API may return an empty array | ||
}; | ||
|
||
expect(isRawDataValid(rawData)).toBe(true); | ||
}); | ||
|
||
it('returns false when a field does not have an array of values', () => { | ||
const rawData = { | ||
field1: [1, 2, 3], | ||
field2: 'invalid', | ||
}; | ||
|
||
expect(isRawDataValid(rawData)).toBe(false); | ||
}); | ||
|
||
it('returns true for empty raw data', () => { | ||
const rawData = {}; | ||
|
||
expect(isRawDataValid(rawData)).toBe(true); | ||
}); | ||
|
||
it('returns false when raw data is an unexpected type', () => { | ||
const rawData = 1234; | ||
|
||
// @ts-expect-error | ||
expect(isRawDataValid(rawData)).toBe(false); | ||
}); | ||
}); |
11 changes: 11 additions & 0 deletions
11
x-pack/packages/kbn-elastic-assistant-common/impl/alerts/helpers/is_raw_data_valid/index.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,11 @@ | ||
/* | ||
* 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 { MaybeRawData } from '../types'; | ||
|
||
export const isRawDataValid = (rawData: MaybeRawData): rawData is Record<string, unknown[]> => | ||
typeof rawData === 'object' && Object.keys(rawData).every((x) => Array.isArray(rawData[x])); |
47 changes: 47 additions & 0 deletions
47
...kages/kbn-elastic-assistant-common/impl/alerts/helpers/size_is_out_of_range/index.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,47 @@ | ||
/* | ||
* 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 { sizeIsOutOfRange } from '.'; | ||
import { MAX_SIZE, MIN_SIZE } from '../types'; | ||
|
||
describe('sizeIsOutOfRange', () => { | ||
it('returns true when size is undefined', () => { | ||
const size = undefined; | ||
|
||
expect(sizeIsOutOfRange(size)).toBe(true); | ||
}); | ||
|
||
it('returns true when size is less than MIN_SIZE', () => { | ||
const size = MIN_SIZE - 1; | ||
|
||
expect(sizeIsOutOfRange(size)).toBe(true); | ||
}); | ||
|
||
it('returns true when size is greater than MAX_SIZE', () => { | ||
const size = MAX_SIZE + 1; | ||
|
||
expect(sizeIsOutOfRange(size)).toBe(true); | ||
}); | ||
|
||
it('returns false when size is exactly MIN_SIZE', () => { | ||
const size = MIN_SIZE; | ||
|
||
expect(sizeIsOutOfRange(size)).toBe(false); | ||
}); | ||
|
||
it('returns false when size is exactly MAX_SIZE', () => { | ||
const size = MAX_SIZE; | ||
|
||
expect(sizeIsOutOfRange(size)).toBe(false); | ||
}); | ||
|
||
it('returns false when size is within the valid range', () => { | ||
const size = MIN_SIZE + 1; | ||
|
||
expect(sizeIsOutOfRange(size)).toBe(false); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
...k/packages/kbn-elastic-assistant-common/impl/alerts/helpers/size_is_out_of_range/index.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,12 @@ | ||
/* | ||
* 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 { MAX_SIZE, MIN_SIZE } from '../types'; | ||
|
||
/** Return true if the provided size is out of range */ | ||
export const sizeIsOutOfRange = (size?: number): boolean => | ||
size == null || size < MIN_SIZE || size > MAX_SIZE; |
14 changes: 14 additions & 0 deletions
14
x-pack/packages/kbn-elastic-assistant-common/impl/alerts/helpers/types.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,14 @@ | ||
/* | ||
* 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 type { SearchResponse } from '@elastic/elasticsearch/lib/api/types'; | ||
|
||
export const MIN_SIZE = 10; | ||
export const MAX_SIZE = 10000; | ||
|
||
/** currently the same shape as "fields" property in the ES response */ | ||
export type MaybeRawData = SearchResponse['fields'] | undefined; |
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
Oops, something went wrong.