Skip to content

Commit c37592f

Browse files
[8.18] Unflatten doc before applying filterlist (#235988) (#236007)
# Backport This will backport the following commits from `main` to `8.18`: - [Unflatten doc before applying filterlist (#235988)](#235988) <!--- 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":"[email protected]"},"sourceCommit":{"committedDate":"2025-09-22T21:01:28Z","message":"Unflatten doc before applying filterlist (#235988)\n\n## Summary\n\nDue that some documents have dots in the fieldnames, e.g.,\n`kibana.alert.original_event.kind` is a single field and not `{\"kibana\":\n{ \"alert\": ... } }`, we need to unflatten those fields before applying\nthe filterlist.\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- [ ] Review the [backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand apply applicable `backport:*` labels.","sha":"7200a319006788333f60036756d171535a41ec07","branchLabelMapping":{"^v9.2.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:all-open","v9.2.0"],"title":"Unflatten doc before applying filterlist","number":235988,"url":"https://github.com/elastic/kibana/pull/235988","mergeCommit":{"message":"Unflatten doc before applying filterlist (#235988)\n\n## Summary\n\nDue that some documents have dots in the fieldnames, e.g.,\n`kibana.alert.original_event.kind` is a single field and not `{\"kibana\":\n{ \"alert\": ... } }`, we need to unflatten those fields before applying\nthe filterlist.\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- [ ] Review the [backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand apply applicable `backport:*` labels.","sha":"7200a319006788333f60036756d171535a41ec07"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.2.0","branchLabelMappingKey":"^v9.2.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/235988","number":235988,"mergeCommit":{"message":"Unflatten doc before applying filterlist (#235988)\n\n## Summary\n\nDue that some documents have dots in the fieldnames, e.g.,\n`kibana.alert.original_event.kind` is a single field and not `{\"kibana\":\n{ \"alert\": ... } }`, we need to unflatten those fields before applying\nthe filterlist.\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- [ ] Review the [backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand apply applicable `backport:*` labels.","sha":"7200a319006788333f60036756d171535a41ec07"}}]}] BACKPORT--> Co-authored-by: Sebastián Zaffarano <[email protected]>
1 parent c7bb31e commit c37592f

File tree

2 files changed

+18
-50
lines changed

2 files changed

+18
-50
lines changed

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

Lines changed: 14 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ describe('Security Solution - Health Diagnostic Queries - utils', () => {
2727
});
2828
});
2929

30+
test('should keep fields marked with KEEP action in flat doc', async () => {
31+
const data = [{ 'kibana.alert.rule.name': 'Endpoint Security (Elastic Defend)' }];
32+
const rules = {
33+
'user.name': Action.KEEP,
34+
'kibana.alert.rule.name': Action.KEEP,
35+
};
36+
37+
const result = await applyFilterlist(data, rules, mockSalt);
38+
39+
expect(result).toEqual([
40+
{ kibana: { alert: { rule: { name: 'Endpoint Security (Elastic Defend)' } } } },
41+
]);
42+
});
43+
3044
test('should keep fields marked with KEEP action', async () => {
3145
const data = [{ user: { name: 'john', email: '[email protected]' } }];
3246
const rules = {
@@ -98,31 +112,6 @@ describe('Security Solution - Health Diagnostic Queries - utils', () => {
98112
expect((result[0] as any).meta.host.ip).not.toBe('192.168.1.1');
99113
});
100114

101-
test('should handle arrays of documents', async () => {
102-
const data = [
103-
[
104-
{ user: 'alice', token: 'abc123' },
105-
{ user: 'bob', token: 'xyz789' },
106-
],
107-
];
108-
const rules = {
109-
user: Action.KEEP,
110-
token: Action.MASK,
111-
};
112-
113-
const result = await applyFilterlist(data, rules, mockSalt);
114-
115-
expect(result).toHaveLength(1);
116-
expect(Array.isArray(result[0])).toBe(true);
117-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
118-
const docs = result[0] as any[];
119-
expect(docs).toHaveLength(2);
120-
expect(docs[0].user).toBe('alice');
121-
expect(docs[1].user).toBe('bob');
122-
expect(docs[0].token).not.toBe('abc123');
123-
expect(docs[1].token).not.toBe('xyz789');
124-
});
125-
126115
test('should handle arrays of complex documents', async () => {
127116
const data = [
128117
{
@@ -301,30 +290,6 @@ describe('Security Solution - Health Diagnostic Queries - utils', () => {
301290
]);
302291
});
303292

304-
test('should handle mixed document types', async () => {
305-
const data = [
306-
{ type: 'user', name: 'john', password: 'secret' },
307-
[{ type: 'admin', name: 'admin', token: 'admin123' }],
308-
];
309-
const rules = {
310-
name: Action.KEEP,
311-
password: Action.MASK,
312-
token: Action.MASK,
313-
};
314-
315-
const result = await applyFilterlist(data, rules, mockSalt);
316-
317-
expect(result).toHaveLength(2);
318-
expect(result[0]).toMatchObject({ name: 'john' });
319-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
320-
expect((result[0] as any).password).not.toBe('secret');
321-
expect(Array.isArray(result[1])).toBe(true);
322-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
323-
const adminDocs = result[1] as any[];
324-
expect(adminDocs[0].name).toBe('admin');
325-
expect(adminDocs[0].token).not.toBe('admin123');
326-
});
327-
328293
test('should handle numeric and boolean values', async () => {
329294
const data = [
330295
{

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {
1313
type HealthDiagnosticQuery,
1414
type HealthDiagnosticQueryStats,
1515
} from './health_diagnostic_service.types';
16+
import { unflatten } from '../helpers';
17+
import type { AnyObject } from '../types';
1618

1719
export function shouldExecute(startDate: Date, endDate: Date, interval: Interval): boolean {
1820
const nextDate = intervalFromDate(startDate, interval);
@@ -131,7 +133,8 @@ export async function applyFilterlist(
131133
}
132134
};
133135

134-
for (const doc of data) {
136+
for (const rawDoc of data) {
137+
const doc = unflatten(rawDoc as AnyObject);
135138
if (Array.isArray(doc)) {
136139
const docs = doc as unknown[];
137140
const result = await Promise.all(

0 commit comments

Comments
 (0)