Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fleet] Do not allow to use logstash output with APM integration #127809

Merged
merged 7 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { createFleetTestRendererMock } from '../../../../../../mock';
import type { MockedFleetStartServices } from '../../../../../../mock';
import { useLicense } from '../../../../../../hooks/use_license';
import type { LicenseService } from '../../../../services';
import type { AgentPolicy } from '../../../../types';

import { useOutputOptions } from './hooks';

Expand Down Expand Up @@ -44,12 +45,44 @@ const mockApiCallsWithOutputs = (http: MockedFleetStartServices['http']) => {
{
id: 'output2',
name: 'Output 2',
is_default: true,
is_default_monitoring: true,
is_default: false,
is_default_monitoring: false,
},
{
id: 'output3',
name: 'Output 3',
is_default: false,
is_default_monitoring: false,
},
],
},
};
}

return defaultHttpClientGetImplementation(path);
});
};

const mockApiCallsWithLogstashOutputs = (http: MockedFleetStartServices['http']) => {
http.get.mockImplementation(async (path) => {
if (typeof path !== 'string') {
throw new Error('Invalid request');
}
if (path === '/api/fleet/outputs') {
return {
data: {
items: [
{
id: 'elasticsearch1',
name: 'Elasticsearch1',
is_default: false,
type: 'elasticsearch',
is_default_monitoring: false,
},
{
id: 'logstash1',
name: 'Logstash 1',
type: 'logstash',
is_default: true,
is_default_monitoring: true,
},
Expand All @@ -69,13 +102,16 @@ describe('useOutputOptions', () => {
hasAtLeast: () => true,
} as unknown as LicenseService);
mockApiCallsWithOutputs(testRenderer.startServices.http);
const { result, waitForNextUpdate } = testRenderer.renderHook(() => useOutputOptions());
const { result, waitForNextUpdate } = testRenderer.renderHook(() =>
useOutputOptions({} as AgentPolicy)
);
expect(result.current.isLoading).toBeTruthy();

await waitForNextUpdate();
expect(result.current.dataOutputOptions).toMatchInlineSnapshot(`
Array [
Object {
"disabled": false,
"inputDisplay": "Default (currently Output 1)",
"value": "@@##DEFAULT_OUTPUT_VALUE##@@",
},
Expand All @@ -99,6 +135,7 @@ describe('useOutputOptions', () => {
expect(result.current.monitoringOutputOptions).toMatchInlineSnapshot(`
Array [
Object {
"disabled": undefined,
"inputDisplay": "Default (currently Output 1)",
"value": "@@##DEFAULT_OUTPUT_VALUE##@@",
},
Expand Down Expand Up @@ -127,13 +164,16 @@ describe('useOutputOptions', () => {
hasAtLeast: () => false,
} as unknown as LicenseService);
mockApiCallsWithOutputs(testRenderer.startServices.http);
const { result, waitForNextUpdate } = testRenderer.renderHook(() => useOutputOptions());
const { result, waitForNextUpdate } = testRenderer.renderHook(() =>
useOutputOptions({} as AgentPolicy)
);
expect(result.current.isLoading).toBeTruthy();

await waitForNextUpdate();
expect(result.current.dataOutputOptions).toMatchInlineSnapshot(`
Array [
Object {
"disabled": false,
"inputDisplay": "Default (currently Output 1)",
"value": "@@##DEFAULT_OUTPUT_VALUE##@@",
},
Expand All @@ -157,6 +197,7 @@ describe('useOutputOptions', () => {
expect(result.current.monitoringOutputOptions).toMatchInlineSnapshot(`
Array [
Object {
"disabled": undefined,
"inputDisplay": "Default (currently Output 1)",
"value": "@@##DEFAULT_OUTPUT_VALUE##@@",
},
Expand All @@ -178,4 +219,152 @@ describe('useOutputOptions', () => {
]
`);
});

it('should enable logstash output if there is no APM integration in the policy', async () => {
const testRenderer = createFleetTestRendererMock();
mockedUseLicence.mockReturnValue({
hasAtLeast: () => true,
} as unknown as LicenseService);
mockApiCallsWithLogstashOutputs(testRenderer.startServices.http);
const { result, waitForNextUpdate } = testRenderer.renderHook(() =>
useOutputOptions({} as AgentPolicy)
);
expect(result.current.isLoading).toBeTruthy();

await waitForNextUpdate();
expect(result.current.dataOutputOptions).toMatchInlineSnapshot(`
Array [
Object {
"disabled": false,
"inputDisplay": "Default (currently Logstash 1)",
"value": "@@##DEFAULT_OUTPUT_VALUE##@@",
},
Object {
"disabled": false,
"inputDisplay": "Elasticsearch1",
"value": "elasticsearch1",
},
Object {
"disabled": false,
"inputDisplay": "Logstash 1",
"value": "logstash1",
},
]
`);
expect(result.current.monitoringOutputOptions).toMatchInlineSnapshot(`
Array [
Object {
"disabled": undefined,
"inputDisplay": "Default (currently Logstash 1)",
"value": "@@##DEFAULT_OUTPUT_VALUE##@@",
},
Object {
"disabled": false,
"inputDisplay": "Elasticsearch1",
"value": "elasticsearch1",
},
Object {
"disabled": false,
"inputDisplay": "Logstash 1",
"value": "logstash1",
},
]
`);
});

it('should not enable logstash output if there is an APM integration in the policy', async () => {
const testRenderer = createFleetTestRendererMock();
mockedUseLicence.mockReturnValue({
hasAtLeast: () => true,
} as unknown as LicenseService);
mockApiCallsWithLogstashOutputs(testRenderer.startServices.http);
const { result, waitForNextUpdate } = testRenderer.renderHook(() =>
useOutputOptions({
package_policies: [
{
package: {
name: 'apm',
},
},
],
} as AgentPolicy)
);
expect(result.current.isLoading).toBeTruthy();

await waitForNextUpdate();
expect(result.current.dataOutputOptions).toMatchInlineSnapshot(`
Array [
Object {
"disabled": true,
"inputDisplay": <React.Fragment>
<EuiText
size="s"
>
Default (currently Logstash 1)
</EuiText>
<EuiSpacer
size="xs"
/>
<EuiText
size="s"
>
<FormattedMessage
defaultMessage="Logstash output for agent integration is not supported for APM"
id="xpack.fleet.agentPolicyForm.outputOptionDisabledAPMAndLogstashText"
values={Object {}}
/>
</EuiText>
</React.Fragment>,
"value": "@@##DEFAULT_OUTPUT_VALUE##@@",
},
Object {
"disabled": false,
"inputDisplay": "Elasticsearch1",
"value": "elasticsearch1",
},
Object {
"disabled": true,
"inputDisplay": <React.Fragment>
<EuiText
size="s"
>
Logstash 1
</EuiText>
<EuiSpacer
size="xs"
/>
<EuiText
size="s"
>
<FormattedMessage
defaultMessage="Logstash output for agent integration is not supported for APM"
id="xpack.fleet.agentPolicyForm.outputOptionDisabledAPMAndLogstashText"
values={Object {}}
/>
</EuiText>
</React.Fragment>,
"value": "logstash1",
},
]
`);
expect(result.current.monitoringOutputOptions).toMatchInlineSnapshot(`
Array [
Object {
"disabled": undefined,
"inputDisplay": "Default (currently Logstash 1)",
"value": "@@##DEFAULT_OUTPUT_VALUE##@@",
},
Object {
"disabled": false,
"inputDisplay": "Elasticsearch1",
"value": "elasticsearch1",
},
Object {
"disabled": false,
"inputDisplay": "Logstash 1",
"value": "logstash1",
},
]
`);
});
});
Loading