-
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.
[8.x] [Telemetry][Security Solution] Index metadata collector (#194004)…
… (#204311) # Backport This will backport the following commits from `main` to `8.x`: - [[Telemetry][Security Solution] Index metadata collector (#194004)](#194004) <!--- Backport version: 8.9.8 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Sebastián Zaffarano","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-13T18:31:03Z","message":"[Telemetry][Security Solution] Index metadata collector (#194004)\n\n## Summary\r\n\r\nImplements a security_solution task scheduled to run once a day to\r\ncollect the following information:\r\n\r\n1. Datastreams stats\r\n2. Indices stats\r\n3. ILMs stats\r\n4. ILM configs\r\n\r\nThe task allows a runtime configuration to limit the number of indices\r\nand data streams to analyze or event to disable the feature entirely.\r\n\r\nOnce the data is gathered, the task sends it as EBT events.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>\r\nCo-authored-by: Elastic Machine <[email protected]>","sha":"36b344a4c58a3d78a892288e0eef71e9ff163b9d","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team: SecuritySolution","backport:all-open","ci:cloud-deploy"],"number":194004,"url":"https://github.com/elastic/kibana/pull/194004","mergeCommit":{"message":"[Telemetry][Security Solution] Index metadata collector (#194004)\n\n## Summary\r\n\r\nImplements a security_solution task scheduled to run once a day to\r\ncollect the following information:\r\n\r\n1. Datastreams stats\r\n2. Indices stats\r\n3. ILMs stats\r\n4. ILM configs\r\n\r\nThe task allows a runtime configuration to limit the number of indices\r\nand data streams to analyze or event to disable the feature entirely.\r\n\r\nOnce the data is gathered, the task sends it as EBT events.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>\r\nCo-authored-by: Elastic Machine <[email protected]>","sha":"36b344a4c58a3d78a892288e0eef71e9ff163b9d"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/194004","number":194004,"mergeCommit":{"message":"[Telemetry][Security Solution] Index metadata collector (#194004)\n\n## Summary\r\n\r\nImplements a security_solution task scheduled to run once a day to\r\ncollect the following information:\r\n\r\n1. Datastreams stats\r\n2. Indices stats\r\n3. ILMs stats\r\n4. ILM configs\r\n\r\nThe task allows a runtime configuration to limit the number of indices\r\nand data streams to analyze or event to disable the feature entirely.\r\n\r\nOnce the data is gathered, the task sends it as EBT events.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>\r\nCo-authored-by: Elastic Machine <[email protected]>","sha":"36b344a4c58a3d78a892288e0eef71e9ff163b9d"}}]}] BACKPORT--> Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
d3fcf47
commit 7a3de72
Showing
43 changed files
with
3,100 additions
and
136 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
152 changes: 152 additions & 0 deletions
152
x-pack/plugins/security_solution/server/integration_tests/configuration.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,152 @@ | ||
/* | ||
* 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 Path from 'path'; | ||
import axios from 'axios'; | ||
|
||
import { cloneDeep } from 'lodash'; | ||
|
||
import { telemetryConfiguration } from '../lib/telemetry/configuration'; | ||
import { | ||
TaskManagerPlugin, | ||
type TaskManagerStartContract, | ||
} from '@kbn/task-manager-plugin/server/plugin'; | ||
|
||
import { | ||
setupTestServers, | ||
removeFile, | ||
mockAxiosPost, | ||
DEFAULT_GET_ROUTES, | ||
mockAxiosGet, | ||
getRandomInt, | ||
} from './lib/helpers'; | ||
|
||
import { | ||
type TestElasticsearchUtils, | ||
type TestKibanaUtils, | ||
} from '@kbn/core-test-helpers-kbn-server'; | ||
import { Plugin as SecuritySolutionPlugin } from '../plugin'; | ||
import { getTelemetryTasks, runSoonConfigTask } from './lib/telemetry_helpers'; | ||
import type { SecurityTelemetryTask } from '../lib/telemetry/task'; | ||
|
||
jest.mock('axios'); | ||
|
||
const logFilePath = Path.join(__dirname, 'config.logs.log'); | ||
const taskManagerStartSpy = jest.spyOn(TaskManagerPlugin.prototype, 'start'); | ||
const securitySolutionStartSpy = jest.spyOn(SecuritySolutionPlugin.prototype, 'start'); | ||
|
||
const mockedAxiosGet = jest.spyOn(axios, 'get'); | ||
const mockedAxiosPost = jest.spyOn(axios, 'post'); | ||
|
||
const securitySolutionPlugin = jest.spyOn(SecuritySolutionPlugin.prototype, 'start'); | ||
|
||
describe('configuration', () => { | ||
let esServer: TestElasticsearchUtils; | ||
let kibanaServer: TestKibanaUtils; | ||
let taskManagerPlugin: TaskManagerStartContract; | ||
let tasks: SecurityTelemetryTask[]; | ||
|
||
beforeAll(async () => { | ||
await removeFile(logFilePath); | ||
|
||
const servers = await setupTestServers(logFilePath); | ||
|
||
esServer = servers.esServer; | ||
kibanaServer = servers.kibanaServer; | ||
|
||
expect(taskManagerStartSpy).toHaveBeenCalledTimes(1); | ||
taskManagerPlugin = taskManagerStartSpy.mock.results[0].value; | ||
|
||
expect(securitySolutionStartSpy).toHaveBeenCalledTimes(1); | ||
|
||
tasks = getTelemetryTasks(securitySolutionStartSpy); | ||
|
||
expect(securitySolutionPlugin).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
afterAll(async () => { | ||
if (kibanaServer) { | ||
await kibanaServer.stop(); | ||
} | ||
if (esServer) { | ||
await esServer.stop(); | ||
} | ||
}); | ||
|
||
beforeEach(async () => { | ||
jest.clearAllMocks(); | ||
mockAxiosPost(mockedAxiosPost); | ||
}); | ||
|
||
afterEach(async () => {}); | ||
|
||
describe('configuration task', () => { | ||
it('should keep default values when no new config was provided', async () => { | ||
const before = cloneDeep(telemetryConfiguration); | ||
|
||
await runSoonConfigTask(tasks, taskManagerPlugin); | ||
|
||
expect(telemetryConfiguration).toEqual(before); | ||
}); | ||
|
||
it('should update values with new manifest', async () => { | ||
const expected = { | ||
telemetry_max_buffer_size: getRandomInt(1, 100), | ||
max_security_list_telemetry_batch: getRandomInt(1, 100), | ||
max_endpoint_telemetry_batch: getRandomInt(1, 100), | ||
max_detection_rule_telemetry_batch: getRandomInt(1, 100), | ||
max_detection_alerts_batch: getRandomInt(1, 100), | ||
use_async_sender: true, | ||
pagination_config: { | ||
max_page_size_bytes: getRandomInt(1, 100), | ||
num_docs_to_sample: getRandomInt(1, 100), | ||
}, | ||
sender_channels: { | ||
default: { | ||
buffer_time_span_millis: getRandomInt(1, 100), | ||
inflight_events_threshold: getRandomInt(1, 100), | ||
max_payload_size_bytes: getRandomInt(1, 100), | ||
}, | ||
}, | ||
indices_metadata_config: { | ||
indices_threshold: getRandomInt(1, 100), | ||
datastreams_threshold: getRandomInt(1, 100), | ||
max_prefixes: getRandomInt(1, 100), | ||
max_group_size: getRandomInt(1, 100), | ||
}, | ||
}; | ||
|
||
mockAxiosGet(mockedAxiosGet, [ | ||
...DEFAULT_GET_ROUTES, | ||
[/.*telemetry-buffer-and-batch-sizes-v1.*/, { status: 200, data: cloneDeep(expected) }], | ||
]); | ||
|
||
await runSoonConfigTask(tasks, taskManagerPlugin); | ||
|
||
expect(telemetryConfiguration.telemetry_max_buffer_size).toEqual( | ||
expected.telemetry_max_buffer_size | ||
); | ||
expect(telemetryConfiguration.max_security_list_telemetry_batch).toEqual( | ||
expected.max_security_list_telemetry_batch | ||
); | ||
expect(telemetryConfiguration.max_endpoint_telemetry_batch).toEqual( | ||
expected.max_endpoint_telemetry_batch | ||
); | ||
expect(telemetryConfiguration.max_detection_rule_telemetry_batch).toEqual( | ||
expected.max_detection_rule_telemetry_batch | ||
); | ||
expect(telemetryConfiguration.max_detection_alerts_batch).toEqual( | ||
expected.max_detection_alerts_batch | ||
); | ||
expect(telemetryConfiguration.use_async_sender).toEqual(expected.use_async_sender); | ||
expect(telemetryConfiguration.sender_channels).toEqual(expected.sender_channels); | ||
expect(telemetryConfiguration.pagination_config).toEqual(expected.pagination_config); | ||
expect(telemetryConfiguration.indices_metadata_config).toEqual( | ||
expected.indices_metadata_config | ||
); | ||
}); | ||
}); | ||
}); |
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.