From efa5a6a6f9fecb7e618f3388b279e316ab49e277 Mon Sep 17 00:00:00 2001 From: Julia Bardi Date: Thu, 14 Dec 2023 09:31:20 +0100 Subject: [PATCH 1/3] removed restriction to use remote es as integration data --- .../hooks.test.tsx | 5 ++- .../agent_policy_advanced_fields/hooks.tsx | 42 +++++++++---------- .../components/edit_output_flyout/index.tsx | 1 - .../fleet/server/services/output.test.ts | 16 +++---- .../plugins/fleet/server/services/output.ts | 15 ------- 5 files changed, 29 insertions(+), 50 deletions(-) diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/hooks.test.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/hooks.test.tsx index e027317bf621aa..8c2983ee9fd83a 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/hooks.test.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/hooks.test.tsx @@ -533,7 +533,7 @@ describe('useOutputOptions', () => { `); }); - it('should only enable remote es output for monitoring output', async () => { + it('should enable remote es output for data and monitoring output', async () => { const testRenderer = createFleetTestRendererMock(); mockedUseLicence.mockReturnValue({ hasAtLeast: () => true, @@ -545,7 +545,8 @@ describe('useOutputOptions', () => { expect(result.current.isLoading).toBeTruthy(); await waitForNextUpdate(); - expect(result.current.dataOutputOptions.length).toEqual(1); + expect(result.current.dataOutputOptions.length).toEqual(2); + expect(result.current.dataOutputOptions[1].value).toEqual('remote1'); expect(result.current.monitoringOutputOptions.length).toEqual(2); expect(result.current.monitoringOutputOptions[1].value).toEqual('remote1'); }); diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/hooks.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/hooks.tsx index 9ee8b1f2257353..15681ea1dfbb66 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/hooks.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/hooks.tsx @@ -16,7 +16,7 @@ import { useGetDownloadSources, useGetFleetServerHosts, } from '../../../../hooks'; -import { LICENCE_FOR_PER_POLICY_OUTPUT, outputType } from '../../../../../../../common/constants'; +import { LICENCE_FOR_PER_POLICY_OUTPUT } from '../../../../../../../common/constants'; import { getAllowedOutputTypeForPolicy, policyHasFleetServer, @@ -99,28 +99,26 @@ export function useOutputOptions(agentPolicy: Partial item.type !== outputType.RemoteElasticsearch) - .map((item) => { - const isOutputTypeUnsupported = !allowedOutputTypes.includes(item.type); + ...outputsRequest.data.items.map((item) => { + const isOutputTypeUnsupported = !allowedOutputTypes.includes(item.type); - return { - value: item.id, - inputDisplay: getOutputLabel( - item.name, - isOutputTypeUnsupported ? ( - - ) : undefined - ), - disabled: !isPolicyPerOutputAllowed || isOutputTypeUnsupported, - }; - }), + return { + value: item.id, + inputDisplay: getOutputLabel( + item.name, + isOutputTypeUnsupported ? ( + + ) : undefined + ), + disabled: !isPolicyPerOutputAllowed || isOutputTypeUnsupported, + }; + }), ]; }, [outputsRequest, isPolicyPerOutputAllowed, allowedOutputTypes]); diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/settings/components/edit_output_flyout/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/settings/components/edit_output_flyout/index.tsx index 511af850cab46d..daebac615d6eb5 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/settings/components/edit_output_flyout/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/settings/components/edit_output_flyout/index.tsx @@ -542,7 +542,6 @@ export const EditOutputFlyout: React.FunctionComponent = }} /> } - disabled={isRemoteESOutput} /> diff --git a/x-pack/plugins/fleet/server/services/output.test.ts b/x-pack/plugins/fleet/server/services/output.test.ts index c17cf9d3af210f..8c2fee196d8d81 100644 --- a/x-pack/plugins/fleet/server/services/output.test.ts +++ b/x-pack/plugins/fleet/server/services/output.test.ts @@ -705,12 +705,12 @@ describe('Output Service', () => { ); }); - it('should throw when a remote es output is attempted to be created as default data output', async () => { + it('should not throw when a remote es output is attempted to be created as default data output', async () => { const soClient = getMockedSoClient({ defaultOutputId: 'output-test', }); - await expect( + expect( outputService.create( soClient, esClientMock, @@ -722,9 +722,7 @@ describe('Output Service', () => { }, { id: 'output-1' } ) - ).rejects.toThrow( - `Remote elasticsearch output cannot be set as default output for integration data. Please set "is_default" to false.` - ); + ).resolves.not.toThrow(); }); it('should set preset: balanced by default when creating a new ES output', async () => { @@ -1644,21 +1642,19 @@ describe('Output Service', () => { ); }); - it('should throw when a remote es output is attempted to be updated as default data output', async () => { + it('should not throw when a remote es output is attempted to be updated as default data output', async () => { const soClient = getMockedSoClient({ defaultOutputId: 'output-test', }); - await expect( + expect( outputService.update(soClient, esClientMock, 'output-test', { is_default: true, is_default_monitoring: false, name: 'Test', type: 'remote_elasticsearch', }) - ).rejects.toThrow( - `Remote elasticsearch output cannot be set as default output for integration data. Please set "is_default" to false.` - ); + ).resolves.not.toThrow(); }); }); diff --git a/x-pack/plugins/fleet/server/services/output.ts b/x-pack/plugins/fleet/server/services/output.ts index 7b838d9b9b0a53..e73a070a54965f 100644 --- a/x-pack/plugins/fleet/server/services/output.ts +++ b/x-pack/plugins/fleet/server/services/output.ts @@ -441,13 +441,6 @@ class OutputService { logger.debug(`Creating new output`); const data: OutputSOAttributes = { ...omit(output, ['ssl', 'secrets']) }; - if (output.type === outputType.RemoteElasticsearch) { - if (data.is_default) { - throw new OutputInvalidError( - 'Remote elasticsearch output cannot be set as default output for integration data. Please set "is_default" to false.' - ); - } - } if (outputTypeSupportPresets(data.type)) { if ( @@ -767,14 +760,6 @@ class OutputService { const logger = appContextService.getLogger(); logger.debug(`Updating output ${id}`); - if (data.type === outputType.RemoteElasticsearch) { - if (data.is_default) { - throw new OutputInvalidError( - 'Remote elasticsearch output cannot be set as default output for integration data. Please set "is_default" to false.' - ); - } - } - let secretsToDelete: PolicySecretReference[] = []; const originalOutput = await this.get(soClient, id); From 61786508a49b1f905f4f274e7013be7ed1fc7fe0 Mon Sep 17 00:00:00 2001 From: Julia Bardi Date: Thu, 14 Dec 2023 15:06:00 +0100 Subject: [PATCH 2/3] removed restriction to set remote_elasticsearch data output on agent policy with apm --- .../fleet/common/services/output_helpers.test.ts | 4 ++-- .../fleet/common/services/output_helpers.ts | 12 +++++++++--- .../agent_policy_advanced_fields/hooks.test.tsx | 16 ++++++++-------- .../agent_policy_advanced_fields/hooks.tsx | 4 ++-- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/x-pack/plugins/fleet/common/services/output_helpers.test.ts b/x-pack/plugins/fleet/common/services/output_helpers.test.ts index cba42f1b6c233f..57756dd699494e 100644 --- a/x-pack/plugins/fleet/common/services/output_helpers.test.ts +++ b/x-pack/plugins/fleet/common/services/output_helpers.test.ts @@ -26,7 +26,7 @@ describe('getAllowedOutputTypeForPolicy', () => { expect(res).toContain('logstash'); }); - it('should return only elasticsearch for an agent policy with APM', () => { + it('should return only elasticsearch types for an agent policy with APM', () => { const res = getAllowedOutputTypeForPolicy({ package_policies: [ { @@ -35,7 +35,7 @@ describe('getAllowedOutputTypeForPolicy', () => { ], } as any); - expect(res).toEqual(['elasticsearch']); + expect(res).toEqual(['elasticsearch', 'remote_elasticsearch']); }); it('should return only elasticsearch for an agent policy with Fleet Server', () => { diff --git a/x-pack/plugins/fleet/common/services/output_helpers.ts b/x-pack/plugins/fleet/common/services/output_helpers.ts index 26d97f42c39b45..5802765c23999b 100644 --- a/x-pack/plugins/fleet/common/services/output_helpers.ts +++ b/x-pack/plugins/fleet/common/services/output_helpers.ts @@ -28,15 +28,21 @@ export function getAllowedOutputTypeForPolicy(agentPolicy: AgentPolicy) { agentPolicy.package_policies && agentPolicy.package_policies.some( (p) => - p.package?.name === FLEET_APM_PACKAGE || - p.package?.name === FLEET_SERVER_PACKAGE || - p.package?.name === FLEET_SYNTHETICS_PACKAGE + p.package?.name === FLEET_SERVER_PACKAGE || p.package?.name === FLEET_SYNTHETICS_PACKAGE ); if (isRestrictedToSameClusterES) { return [outputType.Elasticsearch]; } + const isRestrictedToESType = + agentPolicy.package_policies && + agentPolicy.package_policies.some((p) => p.package?.name === FLEET_APM_PACKAGE); + + if (isRestrictedToESType) { + return [outputType.Elasticsearch, outputType.RemoteElasticsearch]; + } + return Object.values(outputType); } diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/hooks.test.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/hooks.test.tsx index 8c2983ee9fd83a..45594c95499361 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/hooks.test.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/hooks.test.tsx @@ -155,7 +155,7 @@ describe('useOutputOptions', () => { size="s" > { size="s" > { size="s" > { size="s" > { size="s" > { size="s" > { size="s" > { size="s" > Date: Mon, 18 Dec 2023 12:49:40 +0100 Subject: [PATCH 3/3] reverted change to allow apm with remote es as data output --- .../fleet/common/services/output_helpers.test.ts | 4 ++-- .../fleet/common/services/output_helpers.ts | 12 +++--------- .../agent_policy_advanced_fields/hooks.test.tsx | 16 ++++++++-------- .../agent_policy_advanced_fields/hooks.tsx | 4 ++-- 4 files changed, 15 insertions(+), 21 deletions(-) diff --git a/x-pack/plugins/fleet/common/services/output_helpers.test.ts b/x-pack/plugins/fleet/common/services/output_helpers.test.ts index 57756dd699494e..cba42f1b6c233f 100644 --- a/x-pack/plugins/fleet/common/services/output_helpers.test.ts +++ b/x-pack/plugins/fleet/common/services/output_helpers.test.ts @@ -26,7 +26,7 @@ describe('getAllowedOutputTypeForPolicy', () => { expect(res).toContain('logstash'); }); - it('should return only elasticsearch types for an agent policy with APM', () => { + it('should return only elasticsearch for an agent policy with APM', () => { const res = getAllowedOutputTypeForPolicy({ package_policies: [ { @@ -35,7 +35,7 @@ describe('getAllowedOutputTypeForPolicy', () => { ], } as any); - expect(res).toEqual(['elasticsearch', 'remote_elasticsearch']); + expect(res).toEqual(['elasticsearch']); }); it('should return only elasticsearch for an agent policy with Fleet Server', () => { diff --git a/x-pack/plugins/fleet/common/services/output_helpers.ts b/x-pack/plugins/fleet/common/services/output_helpers.ts index 5802765c23999b..988be3bc277f7f 100644 --- a/x-pack/plugins/fleet/common/services/output_helpers.ts +++ b/x-pack/plugins/fleet/common/services/output_helpers.ts @@ -28,21 +28,15 @@ export function getAllowedOutputTypeForPolicy(agentPolicy: AgentPolicy) { agentPolicy.package_policies && agentPolicy.package_policies.some( (p) => - p.package?.name === FLEET_SERVER_PACKAGE || p.package?.name === FLEET_SYNTHETICS_PACKAGE + p.package?.name === FLEET_SERVER_PACKAGE || + p.package?.name === FLEET_SYNTHETICS_PACKAGE || + p.package?.name === FLEET_APM_PACKAGE ); if (isRestrictedToSameClusterES) { return [outputType.Elasticsearch]; } - const isRestrictedToESType = - agentPolicy.package_policies && - agentPolicy.package_policies.some((p) => p.package?.name === FLEET_APM_PACKAGE); - - if (isRestrictedToESType) { - return [outputType.Elasticsearch, outputType.RemoteElasticsearch]; - } - return Object.values(outputType); } diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/hooks.test.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/hooks.test.tsx index 45594c95499361..8c2983ee9fd83a 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/hooks.test.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/hooks.test.tsx @@ -155,7 +155,7 @@ describe('useOutputOptions', () => { size="s" > { size="s" > { size="s" > { size="s" > { size="s" > { size="s" > { size="s" > { size="s" >