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] Exclude Synthetics from per-policy-outputs #161949

Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 11 additions & 2 deletions x-pack/plugins/fleet/common/services/agent_policies_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import type { AgentPolicy } from '../types';
import { FLEET_SERVER_PACKAGE, FLEET_APM_PACKAGE } from '../constants';
import { FLEET_SERVER_PACKAGE, FLEET_APM_PACKAGE, FLEET_SYNTHETICS_PACKAGE } from '../constants';

export function policyHasFleetServer(agentPolicy: AgentPolicy) {
if (!agentPolicy.package_policies) {
Expand All @@ -19,8 +19,17 @@ export function policyHasFleetServer(agentPolicy: AgentPolicy) {
}

export function policyHasAPMIntegration(agentPolicy: AgentPolicy) {
return policyHasIntegration(agentPolicy, FLEET_APM_PACKAGE);
}

export function policyHasSyntheticsIntegration(agentPolicy: AgentPolicy) {
return policyHasIntegration(agentPolicy, FLEET_SYNTHETICS_PACKAGE);
}

function policyHasIntegration(agentPolicy: AgentPolicy, packageName: string) {
if (!agentPolicy.package_policies) {
return false;
}
return agentPolicy.package_policies?.some((p) => p.package?.name === FLEET_APM_PACKAGE);

return agentPolicy.package_policies?.some((p) => p.package?.name === packageName);
}
6 changes: 5 additions & 1 deletion x-pack/plugins/fleet/common/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ export {
export { getAllowedOutputTypeForPolicy } from './output_helpers';
export { agentStatusesToSummary } from './agent_statuses_to_summary';

export { policyHasFleetServer, policyHasAPMIntegration } from './agent_policies_helpers';
export {
policyHasFleetServer,
policyHasAPMIntegration,
policyHasSyntheticsIntegration,
} from './agent_policies_helpers';

export {
generateNewAgentPolicyWithDefaults,
Expand Down
12 changes: 10 additions & 2 deletions x-pack/plugins/fleet/common/services/output_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
*/

import type { AgentPolicy } from '../types';
import { FLEET_APM_PACKAGE, FLEET_SERVER_PACKAGE, outputType } from '../constants';
import {
FLEET_APM_PACKAGE,
FLEET_SERVER_PACKAGE,
FLEET_SYNTHETICS_PACKAGE,
outputType,
} from '../constants';

/**
* Return allowed output type for a given agent policy,
Expand All @@ -16,7 +21,10 @@ export function getAllowedOutputTypeForPolicy(agentPolicy: AgentPolicy) {
const isRestrictedToSameClusterES =
agentPolicy.package_policies &&
agentPolicy.package_policies.some(
(p) => p.package?.name === FLEET_APM_PACKAGE || p.package?.name === FLEET_SERVER_PACKAGE
(p) =>
p.package?.name === FLEET_APM_PACKAGE ||
p.package?.name === FLEET_SERVER_PACKAGE ||
p.package?.name === FLEET_SYNTHETICS_PACKAGE
);

if (isRestrictedToSameClusterES) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe('useOutputOptions', () => {
size="s"
>
<FormattedMessage
defaultMessage="{outputType} output for agent integration is not supported for Fleet Server or APM."
defaultMessage="{outputType} output for agent integration is not supported for Fleet Server, Synthetics or APM."
id="xpack.fleet.agentPolicyForm.outputOptionDisabledTypeNotSupportedText"
values={
Object {
Expand All @@ -157,7 +157,7 @@ describe('useOutputOptions', () => {
size="s"
>
<FormattedMessage
defaultMessage="{outputType} output for agent integration is not supported for Fleet Server or APM."
defaultMessage="{outputType} output for agent integration is not supported for Fleet Server, Synthetics or APM."
id="xpack.fleet.agentPolicyForm.outputOptionDisabledTypeNotSupportedText"
values={
Object {
Expand All @@ -184,7 +184,7 @@ describe('useOutputOptions', () => {
size="s"
>
<FormattedMessage
defaultMessage="{outputType} output for agent integration is not supported for Fleet Server or APM."
defaultMessage="{outputType} output for agent integration is not supported for Fleet Server, Synthetics or APM."
id="xpack.fleet.agentPolicyForm.outputOptionDisabledTypeNotSupportedText"
values={
Object {
Expand Down Expand Up @@ -258,7 +258,7 @@ describe('useOutputOptions', () => {
size="s"
>
<FormattedMessage
defaultMessage="{outputType} output for agent integration is not supported for Fleet Server or APM."
defaultMessage="{outputType} output for agent integration is not supported for Fleet Server, Synthetics or APM."
id="xpack.fleet.agentPolicyForm.outputOptionDisabledTypeNotSupportedText"
values={
Object {
Expand All @@ -285,7 +285,7 @@ describe('useOutputOptions', () => {
size="s"
>
<FormattedMessage
defaultMessage="{outputType} output for agent integration is not supported for Fleet Server or APM."
defaultMessage="{outputType} output for agent integration is not supported for Fleet Server, Synthetics or APM."
id="xpack.fleet.agentPolicyForm.outputOptionDisabledTypeNotSupportedText"
values={
Object {
Expand All @@ -312,7 +312,7 @@ describe('useOutputOptions', () => {
size="s"
>
<FormattedMessage
defaultMessage="{outputType} output for agent integration is not supported for Fleet Server or APM."
defaultMessage="{outputType} output for agent integration is not supported for Fleet Server, Synthetics or APM."
id="xpack.fleet.agentPolicyForm.outputOptionDisabledTypeNotSupportedText"
values={
Object {
Expand Down Expand Up @@ -441,7 +441,7 @@ describe('useOutputOptions', () => {
size="s"
>
<FormattedMessage
defaultMessage="{outputType} output for agent integration is not supported for Fleet Server or APM."
defaultMessage="{outputType} output for agent integration is not supported for Fleet Server, Synthetics or APM."
id="xpack.fleet.agentPolicyForm.outputOptionDisableOutputTypeText"
values={
Object {
Expand Down Expand Up @@ -473,7 +473,7 @@ describe('useOutputOptions', () => {
size="s"
>
<FormattedMessage
defaultMessage="{outputType} output for agent integration is not supported for Fleet Server or APM."
defaultMessage="{outputType} output for agent integration is not supported for Fleet Server, Synthetics or APM."
id="xpack.fleet.agentPolicyForm.outputOptionDisabledTypeNotSupportedText"
values={
Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { LICENCE_FOR_PER_POLICY_OUTPUT } from '../../../../../../../common/const
import {
getAllowedOutputTypeForPolicy,
policyHasFleetServer,
policyHasSyntheticsIntegration,
} from '../../../../../../../common/services';
import type { NewAgentPolicy, AgentPolicy } from '../../../../types';

Expand Down Expand Up @@ -62,11 +63,11 @@ export function useOutputOptions(agentPolicy: Partial<NewAgentPolicy | AgentPoli
const outputsRequest = useGetOutputs();
const licenseService = useLicense();

const hasFleetServer = policyHasFleetServer(agentPolicy as AgentPolicy);

// Allow changing output when agent policy has fleet server
const isLicenceAllowingPolicyPerOutput =
licenseService.hasAtLeast(LICENCE_FOR_PER_POLICY_OUTPUT) || hasFleetServer;
// Allow changing output when agent policy has fleet server or synthetics integrations
const isPolicyPerOutputAllowed =
licenseService.hasAtLeast(LICENCE_FOR_PER_POLICY_OUTPUT) ||
policyHasFleetServer(agentPolicy as AgentPolicy) ||
policyHasSyntheticsIntegration(agentPolicy as AgentPolicy);
const allowedOutputTypes = useMemo(
() => getAllowedOutputTypeForPolicy(agentPolicy as AgentPolicy),
[agentPolicy]
Expand All @@ -89,7 +90,7 @@ export function useOutputOptions(agentPolicy: Partial<NewAgentPolicy | AgentPoli
const defaultOutputDisabledMessage = defaultOutputDisabled ? (
<FormattedMessage
id="xpack.fleet.agentPolicyForm.outputOptionDisableOutputTypeText"
defaultMessage="{outputType} output for agent integration is not supported for Fleet Server or APM."
defaultMessage="{outputType} output for agent integration is not supported for Fleet Server, Synthetics or APM."
values={{
outputType: defaultOutput.type,
}}
Expand All @@ -108,18 +109,18 @@ export function useOutputOptions(agentPolicy: Partial<NewAgentPolicy | AgentPoli
isOutputTypeUnsupported ? (
<FormattedMessage
id="xpack.fleet.agentPolicyForm.outputOptionDisabledTypeNotSupportedText"
defaultMessage="{outputType} output for agent integration is not supported for Fleet Server or APM."
defaultMessage="{outputType} output for agent integration is not supported for Fleet Server, Synthetics or APM."
values={{
outputType: item.type,
}}
/>
) : undefined
),
disabled: !isLicenceAllowingPolicyPerOutput || isOutputTypeUnsupported,
disabled: !isPolicyPerOutputAllowed || isOutputTypeUnsupported,
};
}),
];
}, [outputsRequest, isLicenceAllowingPolicyPerOutput, allowedOutputTypes]);
}, [outputsRequest, isPolicyPerOutputAllowed, allowedOutputTypes]);

const monitoringOutputOptions = useMemo(() => {
if (outputsRequest.isLoading || !outputsRequest.data) {
Expand All @@ -135,11 +136,11 @@ export function useOutputOptions(agentPolicy: Partial<NewAgentPolicy | AgentPoli
return {
value: item.id,
inputDisplay: item.name,
disabled: !isLicenceAllowingPolicyPerOutput,
disabled: !isPolicyPerOutputAllowed,
};
}),
];
}, [outputsRequest, isLicenceAllowingPolicyPerOutput]);
}, [outputsRequest, isPolicyPerOutputAllowed]);

return useMemo(
() => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ const ConfirmDescription: React.FunctionComponent<ConfirmDescriptionProps> = ({
title={
<FormattedMessage
id="xpack.fleet.settings.updateOutput.warningTitle"
defaultMessage="Logstash output for agent integration is not supported for fleet server."
defaultMessage="Logstash output for agent integration is not supported for fleet server and synthetics."
/>
}
>
<FormattedMessage
id="xpack.fleet.settings.updateOutput.warningMessage"
defaultMessage="Fleet server policies will keep using the existing ES output."
defaultMessage="Fleet server and synthetics policies will keep using the existing ES output."
/>
</EuiCallOut>{' '}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ describe('validateOutputForPolicy', () => {
);
});

it('should not allow logstash output to be used with a policy using fleet server or APM', async () => {
it('should not allow logstash output to be used with a policy using fleet server, synthetics or APM', async () => {
mockHasLicence(true);
mockedOutputService.get.mockResolvedValue({
type: 'logstash',
Expand All @@ -217,7 +217,7 @@ describe('validateOutputForPolicy', () => {
);
});

it('should allow elasticsearch output to be used with a policy using fleet server or APM', async () => {
it('should allow elasticsearch output to be used with a policy using fleet server, synthetics or APM', async () => {
mockHasLicence(true);
mockedOutputService.get.mockResolvedValue({
type: 'elasticsearch',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { SavedObjectsClientContract } from '@kbn/core/server';

import type { AgentPolicySOAttributes, AgentPolicy } from '../../types';
import { LICENCE_FOR_PER_POLICY_OUTPUT, outputType } from '../../../common/constants';
import { policyHasFleetServer } from '../../../common/services';
import { policyHasFleetServer, policyHasSyntheticsIntegration } from '../../../common/services';
import { appContextService } from '..';
import { outputService } from '../output';
import { OutputInvalidError, OutputLicenceError } from '../../errors';
Expand Down Expand Up @@ -80,6 +80,9 @@ export async function validateOutputForPolicy(
// Validate output when the policy has fleet server
if (policyHasFleetServer(data as AgentPolicy)) return;

// Validate output when the policy has synthetics server
jillguyonnet marked this conversation as resolved.
Show resolved Hide resolved
if (policyHasSyntheticsIntegration(data as AgentPolicy)) return;

const hasLicence = appContextService
.getSecurityLicense()
.hasAtLeast(LICENCE_FOR_PER_POLICY_OUTPUT);
Expand Down
5 changes: 5 additions & 0 deletions x-pack/plugins/fleet/server/services/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
packageToPackagePolicy,
policyHasFleetServer,
policyHasAPMIntegration,
policyHasSyntheticsIntegration,
} from '../../common/services';
import {
agentPolicyStatuses,
Expand Down Expand Up @@ -211,6 +212,10 @@ class AgentPolicyService {
return policyHasFleetServer(agentPolicy);
}

public hasSyntheticsIntegration(agentPolicy: AgentPolicy) {
return policyHasSyntheticsIntegration(agentPolicy);
}

public async create(
soClient: SavedObjectsClientContract,
esClient: ElasticsearchClient,
Expand Down
Loading