From 55144fa3cbcf56d247d538ffe729414b40f26f90 Mon Sep 17 00:00:00 2001 From: Julia Bardi <90178898+juliaElastic@users.noreply.github.com> Date: Tue, 26 Mar 2024 11:34:30 +0100 Subject: [PATCH] [8.13][Fleet] Backport output health fix (using output id instead of "default" for non-elasticsearch outputs) (#179406) ## Summary Backport https://github.com/elastic/kibana/pull/178857 and https://github.com/elastic/kibana/pull/179218 to 8.13 Closes https://github.com/elastic/kibana/issues/177927 --- .../agent_policies/full_agent_policy.test.ts | 26 +++++++++++++++++++ .../agent_policies/full_agent_policy.ts | 11 +++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/fleet/server/services/agent_policies/full_agent_policy.test.ts b/x-pack/plugins/fleet/server/services/agent_policies/full_agent_policy.test.ts index a5cba9f9cab3e2..0ecd385c2516cb 100644 --- a/x-pack/plugins/fleet/server/services/agent_policies/full_agent_policy.test.ts +++ b/x-pack/plugins/fleet/server/services/agent_policies/full_agent_policy.test.ts @@ -93,6 +93,15 @@ jest.mock('../output', () => { type: 'elasticsearch', hosts: ['http://127.0.0.1:9201'], }, + 'test-remote-id': { + id: 'test-remote-id', + is_default: true, + is_default_monitoring: true, + name: 'default', + // @ts-ignore + type: 'remote_elasticsearch', + hosts: ['http://127.0.0.1:9201'], + }, }; return { outputService: { @@ -375,6 +384,23 @@ describe('getFullAgentPolicy', () => { expect(agentPolicy?.outputs.default).toBeDefined(); }); + it('should use output id as the default policy id when remote elasticsearch', async () => { + mockAgentPolicy({ + id: 'policy', + status: 'active', + package_policies: [], + is_managed: false, + namespace: 'default', + revision: 1, + data_output_id: 'test-remote-id', + monitoring_output_id: 'test-remote-id', + }); + + const agentPolicy = await getFullAgentPolicy(savedObjectsClientMock.create(), 'agent-policy'); + + expect(agentPolicy?.outputs['test-remote-id']).toBeDefined(); + }); + it('should return the sourceURI from the agent policy', async () => { mockAgentPolicy({ namespace: 'default', diff --git a/x-pack/plugins/fleet/server/services/agent_policies/full_agent_policy.ts b/x-pack/plugins/fleet/server/services/agent_policies/full_agent_policy.ts index 293090e9813fc1..ab277a97774d07 100644 --- a/x-pack/plugins/fleet/server/services/agent_policies/full_agent_policy.ts +++ b/x-pack/plugins/fleet/server/services/agent_policies/full_agent_policy.ts @@ -31,8 +31,12 @@ import type { PackageInfo, } from '../../../common/types'; import { agentPolicyService } from '../agent_policy'; -import { dataTypes, kafkaCompressionType, outputType } from '../../../common/constants'; -import { DEFAULT_OUTPUT } from '../../constants'; +import { + dataTypes, + DEFAULT_OUTPUT, + kafkaCompressionType, + outputType, +} from '../../../common/constants'; import { getPackageInfo } from '../epm/packages'; import { pkgToPkgKey, splitPkgKey } from '../epm/registry'; @@ -494,10 +498,9 @@ export function transformOutputToFullPolicyOutput( * we use "default" for the default policy to avoid breaking changes */ function getOutputIdForAgentPolicy(output: Output) { - if (output.is_default) { + if (output.is_default && output.type === outputType.Elasticsearch) { return DEFAULT_OUTPUT.name; } - return output.id; }