Skip to content

Commit 5642748

Browse files
kibanamachinermyz
andauthored
[8.18] [ObsUX][Infra] Filter out null values from sourceDataStreams (#218772) (#218798)
# Backport This will backport the following commits from `main` to `8.18`: - [[ObsUX][Infra] Filter out null values from `sourceDataStreams` (#218772)](#218772) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Sergi Romeu","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-04-22T10:37:09Z","message":"[ObsUX][Infra] Filter out null values from `sourceDataStreams` (#218772)\n\n## Summary\n\nPart of #213045\n\nThis PR fixes an issue when the `observability:entityCentricExperience`\nflag is enabled.\nBy some reason, we may get null values in `sourceDataStreams` and when\nwe try to validate it with the zod schema, it breaks.","sha":"2dea36a0a63d4cd594e556eb4cfd346cb11f30a3","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:obs-ux-infra_services","backport:version","v9.1.0","v8.19.0","v8.18.1","v9.0.1"],"title":"[ObsUX][Infra] Filter out null values from `sourceDataStreams`","number":218772,"url":"https://github.com/elastic/kibana/pull/218772","mergeCommit":{"message":"[ObsUX][Infra] Filter out null values from `sourceDataStreams` (#218772)\n\n## Summary\n\nPart of #213045\n\nThis PR fixes an issue when the `observability:entityCentricExperience`\nflag is enabled.\nBy some reason, we may get null values in `sourceDataStreams` and when\nwe try to validate it with the zod schema, it breaks.","sha":"2dea36a0a63d4cd594e556eb4cfd346cb11f30a3"}},"sourceBranch":"main","suggestedTargetBranches":["8.19","8.18","9.0"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/218772","number":218772,"mergeCommit":{"message":"[ObsUX][Infra] Filter out null values from `sourceDataStreams` (#218772)\n\n## Summary\n\nPart of #213045\n\nThis PR fixes an issue when the `observability:entityCentricExperience`\nflag is enabled.\nBy some reason, we may get null values in `sourceDataStreams` and when\nwe try to validate it with the zod schema, it breaks.","sha":"2dea36a0a63d4cd594e556eb4cfd346cb11f30a3"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.0","label":"v9.0.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Sergi Romeu <[email protected]>
1 parent e020de9 commit 5642748

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

x-pack/solutions/observability/plugins/infra/server/routes/entities/get_data_stream_types.test.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ describe('getDataStreamTypes', () => {
136136
it('should return entity source_data_stream types when has no metrics', async () => {
137137
(getHasMetricsData as jest.Mock).mockResolvedValue(false);
138138
(getLatestEntity as jest.Mock).mockResolvedValue({
139-
sourceDataStreamType: ['logs', 'traces'],
139+
sourceDataStreamType: ['logs'],
140140
});
141141

142142
const params = {
@@ -153,6 +153,29 @@ describe('getDataStreamTypes', () => {
153153
};
154154

155155
const result = await getDataStreamTypes(params);
156-
expect(result).toEqual(['logs', 'traces']);
156+
expect(result).toEqual(['logs']);
157+
});
158+
159+
it('should ignore null values returned from latestEntity', async () => {
160+
(getHasMetricsData as jest.Mock).mockResolvedValue(false);
161+
(getLatestEntity as jest.Mock).mockResolvedValue({
162+
sourceDataStreamType: ['logs', null, 'metrics', null],
163+
});
164+
165+
const params = {
166+
entityId: 'entity123',
167+
entityType: 'built_in_hosts_from_ecs_data',
168+
entityFilterType: 'host',
169+
entityCentricExperienceEnabled: true,
170+
infraMetricsClient,
171+
obsEsClient,
172+
entityManagerClient,
173+
logger,
174+
from: '2024-12-09T10:49:15Z',
175+
to: '2024-12-10T10:49:15Z',
176+
};
177+
178+
const result = await getDataStreamTypes(params);
179+
expect(result).toEqual(['logs', 'metrics']);
157180
});
158181
});

x-pack/solutions/observability/plugins/infra/server/routes/entities/get_data_stream_types.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@ export async function getDataStreamTypes({
6363

6464
if (latestEntity) {
6565
castArray(latestEntity.sourceDataStreamType).forEach((item) => {
66-
sourceDataStreams.add(item as EntityDataStreamType);
66+
if (
67+
[EntityDataStreamType.LOGS, EntityDataStreamType.METRICS].includes(
68+
item as EntityDataStreamType
69+
)
70+
) {
71+
sourceDataStreams.add(item as EntityDataStreamType);
72+
}
6773
});
6874
}
6975

0 commit comments

Comments
 (0)