Skip to content

Commit

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

## Summary

Closes #173237

Removed restriction to allow using remote es output as integration data
output.

### Steps to verify:

#### Send system integration data to remote es
- Create a remote es output, verify that the output is allowed to be set
as default for agent integrations
- Create an agent policy with system integration and set the remote es
output as integration data output
- Enroll an agent to the agent policy
- Check the remote kibana - Discover, verify that system metrics are
coming in from the agent
- Install system package on the remote cluster to see dashboards,
mappings, etc.
#### Send nginx integration data to remote es
- Add nginx integration to the agent policy
- Create a dummy nginx log file in `/var/tmp/nginx/access.log` and add
some dummy data to it
- Verify that the data from the nginx log file appears in the remote
kibana Discover in `logs-*` data view.
#### Back to default output
- Change the agent policy integration output back to default
- Verify that the system integration data is ingested in the main
cluster.
- Verify that the API key is invalidated in the remote cluster

<img width="1742" alt="image"
src="https://github.com/elastic/kibana/assets/90178898/47ed4e89-e761-4f24-90c3-bf3a49a6b4f1">

<img width="937" alt="image"
src="https://github.com/elastic/kibana/assets/90178898/2e41f37e-a4ef-4f18-aed0-d4160efe306a">

<img width="2162" alt="image"
src="https://github.com/elastic/kibana/assets/90178898/bf5d900b-f3bd-493e-b61a-4554224a97fc">

<img width="2150" alt="image"
src="https://github.com/elastic/kibana/assets/90178898/31e4f32e-8751-4b02-855f-dc7fbd5e64a9">

System dashboard on remote cluster populated:
<img width="2157" alt="image"
src="https://github.com/elastic/kibana/assets/90178898/dfb10791-ab15-4058-9170-7cad51935493">


### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
  • Loading branch information
juliaElastic authored Dec 18, 2023
1 parent 86ed41e commit 4d35abe
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 @@ -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 (
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 4d35abe

Please sign in to comment.