From d6e290775504f989dd3a76740192091c2bf853da Mon Sep 17 00:00:00 2001 From: Julia Bardi <90178898+juliaElastic@users.noreply.github.com> Date: Tue, 19 Dec 2023 10:00:13 +0100 Subject: [PATCH] =?UTF-8?q?[8.12][Fleet]=20removed=20restriction=20to=20us?= =?UTF-8?q?e=20remote=20es=20as=20integration=20data=20(#17=E2=80=A6=20(#1?= =?UTF-8?q?73522)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Backport https://github.com/elastic/kibana/pull/173353 to 8.12 --- .../fleet/common/services/output_helpers.ts | 4 +- .../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 ------- 6 files changed, 31 insertions(+), 52 deletions(-) diff --git a/x-pack/plugins/fleet/common/services/output_helpers.ts b/x-pack/plugins/fleet/common/services/output_helpers.ts index 26d97f42c39b45..988be3bc277f7f 100644 --- a/x-pack/plugins/fleet/common/services/output_helpers.ts +++ b/x-pack/plugins/fleet/common/services/output_helpers.ts @@ -28,9 +28,9 @@ 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_SYNTHETICS_PACKAGE || + p.package?.name === FLEET_APM_PACKAGE ); if (isRestrictedToSameClusterES) { 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 f2d17b0187274d..a478122286d32c 100644 --- a/x-pack/plugins/fleet/server/services/output.ts +++ b/x-pack/plugins/fleet/server/services/output.ts @@ -437,13 +437,6 @@ class OutputService { } ): Promise { 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 ( @@ -757,14 +750,6 @@ class OutputService { fromPreconfiguration: false, } ) { - 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);