Skip to content

Commit

Permalink
[8.12][Fleet] removed restriction to use remote es as integration data (
Browse files Browse the repository at this point in the history
#17… (elastic#173522)

Backport elastic#173353 to 8.12
  • Loading branch information
juliaElastic authored Dec 19, 2023
1 parent 0ead2df commit d6e2907
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 52 deletions.
4 changes: 2 additions & 2 deletions x-pack/plugins/fleet/common/services/output_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -99,28 +99,26 @@ export function useOutputOptions(agentPolicy: Partial<NewAgentPolicy | AgentPoli

return [
getDefaultOutput(defaultOutputName, defaultOutputDisabled, defaultOutputDisabledMessage),
...outputsRequest.data.items
.filter((item) => 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 ? (
<FormattedMessage
id="xpack.fleet.agentPolicyForm.outputOptionDisabledTypeNotSupportedText"
defaultMessage="{outputType} output for agent integration is not supported for Fleet Server, Synthetics or APM."
values={{
outputType: item.type,
}}
/>
) : undefined
),
disabled: !isPolicyPerOutputAllowed || isOutputTypeUnsupported,
};
}),
return {
value: item.id,
inputDisplay: getOutputLabel(
item.name,
isOutputTypeUnsupported ? (
<FormattedMessage
id="xpack.fleet.agentPolicyForm.outputOptionDisabledTypeNotSupportedText"
defaultMessage="{outputType} output for agent integration is not supported for Fleet Server, Synthetics or APM."
values={{
outputType: item.type,
}}
/>
) : undefined
),
disabled: !isPolicyPerOutputAllowed || isOutputTypeUnsupported,
};
}),
];
}, [outputsRequest, isPolicyPerOutputAllowed, allowedOutputTypes]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,6 @@ export const EditOutputFlyout: React.FunctionComponent<EditOutputFlyoutProps> =
}}
/>
}
disabled={isRemoteESOutput}
/>
</EuiFormRow>
<EuiFormRow fullWidth {...inputs.defaultMonitoringOutputInput.formRowProps}>
Expand Down
16 changes: 6 additions & 10 deletions x-pack/plugins/fleet/server/services/output.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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();
});
});

Expand Down
15 changes: 0 additions & 15 deletions x-pack/plugins/fleet/server/services/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,13 +437,6 @@ class OutputService {
}
): Promise<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 (
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit d6e2907

Please sign in to comment.