-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Security Solution][Detection Engine] adds legacy siem signals telemetry #202671
Merged
vitaliidm
merged 11 commits into
elastic:main
from
vitaliidm:de_8_18/add-telemetry-signals-migration-indices
Dec 11, 2024
+714
−14
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0b7d1d3
[Security Solution][Detection Engine] adds legacy siem signals telemetry
vitaliidm d501ae3
[Security Solution][Detection Engine] remove unused oldest timestamp
vitaliidm 58334d8
[Security Solution][Detection Engine] refactpring
vitaliidm 9915f9b
Update index.ts
vitaliidm 979f5df
Merge branch 'main' into de_8_18/add-telemetry-signals-migration-indices
vitaliidm 074e4e5
Merge branch 'main' into de_8_18/add-telemetry-signals-migration-indices
vitaliidm bfd7b43
Update x-pack/test/security_solution_api_integration/test_suites/dete…
vitaliidm 6fc9e7f
Update delete_alerts_migrations.ts
vitaliidm 3ef4c97
Merge branch 'main' into de_8_18/add-telemetry-signals-migration-indices
vitaliidm 478815b
Merge branch 'main' into de_8_18/add-telemetry-signals-migration-indices
vitaliidm cdd92b6
Merge branch 'main' into de_8_18/add-telemetry-signals-migration-indices
vitaliidm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
88 changes: 88 additions & 0 deletions
88
...ecurity_solution/server/lib/detection_engine/migrations/get_index_alias_per_space.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,88 @@ | ||
/* | ||
* 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 { elasticsearchServiceMock } from '@kbn/core/server/mocks'; | ||
import { getIndexAliasPerSpace } from './get_index_alias_per_space'; | ||
|
||
describe('getIndexAliasPerSpace', () => { | ||
let esClient: ReturnType<typeof elasticsearchServiceMock.createElasticsearchClient>; | ||
|
||
beforeEach(() => { | ||
esClient = elasticsearchServiceMock.createElasticsearchClient(); | ||
}); | ||
|
||
it('returns object with index alias and space', async () => { | ||
esClient.indices.getAlias.mockResponseOnce({ | ||
'.siem-signals-default-old-one': { | ||
aliases: { | ||
'.siem-signals-default': { | ||
is_write_index: false, | ||
}, | ||
}, | ||
}, | ||
'.siem-signals-another-1-legacy': { | ||
aliases: { | ||
'.siem-signals-another-1': { | ||
is_write_index: false, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
const result = await getIndexAliasPerSpace({ | ||
esClient, | ||
signalsIndex: '.siem-signals', | ||
signalsAliasAllSpaces: '.siem-signals-*', | ||
}); | ||
|
||
expect(result).toEqual({ | ||
'.siem-signals-another-1-legacy': { | ||
alias: '.siem-signals-another-1', | ||
indexName: '.siem-signals-another-1-legacy', | ||
space: 'another-1', | ||
}, | ||
'.siem-signals-default-old-one': { | ||
alias: '.siem-signals-default', | ||
indexName: '.siem-signals-default-old-one', | ||
space: 'default', | ||
}, | ||
}); | ||
}); | ||
|
||
it('filters out .internal.alert indices', async () => { | ||
esClient.indices.getAlias.mockResponseOnce({ | ||
'.siem-signals-default-old-one': { | ||
aliases: { | ||
'.siem-signals-default': { | ||
is_write_index: false, | ||
}, | ||
}, | ||
}, | ||
'.internal.alerts-security.alerts-another-2-000001': { | ||
aliases: { | ||
'.siem-signals-another-2': { | ||
is_write_index: false, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
const result = await getIndexAliasPerSpace({ | ||
esClient, | ||
signalsIndex: '.siem-signals', | ||
signalsAliasAllSpaces: '.siem-signals-*', | ||
}); | ||
|
||
expect(result).toEqual({ | ||
'.siem-signals-default-old-one': { | ||
alias: '.siem-signals-default', | ||
indexName: '.siem-signals-default-old-one', | ||
space: 'default', | ||
}, | ||
}); | ||
}); | ||
}); |
52 changes: 52 additions & 0 deletions
52
...ins/security_solution/server/lib/detection_engine/migrations/get_index_alias_per_space.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,52 @@ | ||
/* | ||
* 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 { ElasticsearchClient } from '@kbn/core/server'; | ||
|
||
interface IndexAlias { | ||
alias: string; | ||
space: string; | ||
indexName: string; | ||
} | ||
|
||
/** | ||
* Retrieves index, its alias and Kibana space | ||
*/ | ||
export const getIndexAliasPerSpace = async ({ | ||
esClient, | ||
signalsIndex, | ||
signalsAliasAllSpaces, | ||
}: { | ||
esClient: ElasticsearchClient; | ||
signalsIndex: string; | ||
signalsAliasAllSpaces: string; | ||
}): Promise<Record<string, IndexAlias>> => { | ||
const response = await esClient.indices.getAlias( | ||
{ | ||
name: signalsAliasAllSpaces, | ||
}, | ||
{ meta: true } | ||
); | ||
|
||
const indexAliasesMap = Object.keys(response.body).reduce<Record<string, IndexAlias>>( | ||
(acc, indexName) => { | ||
if (!indexName.startsWith('.internal.alerts-')) { | ||
const alias = Object.keys(response.body[indexName].aliases)[0]; | ||
|
||
acc[indexName] = { | ||
alias, | ||
space: alias.replace(`${signalsIndex}-`, ''), | ||
indexName, | ||
}; | ||
} | ||
|
||
return acc; | ||
}, | ||
{} | ||
); | ||
|
||
return indexAliasesMap; | ||
}; |
59 changes: 59 additions & 0 deletions
59
...solution/server/lib/detection_engine/migrations/get_latest_index_template_version.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,59 @@ | ||
/* | ||
* 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 { IndicesGetIndexTemplateResponse } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; | ||
import { elasticsearchServiceMock } from '@kbn/core/server/mocks'; | ||
import { getLatestIndexTemplateVersion } from './get_latest_index_template_version'; | ||
|
||
describe('getIndexAliasPerSpace', () => { | ||
let esClient: ReturnType<typeof elasticsearchServiceMock.createElasticsearchClient>; | ||
|
||
beforeEach(() => { | ||
esClient = elasticsearchServiceMock.createElasticsearchClient(); | ||
}); | ||
|
||
it('returns latest index template version', async () => { | ||
esClient.indices.getIndexTemplate.mockResponseOnce({ | ||
index_templates: [ | ||
{ index_template: { version: 77 } }, | ||
{ index_template: { version: 10 } }, | ||
{ index_template: { version: 23 } }, | ||
{ index_template: { version: 0 } }, | ||
], | ||
} as IndicesGetIndexTemplateResponse); | ||
|
||
const version = await getLatestIndexTemplateVersion({ | ||
esClient, | ||
name: '.siem-signals-*', | ||
}); | ||
|
||
expect(version).toBe(77); | ||
}); | ||
|
||
it('returns 0 if templates empty', async () => { | ||
esClient.indices.getIndexTemplate.mockResponseOnce({ | ||
index_templates: [], | ||
}); | ||
|
||
const version = await getLatestIndexTemplateVersion({ | ||
esClient, | ||
name: '.siem-signals-*', | ||
}); | ||
|
||
expect(version).toBe(0); | ||
}); | ||
|
||
it('returns 0 if request fails', async () => { | ||
esClient.indices.getIndexTemplate.mockRejectedValueOnce('Failure'); | ||
|
||
const version = await getLatestIndexTemplateVersion({ | ||
esClient, | ||
name: '.siem-signals-*', | ||
}); | ||
|
||
expect(version).toBe(0); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
...rity_solution/server/lib/detection_engine/migrations/get_latest_index_template_version.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,34 @@ | ||
/* | ||
* 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 { ElasticsearchClient } from '@kbn/core/server'; | ||
|
||
/** | ||
* Retrieves the latest version of index template | ||
* There are can be multiple index templates across different Kibana spaces, | ||
* so we get them all and return the latest(greatest) number | ||
*/ | ||
export const getLatestIndexTemplateVersion = async ({ | ||
esClient, | ||
name, | ||
}: { | ||
esClient: ElasticsearchClient; | ||
name: string; | ||
}): Promise<number> => { | ||
let latestTemplateVersion: number; | ||
try { | ||
const response = await esClient.indices.getIndexTemplate({ name }); | ||
const versions = response.index_templates.map( | ||
(template) => template.index_template.version ?? 0 | ||
); | ||
|
||
latestTemplateVersion = versions.length ? Math.max(...versions) : 0; | ||
} catch (e) { | ||
latestTemplateVersion = 0; | ||
} | ||
|
||
return latestTemplateVersion; | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again for tracking this one down 👍