Skip to content

Commit

Permalink
[UII] Support integration-level outputs (#189125)
Browse files Browse the repository at this point in the history
## Summary

Resolves #143905. This PR adds support for integration-level outputs.
This means that different integrations within the same agent policy can
now be configured to send data to different locations. This feature is
gated behind `enterprise` level subscription.

For each input, the agent policy will configure sending data to the
following outputs in decreasing order of priority:
1. Output set specifically on the integration policy
2. Output set specifically on the integration's parent agent policy
(including the case where an integration policy belongs to multiple
agent policies)
3. Global default data output set via Fleet Settings

Integration-level outputs will respect the same rules as agent
policy-level outputs:
- Certain integrations are disallowed from using certain output types,
attempting to add them to each other via creation, updating, or
"defaulting", will fail
- `fleet-server`, `synthetics`, and `apm` can only use same-cluster
Elasticsearch output
- When an output is deleted, any integrations that were specifically
using it will "clear" their output configuration and revert back to
either `#2` or `#3` in the above list
- When an output is edited, all agent policies across all spaces that
use it will be bumped to a new revision, this includes:
- Agent policies that have that output specifically set in their
settings (existing behavior)
- Agent policies that contain integrations which specifically has that
output set (new behavior)
- When a proxy is edited, the same new revision bump above will apply
for any outputs using that proxy

The final agent policy YAML that is generated will have:
- `outputs` block that includes:
- Data and monitoring outputs set at the agent policy level (existing
behavior)
- Any additional outputs set at the integration level, if they differ
from the above
- `outputs_permissions` block that includes permissions for each
Elasticsearch output depending on which integrations and/or agent
monitoring are assigned to it

Integration policies table now includes `Output` column. If the output
is defaulting to agent policy-level output, or global setting output, a
tooltip is shown:

<img width="1392" alt="image"
src="https://github.com/user-attachments/assets/5534716b-49b5-402a-aa4a-4ba6533e0ca8">

Configuring an integration-level output is done under Advanced options
in the policy editor. Setting to the blank value will "clear" the output
configuration. The list of available outputs is filtered by what outputs
are available for that integration (see above):

<img width="799" alt="image"
src="https://github.com/user-attachments/assets/617af6f4-e8f8-40b1-b476-848f8ac96e76">

An example of failure: ES output cannot be changed to Kafka while there
is an integration
<img width="1289" alt="image"
src="https://github.com/user-attachments/assets/11847eb5-fd5d-4271-8464-983d7ab39218">


## TODO
- [x] Adjust side effects of editing/deleting output when policies use
it across different spaces
- [x] Add API integration tests
- [x] Update OpenAPI spec
- [x] Create doc issue

### Checklist

Delete any items that are not applicable to this PR.

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [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

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
jen-huang and kibanamachine authored Aug 13, 2024
1 parent 8ee0493 commit 8266415
Show file tree
Hide file tree
Showing 53 changed files with 1,266 additions and 279 deletions.
1 change: 1 addition & 0 deletions packages/kbn-check-mappings-update-cli/current_fields.json
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@
"is_managed",
"name",
"namespace",
"output_id",
"overrides",
"package",
"package.name",
Expand Down
3 changes: 3 additions & 0 deletions packages/kbn-check-mappings-update-cli/current_mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2101,6 +2101,9 @@
"namespace": {
"type": "keyword"
},
"output_id": {
"type": "keyword"
},
"overrides": {
"index": false,
"type": "flattened"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"ingest-agent-policies": "90625b4a5ded9d4867358fcccc14a57c0454fcee",
"ingest-download-sources": "279a68147e62e4d8858c09ad1cf03bd5551ce58d",
"ingest-outputs": "daafff49255ab700e07491376fe89f04fc998b91",
"ingest-package-policies": "2c0f7c72d211bb7d3076ce2fc0bd368f9c16d274",
"ingest-package-policies": "53a94064674835fdb35e5186233bcd7052eabd22",
"ingest_manager_settings": "91445219e7115ff0c45d1dabd5d614a80b421797",
"inventory-view": "b8683c8e352a286b4aca1ab21003115a4800af83",
"kql-telemetry": "93c1d16c1a0dfca9c8842062cf5ef8f62ae401ad",
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/fleet/common/constants/mappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

/**
* ATTENTION: Mappings for Fleet are defined in the ElasticSearch repo.
* ATTENTION: Mappings for Fleet are defined in the Elasticsearch repo.
*
* The following mappings declared here closely mirror them
* But they are only used to perform validation on the endpoints using ListWithKuery
Expand Down Expand Up @@ -54,6 +54,7 @@ export const PACKAGE_POLICIES_MAPPINGS = {
is_managed: { type: 'boolean' },
policy_id: { type: 'keyword' },
policy_ids: { type: 'keyword' },
output_id: { type: 'keyword' },
package: {
properties: {
name: { type: 'keyword' },
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/common/constants/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const DEFAULT_OUTPUT: NewOutput = {
export const SERVERLESS_DEFAULT_OUTPUT_ID = 'es-default-output';

export const LICENCE_FOR_PER_POLICY_OUTPUT = 'platinum';
export const LICENCE_FOR_OUTPUT_PER_INTEGRATION = 'enterprise';

/**
* Kafka constants
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/fleet/common/constants/package_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ export const inputsFormat = {
Simplified: 'simplified',
Legacy: 'legacy',
} as const;

export const LICENCE_FOR_MULTIPLE_AGENT_POLICIES = 'enterprise';
3 changes: 1 addition & 2 deletions x-pack/plugins/fleet/common/openapi/bundled.json
Original file line number Diff line number Diff line change
Expand Up @@ -7484,8 +7484,7 @@
"type": "string"
},
"output_id": {
"type": "string",
"deprecated": true
"type": "string"
},
"inputs": {
"type": "array",
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/fleet/common/openapi/bundled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4804,7 +4804,6 @@ components:
type: string
output_id:
type: string
deprecated: true
inputs:
type: array
items:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ properties:
type: string
output_id:
type: string
deprecated: true
inputs:
type: array
items:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ properties:
type: string
output_id:
type: string
description: Not supported output can be set at the agent policy level only
deprecated: true
inputs:
type: array
items:
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('toPackagePolicy', () => {
namespace: 'default',
policy_id: 'policy123',
policy_ids: ['policy123'],
output_id: 'output123',
description: 'Test description',
inputs: {
'nginx-logfile': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface SimplifiedPackagePolicy {
id?: string;
policy_id?: string;
policy_ids: string[];
output_id?: string;
namespace: string;
name: string;
description?: string;
Expand Down Expand Up @@ -147,6 +148,7 @@ export function simplifiedPackagePolicytoNewPackagePolicy(
const {
policy_id: policyId,
policy_ids: policyIds,
output_id: outputId,
namespace,
name,
description,
Expand All @@ -161,6 +163,10 @@ export function simplifiedPackagePolicytoNewPackagePolicy(
description
);

if (outputId) {
packagePolicy.output_id = outputId;
}

if (packagePolicy.package && options?.experimental_data_stream_features) {
packagePolicy.package.experimental_data_stream_features =
options.experimental_data_stream_features;
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/fleet/common/types/models/package_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ export interface NewPackagePolicy {
/** @deprecated */
policy_id?: string;
policy_ids: string[];
// Nullable to allow user to reset to default outputs
output_id?: string | null;
package?: PackagePolicyPackage;
inputs: NewPackagePolicyInput[];
vars?: PackagePolicyConfigRecord;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export type PostDeletePackagePoliciesResponse = Array<{
package?: PackagePolicyPackage;
policy_id?: string;
policy_ids?: string[];
output_id?: string;
// Support generic errors
statusCode?: number;
body?: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import { useMemo } from 'react';
import { useHistory } from 'react-router-dom';

import { LICENCE_FOR_OUTPUT_PER_INTEGRATION } from '../../../../../../../../../common/constants';
import { getAllowedOutputTypesForIntegration } from '../../../../../../../../../common/services/output_helpers';
import { useGetOutputs, useLicense } from '../../../../../../hooks';

export function useDataStreamId() {
const history = useHistory();

Expand All @@ -16,3 +20,21 @@ export function useDataStreamId() {
return searchParams.get('datastreamId') ?? undefined;
}, [history.location.search]);
}

export function useOutputs(packageName: string) {
const licenseService = useLicense();
const canUseOutputPerIntegration = licenseService.hasAtLeast(LICENCE_FOR_OUTPUT_PER_INTEGRATION);
const { data: outputsData, isLoading } = useGetOutputs();
const allowedOutputTypes = getAllowedOutputTypesForIntegration(packageName);
const allowedOutputs = useMemo(() => {
if (!outputsData || !canUseOutputPerIntegration) {
return [];
}
return outputsData.items.filter((output) => allowedOutputTypes.includes(output.type));
}, [allowedOutputTypes, canUseOutputPerIntegration, outputsData]);
return {
isLoading,
canUseOutputPerIntegration,
allowedOutputs,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
EuiLink,
EuiCallOut,
EuiSpacer,
EuiSelect,
} from '@elastic/eui';

import styled from 'styled-components';
Expand All @@ -32,6 +33,7 @@ import { isAdvancedVar } from '../../services';
import type { PackagePolicyValidationResults } from '../../services';

import { PackagePolicyInputVarField } from './components';
import { useOutputs } from './components/hooks';

// on smaller screens, fields should be displayed in one column
const FormGroupResponsiveFields = styled(EuiDescribedFormGroup)`
Expand Down Expand Up @@ -81,6 +83,14 @@ export const StepDefinePackagePolicy: React.FunctionComponent<{
});
}

// Outputs
const {
isLoading: isOutputsLoading,
canUseOutputPerIntegration,
allowedOutputs,
} = useOutputs(packageInfo.name);

// Managed policy
const isManaged = packagePolicy.is_managed;

return validationResults ? (
Expand Down Expand Up @@ -245,6 +255,7 @@ export const StepDefinePackagePolicy: React.FunctionComponent<{
{isShowingAdvanced ? (
<EuiFlexItem>
<EuiFlexGroup direction="column" gutterSize="m">
{/* Namespace */}
<EuiFlexItem>
<EuiFormRow
isInvalid={!!validationResults.namespace}
Expand All @@ -264,7 +275,7 @@ export const StepDefinePackagePolicy: React.FunctionComponent<{
) : (
<FormattedMessage
id="xpack.fleet.createPackagePolicy.stepConfigure.packagePolicyNamespaceHelpLabel"
defaultMessage="Change the default namespace inherited from the selected Agent policy. This setting changes the name of the integration's data stream. {learnMore}."
defaultMessage="Change the default namespace inherited from the parent agent policy. This setting changes the name of the integration's data stream. {learnMore}."
values={{
learnMore: (
<EuiLink
Expand Down Expand Up @@ -304,6 +315,49 @@ export const StepDefinePackagePolicy: React.FunctionComponent<{
/>
</EuiFormRow>
</EuiFlexItem>

{/* Output */}
{canUseOutputPerIntegration && (
<EuiFlexItem>
<EuiFormRow
label={
<FormattedMessage
id="xpack.fleet.createPackagePolicy.stepConfigure.packagePolicyOutputInputLabel"
defaultMessage="Output"
/>
}
helpText={
<FormattedMessage
id="xpack.fleet.createPackagePolicy.stepConfigure.packagePolicyOutputHelpLabel"
defaultMessage="Change the default output inherited from the parent agent policy. This setting changes where the integration's data is sent."
/>
}
>
<EuiSelect
data-test-subj="packagePolicyOutputInput"
isLoading={isOutputsLoading}
options={[
{
value: '',
text: '',
},
...allowedOutputs.map((output) => ({
value: output.id,
text: output.name,
})),
]}
value={packagePolicy.output_id || ''}
onChange={(e) => {
updatePackagePolicy({
output_id: e.target.value.trim() || null,
});
}}
/>
</EuiFormRow>
</EuiFlexItem>
)}

{/* Data retention settings info */}
<EuiFlexItem>
<EuiFormRow
label={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import {
usePermissionCheck,
useStartServices,
useMultipleAgentPolicies,
useGetOutputs,
useDefaultOutput,
} from '../../../../../hooks';
import { pkgKeyFromPackageInfo } from '../../../../../services';

Expand Down Expand Up @@ -106,6 +108,16 @@ export const PackagePoliciesTable: React.FunctionComponent<Props> = ({
return packagePolicy.policy_ids.length || 0;
}, []);

const { data: outputsData, isLoading: isOutputsLoading } = useGetOutputs();
const { output: defaultOutputData } = useDefaultOutput();
const outputNamesById = useMemo(() => {
const outputs = outputsData?.items ?? [];
return outputs.reduce<Record<string, string>>((acc, output) => {
acc[output.id] = output.name;
return acc;
}, {});
}, [outputsData]);

const columns = useMemo(
(): EuiInMemoryTableProps<InMemoryPackagePolicy>['columns'] => [
{
Expand All @@ -115,6 +127,7 @@ export const PackagePoliciesTable: React.FunctionComponent<Props> = ({
name: i18n.translate('xpack.fleet.policyDetails.packagePoliciesTable.nameColumnTitle', {
defaultMessage: 'Integration policy',
}),
width: '35%',
render: (value: string, packagePolicy: InMemoryPackagePolicy) => (
<EuiFlexGroup gutterSize="s" alignItems="center">
<EuiFlexItem data-test-subj="PackagePoliciesTableName" grow={false}>
Expand Down Expand Up @@ -278,10 +291,67 @@ export const PackagePoliciesTable: React.FunctionComponent<Props> = ({
);
},
},
{
field: 'output_id',
name: i18n.translate('xpack.fleet.policyDetails.packagePoliciesTable.outputColumnTitle', {
defaultMessage: 'Output',
}),
render: (outputId: InMemoryPackagePolicy['output_id']) => {
if (isOutputsLoading) {
return null;
}
if (outputId) {
return <EuiBadge color="hollow">{outputNamesById[outputId] || outputId}</EuiBadge>;
}
if (agentPolicy.data_output_id) {
return (
<>
<EuiBadge color="default">
{outputNamesById[agentPolicy.data_output_id] || agentPolicy.data_output_id}
</EuiBadge>
&nbsp;
<EuiIconTip
content={i18n.translate(
'xpack.fleet.policyDetails.packagePoliciesTable.outputFromParentPolicyText',
{
defaultMessage: 'Output defined in parent agent policy',
}
)}
position="right"
type="iInCircle"
color="subdued"
/>
</>
);
}
if (defaultOutputData) {
return (
<>
<EuiBadge color="default">
{outputNamesById[defaultOutputData.id] || defaultOutputData.id}
</EuiBadge>
&nbsp;
<EuiIconTip
content={i18n.translate(
'xpack.fleet.policyDetails.packagePoliciesTable.outputFromFleetSettingsText',
{
defaultMessage: 'Output defined in Fleet settings',
}
)}
position="right"
type="iInCircle"
color="subdued"
/>
</>
);
}
},
},
{
name: i18n.translate('xpack.fleet.policyDetails.packagePoliciesTable.actionsColumnTitle', {
defaultMessage: 'Actions',
}),
width: '70px',
actions: [
{
render: (packagePolicy: InMemoryPackagePolicy) => {
Expand Down Expand Up @@ -309,8 +379,11 @@ export const PackagePoliciesTable: React.FunctionComponent<Props> = ({
agentPolicy,
canUseMultipleAgentPolicies,
canReadAgentPolicies,
canWriteIntegrationPolicies,
getSharedPoliciesNumber,
canWriteIntegrationPolicies,
isOutputsLoading,
defaultOutputData,
outputNamesById,
]
);

Expand Down
Loading

0 comments on commit 8266415

Please sign in to comment.