Skip to content

Commit

Permalink
[Fleet] Make stream id unique in agent policy (#82447)
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet authored Nov 8, 2020
1 parent c77de15 commit 8560b2d
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,14 @@ describe('Ingest Manager - packageToPackagePolicy', () => {
{
type: 'foo',
enabled: true,
streams: [
{ id: 'foo-foo', enabled: true, data_stream: { dataset: 'foo', type: 'logs' } },
],
streams: [{ enabled: true, data_stream: { dataset: 'foo', type: 'logs' } }],
},
{
type: 'bar',
enabled: true,
streams: [
{ id: 'bar-bar', enabled: true, data_stream: { dataset: 'bar', type: 'logs' } },
{ id: 'bar-bar2', enabled: true, data_stream: { dataset: 'bar2', type: 'logs' } },
{ enabled: true, data_stream: { dataset: 'bar', type: 'logs' } },
{ enabled: true, data_stream: { dataset: 'bar2', type: 'logs' } },
],
},
]);
Expand Down Expand Up @@ -142,7 +140,6 @@ describe('Ingest Manager - packageToPackagePolicy', () => {
enabled: true,
streams: [
{
id: 'foo-foo',
enabled: true,
data_stream: { dataset: 'foo', type: 'logs' },
vars: { 'var-name': { value: 'foo-var-value' } },
Expand All @@ -154,13 +151,11 @@ describe('Ingest Manager - packageToPackagePolicy', () => {
enabled: true,
streams: [
{
id: 'bar-bar',
enabled: true,
data_stream: { dataset: 'bar', type: 'logs' },
vars: { 'var-name': { type: 'text', value: 'bar-var-value' } },
},
{
id: 'bar-bar2',
enabled: true,
data_stream: { dataset: 'bar2', type: 'logs' },
vars: { 'var-name': { type: 'yaml', value: 'bar2-var-value' } },
Expand Down Expand Up @@ -258,7 +253,6 @@ describe('Ingest Manager - packageToPackagePolicy', () => {
},
streams: [
{
id: 'foo-foo',
enabled: true,
data_stream: { dataset: 'foo', type: 'logs' },
vars: {
Expand All @@ -276,15 +270,13 @@ describe('Ingest Manager - packageToPackagePolicy', () => {
},
streams: [
{
id: 'bar-bar',
enabled: true,
data_stream: { dataset: 'bar', type: 'logs' },
vars: {
'var-name': { value: 'bar-var-value' },
},
},
{
id: 'bar-bar2',
enabled: true,
data_stream: { dataset: 'bar2', type: 'logs' },
vars: {
Expand All @@ -298,15 +290,13 @@ describe('Ingest Manager - packageToPackagePolicy', () => {
enabled: false,
streams: [
{
id: 'with-disabled-streams-disabled',
enabled: false,
data_stream: { dataset: 'disabled', type: 'logs' },
vars: {
'var-name': { value: [] },
},
},
{
id: 'with-disabled-streams-disabled2',
enabled: false,
data_stream: { dataset: 'disabled2', type: 'logs' },
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import {
RegistryPolicyTemplate,
RegistryVarsEntry,
RegistryStream,
PackagePolicy,
PackagePolicyConfigRecord,
PackagePolicyConfigRecordEntry,
PackagePolicyInput,
PackagePolicyInputStream,
NewPackagePolicyInput,
NewPackagePolicyInputStream,
NewPackagePolicy,
} from '../types';

Expand Down Expand Up @@ -42,8 +41,10 @@ const getStreamsForInputType = (
/*
* This service creates a package policy inputs definition from defaults provided in package info
*/
export const packageToPackagePolicyInputs = (packageInfo: PackageInfo): PackagePolicy['inputs'] => {
const inputs: PackagePolicy['inputs'] = [];
export const packageToPackagePolicyInputs = (
packageInfo: PackageInfo
): NewPackagePolicy['inputs'] => {
const inputs: NewPackagePolicy['inputs'] = [];

// Assume package will only ever ship one package policy template for now
const packagePolicyTemplate: RegistryPolicyTemplate | null =
Expand Down Expand Up @@ -71,12 +72,11 @@ export const packageToPackagePolicyInputs = (packageInfo: PackageInfo): PackageP
};

// Map each package input stream into package policy input stream
const streams: PackagePolicyInputStream[] = getStreamsForInputType(
const streams: NewPackagePolicyInputStream[] = getStreamsForInputType(
packageInput.type,
packageInfo
).map((packageStream) => {
const stream: PackagePolicyInputStream = {
id: `${packageInput.type}-${packageStream.data_stream.dataset}`,
const stream: NewPackagePolicyInputStream = {
enabled: packageStream.enabled === false ? false : true,
data_stream: packageStream.data_stream,
};
Expand All @@ -86,7 +86,7 @@ export const packageToPackagePolicyInputs = (packageInfo: PackageInfo): PackageP
return stream;
});

const input: PackagePolicyInput = {
const input: NewPackagePolicyInput = {
type: packageInput.type,
enabled: streams.length ? !!streams.find((stream) => stream.enabled) : true,
streams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export interface PackagePolicyConfigRecordEntry {
export type PackagePolicyConfigRecord = Record<string, PackagePolicyConfigRecordEntry>;

export interface NewPackagePolicyInputStream {
id: string;
enabled: boolean;
data_stream: {
dataset: string;
Expand All @@ -29,6 +28,7 @@ export interface NewPackagePolicyInputStream {
}

export interface PackagePolicyInputStream extends NewPackagePolicyInputStream {
id: string;
compiled_stream?: any;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
EuiSpacer,
EuiButtonEmpty,
} from '@elastic/eui';
import { PackagePolicyInput, RegistryVarsEntry } from '../../../../types';
import { NewPackagePolicyInput, RegistryVarsEntry } from '../../../../types';
import {
isAdvancedVar,
PackagePolicyConfigValidationResults,
Expand All @@ -28,8 +28,8 @@ const FlexItemWithMaxWidth = styled(EuiFlexItem)`

export const PackagePolicyInputConfig: React.FunctionComponent<{
packageInputVars?: RegistryVarsEntry[];
packagePolicyInput: PackagePolicyInput;
updatePackagePolicyInput: (updatedInput: Partial<PackagePolicyInput>) => void;
packagePolicyInput: NewPackagePolicyInput;
updatePackagePolicyInput: (updatedInput: Partial<NewPackagePolicyInput>) => void;
inputVarsValidationResults: PackagePolicyConfigValidationResults;
forceShowErrors?: boolean;
}> = memo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
EuiSpacer,
} from '@elastic/eui';
import {
PackagePolicyInput,
NewPackagePolicyInput,
PackagePolicyInputStream,
RegistryInput,
RegistryStream,
Expand All @@ -40,7 +40,7 @@ const ShortenedHorizontalRule = styled(EuiHorizontalRule)`
const shouldShowStreamsByDefault = (
packageInput: RegistryInput,
packageInputStreams: Array<RegistryStream & { data_stream: { dataset: string } }>,
packagePolicyInput: PackagePolicyInput
packagePolicyInput: NewPackagePolicyInput
): boolean => {
return (
packagePolicyInput.enabled &&
Expand All @@ -63,8 +63,8 @@ const shouldShowStreamsByDefault = (
export const PackagePolicyInputPanel: React.FunctionComponent<{
packageInput: RegistryInput;
packageInputStreams: Array<RegistryStream & { data_stream: { dataset: string } }>;
packagePolicyInput: PackagePolicyInput;
updatePackagePolicyInput: (updatedInput: Partial<PackagePolicyInput>) => void;
packagePolicyInput: NewPackagePolicyInput;
updatePackagePolicyInput: (updatedInput: Partial<NewPackagePolicyInput>) => void;
inputValidationResults: PackagePolicyInputValidationResults;
forceShowErrors?: boolean;
}> = memo(
Expand Down Expand Up @@ -210,7 +210,7 @@ export const PackagePolicyInputPanel: React.FunctionComponent<{
...updatedStream,
};

const updatedInput: Partial<PackagePolicyInput> = {
const updatedInput: Partial<NewPackagePolicyInput> = {
streams: newStreams,
};

Expand All @@ -227,7 +227,7 @@ export const PackagePolicyInputPanel: React.FunctionComponent<{
updatePackagePolicyInput(updatedInput);
}}
inputStreamValidationResults={
inputValidationResults.streams![packagePolicyInputStream!.id]
inputValidationResults.streams![packagePolicyInputStream!.data_stream!.dataset]
}
forceShowErrors={forceShowErrors}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
EuiSpacer,
EuiButtonEmpty,
} from '@elastic/eui';
import { PackagePolicyInputStream, RegistryStream, RegistryVarsEntry } from '../../../../types';
import { NewPackagePolicyInputStream, RegistryStream, RegistryVarsEntry } from '../../../../types';
import {
isAdvancedVar,
PackagePolicyConfigValidationResults,
Expand All @@ -30,8 +30,8 @@ const FlexItemWithMaxWidth = styled(EuiFlexItem)`

export const PackagePolicyInputStreamConfig: React.FunctionComponent<{
packageInputStream: RegistryStream;
packagePolicyInputStream: PackagePolicyInputStream;
updatePackagePolicyInputStream: (updatedStream: Partial<PackagePolicyInputStream>) => void;
packagePolicyInputStream: NewPackagePolicyInputStream;
updatePackagePolicyInputStream: (updatedStream: Partial<NewPackagePolicyInputStream>) => void;
inputStreamValidationResults: PackagePolicyConfigValidationResults;
forceShowErrors?: boolean;
}> = memo(
Expand Down
Loading

0 comments on commit 8560b2d

Please sign in to comment.