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; }