Skip to content

Commit e144237

Browse files
kibanamachineszaffaranoelasticmachine
authored
[9.0] [Security Solution] Send EBT when diagnostic query is empty (#238040) (#238080)
# Backport This will backport the following commits from `main` to `9.0`: - [[Security Solution] Send EBT when diagnostic query is empty (#238040)](#238040) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Sebastián Zaffarano","email":"sebastian.zaffarano@elastic.co"},"sourceCommit":{"committedDate":"2025-10-08T15:06:58Z","message":"[Security Solution] Send EBT when diagnostic query is empty (#238040)\n\n## Summary\n\nSend an EBT document even when the diagnostic query does not return\nresults. It ensures that EBT documents are consistent with statistics\nand data; otherwise, we end up with statistics documents without their\ncorresponding data documents.\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n\n- [ ] Any text added follows [EUI's writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\nsentence case text and includes [i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n- [ ]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas added for features that require explanation or tutorials\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n- [ ] If a plugin configuration key changed, check if it needs to be\nallowlisted in the cloud and added to the [docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n- [ ] This was checked for breaking HTTP API changes, and any breaking\nchanges have been approved by the breaking-change committee. The\n`release_note:breaking` label should be applied in these situations.\n- [ ] [Flaky Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\nused on any tests changed\n- [ ] The PR description includes the appropriate Release Notes section,\nand the correct `release_note:*` label is applied per the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n- [x] Review the [backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand apply applicable `backport:*` labels.","sha":"b78fa1f32afd8f57e26289585337d8b4fad5172a","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team: SecuritySolution","backport:version","v9.2.0","v9.3.0","v9.1.6","v8.19.6","v9.0.9"],"title":"[Security Solution] Send EBT when diagnostic query is empty","number":238040,"url":"https://github.com/elastic/kibana/pull/238040","mergeCommit":{"message":"[Security Solution] Send EBT when diagnostic query is empty (#238040)\n\n## Summary\n\nSend an EBT document even when the diagnostic query does not return\nresults. It ensures that EBT documents are consistent with statistics\nand data; otherwise, we end up with statistics documents without their\ncorresponding data documents.\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n\n- [ ] Any text added follows [EUI's writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\nsentence case text and includes [i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n- [ ]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas added for features that require explanation or tutorials\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n- [ ] If a plugin configuration key changed, check if it needs to be\nallowlisted in the cloud and added to the [docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n- [ ] This was checked for breaking HTTP API changes, and any breaking\nchanges have been approved by the breaking-change committee. The\n`release_note:breaking` label should be applied in these situations.\n- [ ] [Flaky Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\nused on any tests changed\n- [ ] The PR description includes the appropriate Release Notes section,\nand the correct `release_note:*` label is applied per the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n- [x] Review the [backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand apply applicable `backport:*` labels.","sha":"b78fa1f32afd8f57e26289585337d8b4fad5172a"}},"sourceBranch":"main","suggestedTargetBranches":["9.2","9.1","8.19","9.0"],"targetPullRequestStates":[{"branch":"9.2","label":"v9.2.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/238040","number":238040,"mergeCommit":{"message":"[Security Solution] Send EBT when diagnostic query is empty (#238040)\n\n## Summary\n\nSend an EBT document even when the diagnostic query does not return\nresults. It ensures that EBT documents are consistent with statistics\nand data; otherwise, we end up with statistics documents without their\ncorresponding data documents.\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n\n- [ ] Any text added follows [EUI's writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\nsentence case text and includes [i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n- [ ]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas added for features that require explanation or tutorials\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n- [ ] If a plugin configuration key changed, check if it needs to be\nallowlisted in the cloud and added to the [docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n- [ ] This was checked for breaking HTTP API changes, and any breaking\nchanges have been approved by the breaking-change committee. The\n`release_note:breaking` label should be applied in these situations.\n- [ ] [Flaky Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\nused on any tests changed\n- [ ] The PR description includes the appropriate Release Notes section,\nand the correct `release_note:*` label is applied per the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n- [x] Review the [backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand apply applicable `backport:*` labels.","sha":"b78fa1f32afd8f57e26289585337d8b4fad5172a"}},{"branch":"9.1","label":"v9.1.6","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.19","label":"v8.19.6","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.0","label":"v9.0.9","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Sebastián Zaffarano <sebastian.zaffarano@elastic.co> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent 0ad6484 commit e144237

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

x-pack/solutions/security/plugins/security_solution/server/lib/telemetry/diagnostic/health_diagnostic_service.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,43 @@ describe('Security Solution - Health Diagnostic Queries - HealthDiagnosticServic
266266
expect(result[0].passed).toBe(true);
267267
expect(mockLogger.warn).toHaveBeenCalledWith('Error sending EBT', expect.any(Object));
268268
});
269+
270+
test('should send EBT events even when query returns no results', async () => {
271+
const lastExecutionByQuery = { 'test-query': 1640995200000 };
272+
mockQueryExecutor.search.mockReturnValue(from([]));
273+
274+
const result = await service.runHealthDiagnosticQueries(lastExecutionByQuery);
275+
276+
expect(result).toHaveLength(1);
277+
expect(result[0]).toMatchObject({
278+
name: 'test-query',
279+
passed: true,
280+
numDocs: 0,
281+
});
282+
283+
expect(mockAnalytics.reportEvent).toHaveBeenCalledTimes(2);
284+
285+
expect(mockAnalytics.reportEvent).toHaveBeenCalledWith(
286+
'telemetry_health_diagnostic_query_result_event',
287+
expect.objectContaining({
288+
name: 'test-query',
289+
queryId: 'test-query-1',
290+
page: 0,
291+
data: [],
292+
traceId: expect.any(String),
293+
})
294+
);
295+
296+
expect(mockAnalytics.reportEvent).toHaveBeenCalledWith(
297+
'telemetry_health_diagnostic_query_stats_event',
298+
expect.objectContaining({
299+
name: 'test-query',
300+
passed: true,
301+
numDocs: 0,
302+
traceId: expect.any(String),
303+
})
304+
);
305+
});
269306
});
270307
});
271308
});

x-pack/solutions/security/plugins/security_solution/server/lib/telemetry/diagnostic/health_diagnostic_service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import { schema } from '@kbn/config-schema';
9-
import { bufferCount, from, mergeMap, take, tap } from 'rxjs';
9+
import { bufferCount, defaultIfEmpty, from, mergeMap, take, tap } from 'rxjs';
1010
import { cloneDeep } from 'lodash';
1111
import type {
1212
TaskManagerSetupContract,
@@ -127,6 +127,9 @@ export class HealthDiagnosticServiceImpl implements HealthDiagnosticService {
127127
// publish N documents in the same EBT
128128
bufferCount(telemetryConfiguration.health_diagnostic_config.query.bufferSize),
129129

130+
// emit empty array if no items were buffered (ensures EBT is always sent)
131+
defaultIfEmpty([]),
132+
130133
// apply filterlist
131134
mergeMap((result) => from(applyFilterlist(result, query.filterlist, this.salt)))
132135
)

0 commit comments

Comments
 (0)