From 4470626795fb4dadc6ee90d0aca35394fa53efdf Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Mon, 20 Jun 2022 11:13:04 -0400 Subject: [PATCH 01/13] [Fleet] UI to edit custom pipeline|mappings --- .../services/datastream_es_name.test.ts | 19 +++ .../common/services/datastream_es_name.ts | 28 +++++ x-pack/plugins/fleet/common/services/index.ts | 4 + .../plugins/fleet/common/types/models/epm.ts | 2 + .../steps/components/datastream_mappings.tsx | 110 ++++++++++++++++++ .../steps/components/datastream_pipelines.tsx | 110 ++++++++++++++++++ .../components/steps/components/index.ts | 2 + .../components/package_policy_input_panel.tsx | 4 + .../package_policy_input_stream.tsx | 32 ++++- .../steps/step_configure_package.tsx | 1 + .../ingest_pipeline/helpers.test.ts | 12 -- .../elasticsearch/ingest_pipeline/helpers.ts | 15 +-- .../elasticsearch/ingest_pipeline/index.ts | 2 +- .../elasticsearch/ingest_pipeline/install.ts | 6 +- 14 files changed, 312 insertions(+), 35 deletions(-) create mode 100644 x-pack/plugins/fleet/common/services/datastream_es_name.test.ts create mode 100644 x-pack/plugins/fleet/common/services/datastream_es_name.ts create mode 100644 x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx create mode 100644 x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_pipelines.tsx diff --git a/x-pack/plugins/fleet/common/services/datastream_es_name.test.ts b/x-pack/plugins/fleet/common/services/datastream_es_name.test.ts new file mode 100644 index 0000000000000..1b8d8c8ccde7c --- /dev/null +++ b/x-pack/plugins/fleet/common/services/datastream_es_name.test.ts @@ -0,0 +1,19 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { getCustomPipelineNameForDatastream } from './datastream_es_name'; + +describe('getCustomPipelineNameForDatastream', () => { + it('return the correct custom pipeline for datastream', () => { + const res = getCustomPipelineNameForDatastream({ + type: 'logs', + dataset: 'test', + } as any); + + expect(res).toBe('logs-test@custom'); + }); +}); diff --git a/x-pack/plugins/fleet/common/services/datastream_es_name.ts b/x-pack/plugins/fleet/common/services/datastream_es_name.ts new file mode 100644 index 0000000000000..3ce8be6fb0351 --- /dev/null +++ b/x-pack/plugins/fleet/common/services/datastream_es_name.ts @@ -0,0 +1,28 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { RegistryDataStream } from '../types'; + +/** + * Return the ingest pipeline name for a datastream + */ +export const getPipelineNameForDatastream = ({ + dataStream, + packageVersion, +}: { + dataStream: RegistryDataStream; + packageVersion: string; +}): string => { + return `${dataStream.type}-${dataStream.dataset}-${packageVersion}`; +}; + +/** + * Return the custom user ingest pipeline name for a datastream + */ +export const getCustomPipelineNameForDatastream = (dataStream: RegistryDataStream): string => { + return `${dataStream.type}-${dataStream.dataset}@custom`; +}; diff --git a/x-pack/plugins/fleet/common/services/index.ts b/x-pack/plugins/fleet/common/services/index.ts index d8a7ed080ac63..55a04bcfdf6ae 100644 --- a/x-pack/plugins/fleet/common/services/index.ts +++ b/x-pack/plugins/fleet/common/services/index.ts @@ -36,3 +36,7 @@ export { normalizeHostsForAgents } from './hosts_utils'; export { splitPkgKey } from './split_pkg_key'; export { getMaxPackageName } from './max_package_name'; export { getMinVersion, getMaxVersion } from './get_min_max_version'; +export { + getPipelineNameForDatastream, + getCustomPipelineNameForDatastream, +} from './datastream_es_name'; diff --git a/x-pack/plugins/fleet/common/types/models/epm.ts b/x-pack/plugins/fleet/common/types/models/epm.ts index 902b32745d0e6..93eafd89bc2cc 100644 --- a/x-pack/plugins/fleet/common/types/models/epm.ts +++ b/x-pack/plugins/fleet/common/types/models/epm.ts @@ -209,6 +209,7 @@ export enum RegistryStreamKeys { enabled = 'enabled', vars = 'vars', template_path = 'template_path', + data_stream = 'data_stream', } export interface RegistryStream { @@ -218,6 +219,7 @@ export interface RegistryStream { [RegistryStreamKeys.enabled]?: boolean; [RegistryStreamKeys.vars]?: RegistryVarsEntry[]; [RegistryStreamKeys.template_path]: string; + [RegistryStreamKeys.data_stream]?: RegistryDataStream; } export type RequirementVersion = string; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx new file mode 100644 index 0000000000000..e7c49d5ede251 --- /dev/null +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx @@ -0,0 +1,110 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import React from 'react'; +import { + EuiBasicTable, + EuiButtonEmpty, + EuiFlexGroup, + EuiFlexItem, + EuiText, + EuiTitle, + EuiSpacer, + EuiLink, +} from '@elastic/eui'; +import { FormattedMessage } from '@kbn/i18n-react'; +import type { RegistryStream, PackageInfo } from '../../../../../../types'; +import { getPipelineNameForDatastream } from '../../../../../../../../../common'; + +interface Props { + packagePolicyId?: string; + packageInfo: PackageInfo; + packageInputStream: RegistryStream; +} + +export const DatastreamMappings: React.FunctionComponent = ({ + packagePolicyId, + packageInputStream, + packageInfo, +}) => { + if (!packageInputStream.data_stream) { + return null; + } + + const defaultPipelineName = getPipelineNameForDatastream({ + dataStream: packageInputStream.data_stream, + packageVersion: packageInfo.version, + }); + + return ( + + + +
+ +
+
+
+ + + + + + ), + }} + /> + + + + {}, + }, + ], + }, + ]} + > + + + + + + + +
+ ); +}; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_pipelines.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_pipelines.tsx new file mode 100644 index 0000000000000..ab2f9c00f346a --- /dev/null +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_pipelines.tsx @@ -0,0 +1,110 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import React from 'react'; +import { + EuiBasicTable, + EuiButtonEmpty, + EuiFlexGroup, + EuiFlexItem, + EuiText, + EuiTitle, + EuiSpacer, + EuiLink, +} from '@elastic/eui'; +import { FormattedMessage } from '@kbn/i18n-react'; +import type { RegistryStream, PackageInfo } from '../../../../../../types'; +import { getPipelineNameForDatastream } from '../../../../../../../../../common'; + +interface Props { + packagePolicyId?: string; + packageInfo: PackageInfo; + packageInputStream: RegistryStream; +} + +export const DatastreamPipeline: React.FunctionComponent = ({ + packagePolicyId, + packageInputStream, + packageInfo, +}) => { + if (!packageInputStream.data_stream) { + return null; + } + + const defaultPipelineName = getPipelineNameForDatastream({ + dataStream: packageInputStream.data_stream, + packageVersion: packageInfo.version, + }); + + return ( + + + +
+ +
+
+
+ + + + + + ), + }} + /> + + + + {}, + }, + ], + }, + ]} + > + + + + + + + +
+ ); +}; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/index.ts b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/index.ts index a12c67b7d51ad..eb72dcc4b7a12 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/index.ts +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/index.ts @@ -7,3 +7,5 @@ export { PackagePolicyInputPanel } from './package_policy_input_panel'; export { PackagePolicyInputVarField } from './package_policy_input_var_field'; +export { DatastreamPipeline } from './datastream_pipelines'; +export { DatastreamMappings } from './datastream_mappings'; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/package_policy_input_panel.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/package_policy_input_panel.tsx index 47056b1c2dabf..49b409bd90d10 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/package_policy_input_panel.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/package_policy_input_panel.tsx @@ -21,6 +21,7 @@ import { import type { NewPackagePolicyInput, + PackageInfo, PackagePolicyInputStream, RegistryInput, RegistryStream, @@ -63,6 +64,7 @@ const shouldShowStreamsByDefault = ( export const PackagePolicyInputPanel: React.FunctionComponent<{ packageInput: RegistryInput; + packageInfo: PackageInfo; packageInputStreams: Array; packagePolicyInput: NewPackagePolicyInput; updatePackagePolicyInput: (updatedInput: Partial) => void; @@ -71,6 +73,7 @@ export const PackagePolicyInputPanel: React.FunctionComponent<{ }> = memo( ({ packageInput, + packageInfo, packageInputStreams, packagePolicyInput, updatePackagePolicyInput, @@ -214,6 +217,7 @@ export const PackagePolicyInputPanel: React.FunctionComponent<{ {inputStreams.map(({ packageInputStream, packagePolicyInputStream }, index) => ( props.theme.eui.euiSizeL}); @@ -35,6 +38,7 @@ const FlexItemWithMaxWidth = styled(EuiFlexItem)` export const PackagePolicyInputStreamConfig: React.FunctionComponent<{ packageInputStream: RegistryStream; + packageInfo: PackageInfo; packagePolicyInputStream: NewPackagePolicyInputStream; updatePackagePolicyInputStream: (updatedStream: Partial) => void; inputStreamValidationResults: PackagePolicyConfigValidationResults; @@ -42,6 +46,7 @@ export const PackagePolicyInputStreamConfig: React.FunctionComponent<{ }> = memo( ({ packageInputStream, + packageInfo, packagePolicyInputStream, updatePackagePolicyInputStream, inputStreamValidationResults, @@ -54,9 +59,10 @@ export const PackagePolicyInputStreamConfig: React.FunctionComponent<{ const hasErrors = forceShowErrors && validationHasErrors(inputStreamValidationResults); const requiredVars: RegistryVarsEntry[] = []; - // eslint-disable-next-line react-hooks/exhaustive-deps const advancedVars: RegistryVarsEntry[] = []; + const allowCustomIngestPipeline = true; + if (packageInputStream.vars && packageInputStream.vars.length) { packageInputStream.vars.forEach((varDef) => { if (isAdvancedVar(varDef)) { @@ -135,7 +141,7 @@ export const PackagePolicyInputStreamConfig: React.FunctionComponent<{ ); })} - {advancedVars.length ? ( + {advancedVars.length || allowCustomIngestPipeline ? ( @@ -165,8 +171,9 @@ export const PackagePolicyInputStreamConfig: React.FunctionComponent<{ ) : null} - {isShowingAdvanced - ? advancedVars.map((varDef) => { + {isShowingAdvanced ? ( + <> + {advancedVars.map((varDef) => { if (!packagePolicyInputStream.vars) return null; const { name: varName, type: varType } = varDef; const value = packagePolicyInputStream.vars?.[varName]?.value; @@ -192,8 +199,21 @@ export const PackagePolicyInputStreamConfig: React.FunctionComponent<{ /> ); - }) - : null} + })} + + + + + + + + ) : null} ) : null} diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/step_configure_package.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/step_configure_package.tsx index db70c4b480b02..3407250a72122 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/step_configure_package.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/step_configure_package.tsx @@ -72,6 +72,7 @@ export const StepConfigurePackagePolicy: React.FunctionComponent<{ ) => { diff --git a/x-pack/plugins/fleet/server/services/epm/elasticsearch/ingest_pipeline/helpers.test.ts b/x-pack/plugins/fleet/server/services/epm/elasticsearch/ingest_pipeline/helpers.test.ts index 3699db0531db6..fcd60ec51e69e 100644 --- a/x-pack/plugins/fleet/server/services/epm/elasticsearch/ingest_pipeline/helpers.test.ts +++ b/x-pack/plugins/fleet/server/services/epm/elasticsearch/ingest_pipeline/helpers.test.ts @@ -12,7 +12,6 @@ import type { RegistryDataStream } from '../../../../types'; import { addCustomPipelineProcessor, - getCustomPipelineNameForDatastream, getPipelineNameForInstallation, rewriteIngestPipeline, } from './helpers'; @@ -192,14 +191,3 @@ processors: ); }); }); - -describe('getCustomPipelineNameForDatastream', () => { - it('return the correct custom pipeline for datastream', () => { - const res = getCustomPipelineNameForDatastream({ - type: 'logs', - dataset: 'test', - } as any); - - expect(res).toBe('logs-test@custom'); - }); -}); diff --git a/x-pack/plugins/fleet/server/services/epm/elasticsearch/ingest_pipeline/helpers.ts b/x-pack/plugins/fleet/server/services/epm/elasticsearch/ingest_pipeline/helpers.ts index b2022bfdb8aa3..4a69efa9082c6 100644 --- a/x-pack/plugins/fleet/server/services/epm/elasticsearch/ingest_pipeline/helpers.ts +++ b/x-pack/plugins/fleet/server/services/epm/elasticsearch/ingest_pipeline/helpers.ts @@ -11,6 +11,7 @@ import type { RegistryDataStream } from '../../../../types'; import { getPathParts } from '../../archive'; import type { PipelineInstall, RewriteSubstitution } from './types'; +import { getPipelineNameForDatastream } from '../../../../../common'; export const isTopLevelPipeline = (path: string) => { const pathParts = getPathParts(path); @@ -38,20 +39,6 @@ export const getPipelineNameForInstallation = ({ return `${packageVersion}-${pipelineName}`; }; -export const getPipelineNameForDatastream = ({ - dataStream, - packageVersion, -}: { - dataStream: RegistryDataStream; - packageVersion: string; -}): string => { - return `${dataStream.type}-${dataStream.dataset}-${packageVersion}`; -}; - -export const getCustomPipelineNameForDatastream = (dataStream: RegistryDataStream): string => { - return `${dataStream.type}-${dataStream.dataset}@custom`; -}; - export function rewriteIngestPipeline( pipeline: string, substitutions: RewriteSubstitution[] diff --git a/x-pack/plugins/fleet/server/services/epm/elasticsearch/ingest_pipeline/index.ts b/x-pack/plugins/fleet/server/services/epm/elasticsearch/ingest_pipeline/index.ts index a8f0065645b66..0a8414b4959bf 100644 --- a/x-pack/plugins/fleet/server/services/epm/elasticsearch/ingest_pipeline/index.ts +++ b/x-pack/plugins/fleet/server/services/epm/elasticsearch/ingest_pipeline/index.ts @@ -6,5 +6,5 @@ */ export { prepareToInstallPipelines } from './install'; -export { getPipelineNameForDatastream, isTopLevelPipeline } from './helpers'; +export { isTopLevelPipeline } from './helpers'; export { deletePreviousPipelines, deletePipeline } from './remove'; diff --git a/x-pack/plugins/fleet/server/services/epm/elasticsearch/ingest_pipeline/install.ts b/x-pack/plugins/fleet/server/services/epm/elasticsearch/ingest_pipeline/install.ts index 481d551cb07ac..a1fad104d82ef 100644 --- a/x-pack/plugins/fleet/server/services/epm/elasticsearch/ingest_pipeline/install.ts +++ b/x-pack/plugins/fleet/server/services/epm/elasticsearch/ingest_pipeline/install.ts @@ -17,13 +17,15 @@ import { FLEET_FINAL_PIPELINE_ID, FLEET_FINAL_PIPELINE_VERSION, } from '../../../../constants'; +import { + getCustomPipelineNameForDatastream, + getPipelineNameForDatastream, +} from '../../../../../common'; import { appendMetadataToIngestPipeline } from '../meta'; import { retryTransientEsErrors } from '../retry'; import { - getCustomPipelineNameForDatastream, - getPipelineNameForDatastream, getPipelineNameForInstallation, rewriteIngestPipeline, isTopLevelPipeline, From 2b63ebfc357fd9298d6977f6d8a697b9bbaa9af7 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Mon, 20 Jun 2022 16:06:18 +0000 Subject: [PATCH 02/13] [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix' --- x-pack/plugins/fleet/common/services/datastream_es_name.ts | 2 +- .../components/steps/components/datastream_mappings.tsx | 3 ++- .../components/steps/components/datastream_pipelines.tsx | 3 ++- .../services/epm/elasticsearch/ingest_pipeline/helpers.ts | 3 ++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/fleet/common/services/datastream_es_name.ts b/x-pack/plugins/fleet/common/services/datastream_es_name.ts index 3ce8be6fb0351..1a02e8f1a79ac 100644 --- a/x-pack/plugins/fleet/common/services/datastream_es_name.ts +++ b/x-pack/plugins/fleet/common/services/datastream_es_name.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { RegistryDataStream } from '../types'; +import type { RegistryDataStream } from '../types'; /** * Return the ingest pipeline name for a datastream diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx index e7c49d5ede251..4d585430998cd 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx @@ -17,6 +17,7 @@ import { EuiLink, } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n-react'; + import type { RegistryStream, PackageInfo } from '../../../../../../types'; import { getPipelineNameForDatastream } from '../../../../../../../../../common'; @@ -94,7 +95,7 @@ export const DatastreamMappings: React.FunctionComponent = ({ ], }, ]} - > + /> diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_pipelines.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_pipelines.tsx index ab2f9c00f346a..9fe168d1250a9 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_pipelines.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_pipelines.tsx @@ -17,6 +17,7 @@ import { EuiLink, } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n-react'; + import type { RegistryStream, PackageInfo } from '../../../../../../types'; import { getPipelineNameForDatastream } from '../../../../../../../../../common'; @@ -94,7 +95,7 @@ export const DatastreamPipeline: React.FunctionComponent = ({ ], }, ]} - > + /> diff --git a/x-pack/plugins/fleet/server/services/epm/elasticsearch/ingest_pipeline/helpers.ts b/x-pack/plugins/fleet/server/services/epm/elasticsearch/ingest_pipeline/helpers.ts index 4a69efa9082c6..dc6e72ffe1b3f 100644 --- a/x-pack/plugins/fleet/server/services/epm/elasticsearch/ingest_pipeline/helpers.ts +++ b/x-pack/plugins/fleet/server/services/epm/elasticsearch/ingest_pipeline/helpers.ts @@ -10,9 +10,10 @@ import { ElasticsearchAssetType } from '../../../../types'; import type { RegistryDataStream } from '../../../../types'; import { getPathParts } from '../../archive'; -import type { PipelineInstall, RewriteSubstitution } from './types'; import { getPipelineNameForDatastream } from '../../../../../common'; +import type { PipelineInstall, RewriteSubstitution } from './types'; + export const isTopLevelPipeline = (path: string) => { const pathParts = getPathParts(path); return ( From 4cd26ba984c51753fdd8b03a9b984d8232acdeff Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Mon, 20 Jun 2022 12:27:45 -0400 Subject: [PATCH 03/13] Fix types --- x-pack/plugins/fleet/common/services/datastream_es_name.ts | 2 +- x-pack/plugins/fleet/common/types/models/epm.ts | 2 -- .../components/steps/components/datastream_mappings.tsx | 2 +- .../components/steps/components/datastream_pipelines.tsx | 2 +- .../components/steps/components/package_policy_input_stream.tsx | 2 +- 5 files changed, 4 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/fleet/common/services/datastream_es_name.ts b/x-pack/plugins/fleet/common/services/datastream_es_name.ts index 3ce8be6fb0351..e63909ee997c6 100644 --- a/x-pack/plugins/fleet/common/services/datastream_es_name.ts +++ b/x-pack/plugins/fleet/common/services/datastream_es_name.ts @@ -14,7 +14,7 @@ export const getPipelineNameForDatastream = ({ dataStream, packageVersion, }: { - dataStream: RegistryDataStream; + dataStream: { dataset: string; type: string }; packageVersion: string; }): string => { return `${dataStream.type}-${dataStream.dataset}-${packageVersion}`; diff --git a/x-pack/plugins/fleet/common/types/models/epm.ts b/x-pack/plugins/fleet/common/types/models/epm.ts index 93eafd89bc2cc..902b32745d0e6 100644 --- a/x-pack/plugins/fleet/common/types/models/epm.ts +++ b/x-pack/plugins/fleet/common/types/models/epm.ts @@ -209,7 +209,6 @@ export enum RegistryStreamKeys { enabled = 'enabled', vars = 'vars', template_path = 'template_path', - data_stream = 'data_stream', } export interface RegistryStream { @@ -219,7 +218,6 @@ export interface RegistryStream { [RegistryStreamKeys.enabled]?: boolean; [RegistryStreamKeys.vars]?: RegistryVarsEntry[]; [RegistryStreamKeys.template_path]: string; - [RegistryStreamKeys.data_stream]?: RegistryDataStream; } export type RequirementVersion = string; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx index e7c49d5ede251..95a797a7b6cf3 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx @@ -23,7 +23,7 @@ import { getPipelineNameForDatastream } from '../../../../../../../../../common' interface Props { packagePolicyId?: string; packageInfo: PackageInfo; - packageInputStream: RegistryStream; + packageInputStream: RegistryStream & { data_stream: { dataset: string; type: string } }; } export const DatastreamMappings: React.FunctionComponent = ({ diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_pipelines.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_pipelines.tsx index ab2f9c00f346a..dae6269705932 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_pipelines.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_pipelines.tsx @@ -23,7 +23,7 @@ import { getPipelineNameForDatastream } from '../../../../../../../../../common' interface Props { packagePolicyId?: string; packageInfo: PackageInfo; - packageInputStream: RegistryStream; + packageInputStream: RegistryStream & { data_stream: { dataset: string; type: string } }; } export const DatastreamPipeline: React.FunctionComponent = ({ diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/package_policy_input_stream.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/package_policy_input_stream.tsx index 736a117e0ee58..29e009dfa8c9b 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/package_policy_input_stream.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/package_policy_input_stream.tsx @@ -37,7 +37,7 @@ const FlexItemWithMaxWidth = styled(EuiFlexItem)` `; export const PackagePolicyInputStreamConfig: React.FunctionComponent<{ - packageInputStream: RegistryStream; + packageInputStream: RegistryStream & { data_stream: { dataset: string; type: string } }; packageInfo: PackageInfo; packagePolicyInputStream: NewPackagePolicyInputStream; updatePackagePolicyInputStream: (updatedStream: Partial) => void; From 0d19aeb64e9ca885056d10e752b11c7b84c6c175 Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Mon, 20 Jun 2022 14:04:59 -0400 Subject: [PATCH 04/13] fix typo --- .../components/steps/components/datastream_mappings.tsx | 8 +++----- .../components/steps/components/datastream_pipelines.tsx | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx index e0f6dda4b8e4a..49e9d3c0fc7ca 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx @@ -48,7 +48,7 @@ export const DatastreamMappings: React.FunctionComponent = ({
@@ -57,9 +57,7 @@ export const DatastreamMappings: React.FunctionComponent = ({ @@ -102,7 +100,7 @@ export const DatastreamMappings: React.FunctionComponent = ({
diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_pipelines.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_pipelines.tsx index 3dafbe85339fd..cfd3c6a4bf54c 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_pipelines.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_pipelines.tsx @@ -48,7 +48,7 @@ export const DatastreamPipeline: React.FunctionComponent = ({
@@ -57,9 +57,7 @@ export const DatastreamPipeline: React.FunctionComponent = ({ @@ -102,7 +100,7 @@ export const DatastreamPipeline: React.FunctionComponent = ({ From 555f0733824f8a796e39ed006c4f771508689ab5 Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Tue, 21 Jun 2022 14:28:06 -0400 Subject: [PATCH 05/13] Add navigation to ingest pipeline plugin --- .../common/services/datastream_es_name.ts | 7 +- x-pack/plugins/fleet/kibana.json | 2 +- .../steps/components/datastream_mappings.tsx | 1 + .../steps/components/datastream_pipelines.tsx | 139 +++++++++++++++--- .../components/package_policy_input_panel.tsx | 8 +- .../package_policy_input_stream.tsx | 4 + .../steps/step_configure_package.tsx | 1 + .../fleet/public/hooks/use_request/index.ts | 1 + .../hooks/use_request/ingest_pipelines.ts | 17 +++ x-pack/plugins/fleet/tsconfig.json | 1 + 10 files changed, 152 insertions(+), 29 deletions(-) create mode 100644 x-pack/plugins/fleet/public/hooks/use_request/ingest_pipelines.ts diff --git a/x-pack/plugins/fleet/common/services/datastream_es_name.ts b/x-pack/plugins/fleet/common/services/datastream_es_name.ts index 9f8ac9b9dac23..d94d84d064d5a 100644 --- a/x-pack/plugins/fleet/common/services/datastream_es_name.ts +++ b/x-pack/plugins/fleet/common/services/datastream_es_name.ts @@ -5,8 +5,6 @@ * 2.0. */ -import type { RegistryDataStream } from '../types'; - /** * Return the ingest pipeline name for a datastream */ @@ -23,6 +21,9 @@ export const getPipelineNameForDatastream = ({ /** * Return the custom user ingest pipeline name for a datastream */ -export const getCustomPipelineNameForDatastream = (dataStream: RegistryDataStream): string => { +export const getCustomPipelineNameForDatastream = (dataStream: { + dataset: string; + type: string; +}): string => { return `${dataStream.type}-${dataStream.dataset}@custom`; }; diff --git a/x-pack/plugins/fleet/kibana.json b/x-pack/plugins/fleet/kibana.json index 4bfc6e95f0157..409e9f2a896ae 100644 --- a/x-pack/plugins/fleet/kibana.json +++ b/x-pack/plugins/fleet/kibana.json @@ -9,7 +9,7 @@ "ui": true, "configPath": ["xpack", "fleet"], "requiredPlugins": ["licensing", "data", "encryptedSavedObjects", "navigation", "customIntegrations", "share", "spaces", "security", "unifiedSearch"], - "optionalPlugins": ["features", "cloud", "usageCollection", "home", "globalSearch", "telemetry", "discover"], + "optionalPlugins": ["features", "cloud", "usageCollection", "home", "globalSearch", "telemetry", "discover", "ingestPipelines"], "extraPublicDirs": ["common"], "requiredBundles": ["kibanaReact", "cloud", "esUiShared", "infra", "kibanaUtils", "usageCollection", "unifiedSearch"] } diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx index 49e9d3c0fc7ca..be71e7d56f834 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx @@ -27,6 +27,7 @@ interface Props { packageInputStream: RegistryStream & { data_stream: { dataset: string; type: string } }; } +// Work in progress only here for demo for now export const DatastreamMappings: React.FunctionComponent = ({ packagePolicyId, packageInputStream, diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_pipelines.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_pipelines.tsx index cfd3c6a4bf54c..61d7c5d431272 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_pipelines.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_pipelines.tsx @@ -5,7 +5,7 @@ * 2.0. */ -import React from 'react'; +import React, { useMemo } from 'react'; import { EuiBasicTable, EuiButtonEmpty, @@ -18,29 +18,90 @@ import { } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n-react'; -import type { RegistryStream, PackageInfo } from '../../../../../../types'; -import { getPipelineNameForDatastream } from '../../../../../../../../../common'; +import type { RegistryStream, PackageInfo, NewPackagePolicy } from '../../../../../../types'; +import { useStartServices, useGetPipeline, useLink } from '../../../../../../hooks'; +import { + getPipelineNameForDatastream, + getCustomPipelineNameForDatastream, +} from '../../../../../../../../../common'; +import { useRouteMatch } from 'react-router'; interface Props { - packagePolicyId?: string; + packagePolicy: NewPackagePolicy; packageInfo: PackageInfo; packageInputStream: RegistryStream & { data_stream: { dataset: string; type: string } }; } +interface PipelineItem { + pipelineName: string; + canEdit: boolean; +} + +function toPipelineItem(pipelineName: string, canEdit = false): PipelineItem { + return { pipelineName, canEdit }; +} + +function useDatastreamIngestPipelines( + packageInfo: PackageInfo, + dataStream?: { dataset: string; type: string } +) { + if (!dataStream) { + return { pipelines: [] }; + } + + const defaultPipelineName = getPipelineNameForDatastream({ + dataStream, + packageVersion: packageInfo.version, + }); + + const customPipelineName = getCustomPipelineNameForDatastream(dataStream); + + const res = useGetPipeline(customPipelineName); + + const pipelines: PipelineItem[] = useMemo(() => { + if (res.data) { + return [toPipelineItem(defaultPipelineName), toPipelineItem(customPipelineName, true)]; + } + return [toPipelineItem(defaultPipelineName)]; + }, [defaultPipelineName, customPipelineName, res.data]); + + return { + isLoading: res.isLoading, + hasCustom: !res.isLoading && res.error?.statusCode !== 404, + pipelines, + }; +} + export const DatastreamPipeline: React.FunctionComponent = ({ - packagePolicyId, + packagePolicy, packageInputStream, packageInfo, }) => { + const { + params: { packagePolicyId, policyId }, + } = useRouteMatch<{ policyId: string; packagePolicyId: string }>(); + const { getHref } = useLink(); + + const pageUrl = + packagePolicyId && policyId + ? getHref('edit_integration', { + policyId, + packagePolicyId, + }) + : null; + + const { application, share } = useStartServices(); + const ingestPipelineLocator = share.url.locators.get('INGEST_PIPELINES_APP_LOCATOR'); + + const { pipelines, hasCustom } = useDatastreamIngestPipelines( + packageInfo, + packageInputStream.data_stream + ); + if (!packageInputStream.data_stream) { return null; } - const defaultPipelineName = getPipelineNameForDatastream({ - dataStream: packageInputStream.data_stream, - packageVersion: packageInfo.version, - }); - return ( @@ -73,37 +134,69 @@ export const DatastreamPipeline: React.FunctionComponent = ({ { + if (!ingestPipelineLocator) { + return; + } + const url = await ingestPipelineLocator.getUrl({ + page: 'pipeline_edit', + pipelineId: el.pipelineName, + }); + + application.navigateToUrl(`${url}?redirect_path=${pageUrl}`); + }, + available: ({ canEdit }) => canEdit, + }, { icon: 'inspect', type: 'icon', description: 'test', name: 'inspect', isPrimary: true, - onClick: () => {}, + onClick: async (el) => { + if (!ingestPipelineLocator) { + return; + } + const url = await ingestPipelineLocator.getUrl({ + page: 'pipeline_list', + }); + + application.navigateToUrl( + `${url}?pipeline=${el.pipelineName}&redirect_path=${pageUrl}` + ); + }, }, ], }, ]} /> - - - - - - + {!hasCustom && ( + + + + + + + )} ); }; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/package_policy_input_panel.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/package_policy_input_panel.tsx index 49b409bd90d10..cc641812235ce 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/package_policy_input_panel.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/package_policy_input_panel.tsx @@ -20,6 +20,7 @@ import { } from '@elastic/eui'; import type { + NewPackagePolicy, NewPackagePolicyInput, PackageInfo, PackagePolicyInputStream, @@ -41,7 +42,7 @@ const ShortenedHorizontalRule = styled(EuiHorizontalRule)` const shouldShowStreamsByDefault = ( packageInput: RegistryInput, - packageInputStreams: Array, + packageInputStreams: Array, packagePolicyInput: NewPackagePolicyInput ): boolean => { return ( @@ -65,7 +66,8 @@ const shouldShowStreamsByDefault = ( export const PackagePolicyInputPanel: React.FunctionComponent<{ packageInput: RegistryInput; packageInfo: PackageInfo; - packageInputStreams: Array; + packagePolicy: NewPackagePolicy; + packageInputStreams: Array; packagePolicyInput: NewPackagePolicyInput; updatePackagePolicyInput: (updatedInput: Partial) => void; inputValidationResults: PackagePolicyInputValidationResults; @@ -76,6 +78,7 @@ export const PackagePolicyInputPanel: React.FunctionComponent<{ packageInfo, packageInputStreams, packagePolicyInput, + packagePolicy, updatePackagePolicyInput, inputValidationResults, forceShowErrors, @@ -218,6 +221,7 @@ export const PackagePolicyInputPanel: React.FunctionComponent<{ = memo( ({ + packagePolicy, packageInputStream, packageInfo, packagePolicyInputStream, @@ -202,6 +205,7 @@ export const PackagePolicyInputStreamConfig: React.FunctionComponent<{ })} diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/step_configure_package.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/step_configure_package.tsx index 3407250a72122..57b5376c9fbb7 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/step_configure_package.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/step_configure_package.tsx @@ -73,6 +73,7 @@ export const StepConfigurePackagePolicy: React.FunctionComponent<{ ) => { diff --git a/x-pack/plugins/fleet/public/hooks/use_request/index.ts b/x-pack/plugins/fleet/public/hooks/use_request/index.ts index 2973d2dcd3fc8..2f700052acd7b 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/index.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/index.ts @@ -16,3 +16,4 @@ export * from './outputs'; export * from './settings'; export * from './setup'; export * from './app'; +export * from './ingest_pipelines'; diff --git a/x-pack/plugins/fleet/public/hooks/use_request/ingest_pipelines.ts b/x-pack/plugins/fleet/public/hooks/use_request/ingest_pipelines.ts new file mode 100644 index 0000000000000..c5bd3fed7d7fe --- /dev/null +++ b/x-pack/plugins/fleet/public/hooks/use_request/ingest_pipelines.ts @@ -0,0 +1,17 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import type { GetDataStreamsResponse } from '../../types'; + +import { useRequest } from './use_request'; + +export const useGetPipeline = (pipelineId: string) => { + return useRequest({ + path: `/api/ingest_pipelines/${pipelineId}`, + method: 'get', + }); +}; diff --git a/x-pack/plugins/fleet/tsconfig.json b/x-pack/plugins/fleet/tsconfig.json index d0361f4550576..b88a2605067e3 100644 --- a/x-pack/plugins/fleet/tsconfig.json +++ b/x-pack/plugins/fleet/tsconfig.json @@ -30,6 +30,7 @@ { "path": "../security/tsconfig.json" }, { "path": "../features/tsconfig.json" }, { "path": "../cloud/tsconfig.json" }, + { "path": "../ingest_pipelines/tsconfig.json" }, { "path": "../../../src/plugins/usage_collection/tsconfig.json" }, { "path": "../../../src/plugins/home/tsconfig.json" }, From de4c25dca5ec63d60351b64ace42303ffbf3ef44 Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Wed, 22 Jun 2022 09:15:14 -0400 Subject: [PATCH 06/13] Fix typo --- .../steps/components/datastream_mappings.tsx | 22 ++----------------- .../epm/elasticsearch/template/install.ts | 3 +-- 2 files changed, 3 insertions(+), 22 deletions(-) diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx index be71e7d56f834..b137c828f364c 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx @@ -6,16 +6,7 @@ */ import React from 'react'; -import { - EuiBasicTable, - EuiButtonEmpty, - EuiFlexGroup, - EuiFlexItem, - EuiText, - EuiTitle, - EuiSpacer, - EuiLink, -} from '@elastic/eui'; +import { EuiBasicTable, EuiFlexGroup, EuiFlexItem, EuiText, EuiTitle, EuiLink } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n-react'; import type { RegistryStream, PackageInfo } from '../../../../../../types'; @@ -76,9 +67,9 @@ export const DatastreamMappings: React.FunctionComponent = ({ = ({ ]} /> - - - - - - ); }; diff --git a/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/install.ts b/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/install.ts index 0393c8bf91a50..c0a185a0b270e 100644 --- a/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/install.ts +++ b/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/install.ts @@ -10,6 +10,7 @@ import Boom from '@hapi/boom'; import type { ElasticsearchClient, Logger } from '@kbn/core/server'; import { ElasticsearchAssetType } from '../../../../types'; +import { getPipelineNameForDatastream } from '../../../../../common'; import type { RegistryDataStream, IndexTemplateEntry, @@ -22,9 +23,7 @@ import type { EsAssetReference, PackageInfo, } from '../../../../types'; - import { loadFieldsFromYaml, processFields } from '../../fields/field'; -import { getPipelineNameForDatastream } from '../ingest_pipeline'; import { getAsset, getPathParts } from '../../archive'; import { FLEET_COMPONENT_TEMPLATES, From 4f7a9cff0cac6dc5d02c32ffbf885834f4502599 Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Wed, 22 Jun 2022 13:41:50 -0400 Subject: [PATCH 07/13] Add test to datastream pipeline --- .../steps/components/datastream_mappings.tsx | 2 +- .../components/datastream_pipelines.test.tsx | 78 ++++++++ .../steps/components/datastream_pipelines.tsx | 62 ++++--- .../components/steps/components/index.ts | 2 +- .../package_policy_input_stream.tsx | 166 +++++++++--------- 5 files changed, 199 insertions(+), 111 deletions(-) create mode 100644 x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_pipelines.test.tsx diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx index b137c828f364c..0eae8ba0ea4cb 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx @@ -55,7 +55,7 @@ export const DatastreamMappings: React.FunctionComponent = ({ ), diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_pipelines.test.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_pipelines.test.tsx new file mode 100644 index 0000000000000..333b16393fd74 --- /dev/null +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_pipelines.test.tsx @@ -0,0 +1,78 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import React from 'react'; + +import { createFleetTestRendererMock } from '../../../../../../../../mock'; +import { useGetPipeline } from '../../../../../../hooks'; + +import { DatastreamPipelines } from './datastream_pipelines'; + +const mockedUseGetPipeline = useGetPipeline as jest.MockedFunction; + +jest.mock('../../../../../../hooks', () => { + return { + ...jest.requireActual('../../../../../../hooks'), + FleetStatusProvider: (props: any) => { + return props.children; + }, + useFleetStatus: jest.fn().mockReturnValue({ isReady: true } as any), + useGetPipeline: jest.fn(), + }; +}); + +describe('DatastreamPipelines', () => { + it('should render with a add button if there is no custom pipeline', () => { + const renderer = createFleetTestRendererMock(); + mockedUseGetPipeline.mockReturnValue({ + isLoading: false, + error: { + statusCode: 404, + }, + } as any); + + const result = renderer.render( + + ); + + expect(result.queryByTestId('datastreamAddCustomIngestPipelineBtn')).not.toBeNull(); + expect(result.queryAllByTestId('datastreamInspectPipelineBtn')).toHaveLength(1); + expect(result.queryAllByTestId('datastreamEditPipelineBtn')).toHaveLength(0); + }); + + it('should render without a add button if there is a pipeline', () => { + const renderer = createFleetTestRendererMock(); + mockedUseGetPipeline.mockReturnValue({ + isLoading: false, + data: { + name: 'test', + }, + } as any); + + const result = renderer.render( + + ); + + expect(result.queryByTestId('datastreamAddCustomIngestPipelineBtn')).toBeNull(); + expect(result.queryAllByTestId('datastreamInspectPipelineBtn')).toHaveLength(2); + expect(result.queryAllByTestId('datastreamEditPipelineBtn')).toHaveLength(1); + }); +}); diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_pipelines.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_pipelines.tsx index 61d7c5d431272..8f1fe7d5846a3 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_pipelines.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_pipelines.tsx @@ -6,6 +6,8 @@ */ import React, { useMemo } from 'react'; +import { useRouteMatch } from 'react-router-dom'; +import { i18n } from '@kbn/i18n'; import { EuiBasicTable, EuiButtonEmpty, @@ -18,18 +20,16 @@ import { } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n-react'; -import type { RegistryStream, PackageInfo, NewPackagePolicy } from '../../../../../../types'; +import type { PackageInfo } from '../../../../../../types'; import { useStartServices, useGetPipeline, useLink } from '../../../../../../hooks'; import { getPipelineNameForDatastream, getCustomPipelineNameForDatastream, } from '../../../../../../../../../common'; -import { useRouteMatch } from 'react-router'; interface Props { - packagePolicy: NewPackagePolicy; packageInfo: PackageInfo; - packageInputStream: RegistryStream & { data_stream: { dataset: string; type: string } }; + dataStream: { dataset: string; type: string }; } interface PipelineItem { @@ -43,12 +43,8 @@ function toPipelineItem(pipelineName: string, canEdit = false): PipelineItem { function useDatastreamIngestPipelines( packageInfo: PackageInfo, - dataStream?: { dataset: string; type: string } + dataStream: { dataset: string; type: string } ) { - if (!dataStream) { - return { pipelines: [] }; - } - const defaultPipelineName = getPipelineNameForDatastream({ dataStream, packageVersion: packageInfo.version, @@ -72,9 +68,8 @@ function useDatastreamIngestPipelines( }; } -export const DatastreamPipeline: React.FunctionComponent = ({ - packagePolicy, - packageInputStream, +export const DatastreamPipelines: React.FunctionComponent = ({ + dataStream, packageInfo, }) => { const { @@ -90,15 +85,12 @@ export const DatastreamPipeline: React.FunctionComponent = ({ }) : null; - const { application, share } = useStartServices(); + const { application, share, docLinks } = useStartServices(); const ingestPipelineLocator = share.url.locators.get('INGEST_PIPELINES_APP_LOCATOR'); - const { pipelines, hasCustom } = useDatastreamIngestPipelines( - packageInfo, - packageInputStream.data_stream - ); + const { pipelines, hasCustom, isLoading } = useDatastreamIngestPipelines(packageInfo, dataStream); - if (!packageInputStream.data_stream) { + if (!dataStream) { return null; } @@ -121,10 +113,10 @@ export const DatastreamPipeline: React.FunctionComponent = ({ defaultMessage="Ingest pipelines perform common transformations on the ingested data. We recommend modifying only the custom ingest pipeline. These pipelines are shared between integration policies of the same integration type. Hence, any modifications tot he ingest pipelines would affect all the integration policies. {learnMoreLink}" values={{ learnMoreLink: ( - + ), @@ -134,6 +126,7 @@ export const DatastreamPipeline: React.FunctionComponent = ({ = ({ { icon: 'pencil', type: 'icon', - description: 'edit', - name: 'inspect', + description: i18n.translate( + 'xpack.fleet.packagePolicyEdotpr.datastreamIngestPipelines.editBtn', + { + defaultMessage: 'Edit pipeline', + } + ), + 'data-test-subj': 'datastreamEditPipelineBtn', + name: 'edit', isPrimary: true, onClick: async (el) => { if (!ingestPipelineLocator) { @@ -165,8 +164,14 @@ export const DatastreamPipeline: React.FunctionComponent = ({ { icon: 'inspect', type: 'icon', - description: 'test', + description: i18n.translate( + 'xpack.fleet.packagePolicyEditor.datastreamIngestPipelines.inspectBtn', + { + defaultMessage: 'Inspect pipeline', + } + ), name: 'inspect', + 'data-test-subj': 'datastreamInspectPipelineBtn', isPrimary: true, onClick: async (el) => { if (!ingestPipelineLocator) { @@ -186,12 +191,17 @@ export const DatastreamPipeline: React.FunctionComponent = ({ ]} /> - {!hasCustom && ( + {!isLoading && !hasCustom && ( - + diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/index.ts b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/index.ts index eb72dcc4b7a12..72c86584a8da8 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/index.ts +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/index.ts @@ -7,5 +7,5 @@ export { PackagePolicyInputPanel } from './package_policy_input_panel'; export { PackagePolicyInputVarField } from './package_policy_input_var_field'; -export { DatastreamPipeline } from './datastream_pipelines'; +export { DatastreamPipelines } from './datastream_pipelines'; export { DatastreamMappings } from './datastream_mappings'; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/package_policy_input_stream.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/package_policy_input_stream.tsx index 8a0c7af1a2648..7a5722c5922a8 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/package_policy_input_stream.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/package_policy_input_stream.tsx @@ -30,7 +30,7 @@ import type { PackagePolicyConfigValidationResults } from '../../../services'; import { isAdvancedVar, validationHasErrors } from '../../../services'; import { PackagePolicyInputVarField } from './package_policy_input_var_field'; -import { DatastreamPipeline } from './datastream_pipelines'; +import { DatastreamPipelines } from './datastream_pipelines'; import { DatastreamMappings } from './datastream_mappings'; const FlexItemWithMaxWidth = styled(EuiFlexItem)` @@ -61,20 +61,22 @@ export const PackagePolicyInputStreamConfig: React.FunctionComponent<{ // Errors state const hasErrors = forceShowErrors && validationHasErrors(inputStreamValidationResults); - const requiredVars: RegistryVarsEntry[] = []; - const advancedVars: RegistryVarsEntry[] = []; + const [requiredVars, advancedVars] = useMemo(() => { + const _requiredVars: RegistryVarsEntry[] = []; + const _advancedVars: RegistryVarsEntry[] = []; - const allowCustomIngestPipeline = true; + if (packageInputStream.vars && packageInputStream.vars.length) { + packageInputStream.vars.forEach((varDef) => { + if (isAdvancedVar(varDef)) { + _advancedVars.push(varDef); + } else { + _requiredVars.push(varDef); + } + }); + } - if (packageInputStream.vars && packageInputStream.vars.length) { - packageInputStream.vars.forEach((varDef) => { - if (isAdvancedVar(varDef)) { - advancedVars.push(varDef); - } else { - requiredVars.push(varDef); - } - }); - } + return [_requiredVars, _advancedVars]; + }, [packageInputStream.vars]); const advancedVarsWithErrorsCount: number = useMemo( () => @@ -144,82 +146,80 @@ export const PackagePolicyInputStreamConfig: React.FunctionComponent<{ ); })} - {advancedVars.length || allowCustomIngestPipeline ? ( - - - + {/* Advenced section */} + + + + + setIsShowingAdvanced(!isShowingAdvanced)} + flush="left" + > + + + + {!isShowingAdvanced && hasErrors && advancedVarsWithErrorsCount ? ( - setIsShowingAdvanced(!isShowingAdvanced)} - flush="left" - > + - + - {!isShowingAdvanced && hasErrors && advancedVarsWithErrorsCount ? ( - - - - - - ) : null} - - - {isShowingAdvanced ? ( - <> - {advancedVars.map((varDef) => { - if (!packagePolicyInputStream.vars) return null; - const { name: varName, type: varType } = varDef; - const value = packagePolicyInputStream.vars?.[varName]?.value; + ) : null} + + + {isShowingAdvanced ? ( + <> + {advancedVars.map((varDef) => { + if (!packagePolicyInputStream.vars) return null; + const { name: varName, type: varType } = varDef; + const value = packagePolicyInputStream.vars?.[varName]?.value; - return ( - - { - updatePackagePolicyInputStream({ - vars: { - ...packagePolicyInputStream.vars, - [varName]: { - type: varType, - value: newValue, - }, + return ( + + { + updatePackagePolicyInputStream({ + vars: { + ...packagePolicyInputStream.vars, + [varName]: { + type: varType, + value: newValue, }, - }); - }} - errors={inputStreamValidationResults?.vars![varName]} - forceShowErrors={forceShowErrors} - /> - - ); - })} - - - - - - - - ) : null} - - ) : null} + }, + }); + }} + errors={inputStreamValidationResults?.vars![varName]} + forceShowErrors={forceShowErrors} + /> + + ); + })} + + + + + + + + ) : null} + From 7c68e1df211967721ba5d83a22386ceafbdae399 Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Thu, 23 Jun 2022 09:42:35 -0400 Subject: [PATCH 08/13] Datastream mappings component --- x-pack/plugins/fleet/common/constants/epm.ts | 3 + .../services/datastream_es_name.test.ts | 36 ++++- .../common/services/datastream_es_name.ts | 29 ++++ x-pack/plugins/fleet/common/services/index.ts | 2 + .../components/datastream_mappings.tsx | 144 ++++++++++++++++++ .../datastream_pipelines.test.tsx | 14 +- .../components => }/datastream_pipelines.tsx | 21 ++- .../components/index.ts | 4 + .../steps/components/datastream_mappings.tsx | 92 ----------- .../components/steps/components/index.ts | 2 - .../package_policy_input_stream.tsx | 10 +- x-pack/plugins/fleet/public/index.ts | 9 ++ .../fleet/server/constants/fleet_es_assets.ts | 4 - .../plugins/fleet/server/constants/index.ts | 5 +- .../services/epm/elasticsearch/index.test.ts | 39 ----- .../services/epm/elasticsearch/index.ts | 17 --- .../elasticsearch/template/remove_legacy.ts | 2 +- .../epm/elasticsearch/template/template.ts | 2 +- 18 files changed, 253 insertions(+), 182 deletions(-) create mode 100644 x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/datastream_mappings.tsx rename x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/{steps/components => }/datastream_pipelines.test.tsx (84%) rename x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/{steps/components => }/datastream_pipelines.tsx (92%) delete mode 100644 x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx delete mode 100644 x-pack/plugins/fleet/server/services/epm/elasticsearch/index.test.ts delete mode 100644 x-pack/plugins/fleet/server/services/epm/elasticsearch/index.ts diff --git a/x-pack/plugins/fleet/common/constants/epm.ts b/x-pack/plugins/fleet/common/constants/epm.ts index 07f6fa048dc42..776691a895c17 100644 --- a/x-pack/plugins/fleet/common/constants/epm.ts +++ b/x-pack/plugins/fleet/common/constants/epm.ts @@ -18,6 +18,9 @@ export const FLEET_SYNTHETICS_PACKAGE = 'synthetics'; export const FLEET_KUBERNETES_PACKAGE = 'kubernetes'; export const FLEET_CLOUD_SECURITY_POSTURE_PACKAGE = 'cloud_security_posture'; +export const PACKAGE_TEMPLATE_SUFFIX = '@package'; +export const USER_SETTINGS_TEMPLATE_SUFFIX = '@custom'; + export const FLEET_ELASTIC_AGENT_DETAILS_DASHBOARD_ID = 'elastic_agent-f47f18cc-9c7d-4278-b2ea-a6dee816d395'; /* diff --git a/x-pack/plugins/fleet/common/services/datastream_es_name.test.ts b/x-pack/plugins/fleet/common/services/datastream_es_name.test.ts index 1b8d8c8ccde7c..8e1eb3b1b9f12 100644 --- a/x-pack/plugins/fleet/common/services/datastream_es_name.test.ts +++ b/x-pack/plugins/fleet/common/services/datastream_es_name.test.ts @@ -5,7 +5,10 @@ * 2.0. */ -import { getCustomPipelineNameForDatastream } from './datastream_es_name'; +import { + getCustomPipelineNameForDatastream, + getRegistryDataStreamAssetBaseName, +} from './datastream_es_name'; describe('getCustomPipelineNameForDatastream', () => { it('return the correct custom pipeline for datastream', () => { @@ -17,3 +20,34 @@ describe('getCustomPipelineNameForDatastream', () => { expect(res).toBe('logs-test@custom'); }); }); + +describe('getRegistryDataStreamAssetBaseName', () => { + it('return the asset name', () => { + const dataStream = { + dataset: 'nginx.access', + title: 'Nginx Acess Logs', + release: 'beta', + type: 'logs', + ingest_pipeline: 'default', + package: 'nginx', + path: 'access', + }; + const name = getRegistryDataStreamAssetBaseName(dataStream); + expect(name).toStrictEqual('logs-nginx.access'); + }); + + it('return the asset name for hidden index', () => { + const dataStream = { + dataset: 'nginx.access', + title: 'Nginx Acess Logs', + release: 'beta', + type: 'logs', + ingest_pipeline: 'default', + package: 'nginx', + path: 'access', + hidden: true, + }; + const name = getRegistryDataStreamAssetBaseName(dataStream); + expect(name).toStrictEqual('.logs-nginx.access'); + }); +}); diff --git a/x-pack/plugins/fleet/common/services/datastream_es_name.ts b/x-pack/plugins/fleet/common/services/datastream_es_name.ts index d94d84d064d5a..077f1f5f0dc7f 100644 --- a/x-pack/plugins/fleet/common/services/datastream_es_name.ts +++ b/x-pack/plugins/fleet/common/services/datastream_es_name.ts @@ -5,6 +5,35 @@ * 2.0. */ +import type { USER_SETTINGS_TEMPLATE_SUFFIX, PACKAGE_TEMPLATE_SUFFIX } from '../constants'; + +/** + * Creates the base name for Elasticsearch assets in the form of + * {type}-{dataset} + */ +export function getRegistryDataStreamAssetBaseName(dataStream: { + dataset: string; + type: string; + hidden?: boolean; +}): string { + const baseName = `${dataStream.type}-${dataStream.dataset}`; + return dataStream.hidden ? `.${baseName}` : baseName; +} + +/** + * Return the name for a component template + */ +export function getComponentTemplateNameForDatastream( + dataStream: { + dataset: string; + type: string; + hidden?: boolean; + }, + suffix?: typeof PACKAGE_TEMPLATE_SUFFIX | typeof USER_SETTINGS_TEMPLATE_SUFFIX +): string { + return `${getRegistryDataStreamAssetBaseName(dataStream)}${suffix ?? ''}`; +} + /** * Return the ingest pipeline name for a datastream */ diff --git a/x-pack/plugins/fleet/common/services/index.ts b/x-pack/plugins/fleet/common/services/index.ts index 55a04bcfdf6ae..3774abb1cc4b3 100644 --- a/x-pack/plugins/fleet/common/services/index.ts +++ b/x-pack/plugins/fleet/common/services/index.ts @@ -39,4 +39,6 @@ export { getMinVersion, getMaxVersion } from './get_min_max_version'; export { getPipelineNameForDatastream, getCustomPipelineNameForDatastream, + getRegistryDataStreamAssetBaseName, + getComponentTemplateNameForDatastream, } from './datastream_es_name'; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/datastream_mappings.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/datastream_mappings.tsx new file mode 100644 index 0000000000000..67fea7d444e00 --- /dev/null +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/datastream_mappings.tsx @@ -0,0 +1,144 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import React from 'react'; +import { EuiBasicTable, EuiFlexGroup, EuiFlexItem, EuiText, EuiTitle, EuiLink } from '@elastic/eui'; +import { FormattedMessage } from '@kbn/i18n-react'; +import { i18n } from '@kbn/i18n'; +import { useRouteMatch } from 'react-router-dom'; + +import type { PackageInfo } from '../../../../types'; +import { getComponentTemplateNameForDatastream } from '../../../../../../../common'; +import { useLink, useStartServices } from '../../../../hooks'; + +export interface PackagePolicyEditorDatastreamMappingsProps { + packageInfo: PackageInfo; + dataStream: { dataset: string; type: string }; +} + +function useComponentTemplates(dataStream: { dataset: string; type: string }) { + return [ + { + templateName: getComponentTemplateNameForDatastream(dataStream, '@package'), + }, + { + templateName: getComponentTemplateNameForDatastream(dataStream, '@custom'), + canEdit: true, + }, + ]; +} + +// Work in progress only here for demo for now +export const PackagePolicyEditorDatastreamMappings: React.FunctionComponent< + PackagePolicyEditorDatastreamMappingsProps +> = ({ dataStream, packageInfo }) => { + const { + params: { packagePolicyId, policyId }, + } = useRouteMatch<{ policyId: string; packagePolicyId: string }>(); + const { getHref } = useLink(); + + const pageUrl = + packagePolicyId && policyId + ? getHref('edit_integration', { + policyId, + packagePolicyId, + }) + : null; + + const { application, docLinks } = useStartServices(); + const componentTemplateItems = useComponentTemplates(dataStream); + + return ( + + + +
+ +
+
+
+ + + + + + ), + }} + /> + + + + { + const url = application.getUrlForApp('management', { + path: `/data/index_management/edit_component_template/${el.templateName}`, + }); + + application.navigateToUrl(`${url}?redirect_path=${pageUrl}`); + }, + available: ({ canEdit }) => !!canEdit, + }, + { + icon: 'inspect', + type: 'icon', + description: i18n.translate( + 'xpack.fleet.packagePolicyEditor.datastreamMappings.inspectBtn', + { + defaultMessage: 'Inspect mappings', + } + ), + name: 'inspect', + 'data-test-subj': 'datastreamInspectMappingsBtn', + isPrimary: true, + onClick: async (el) => { + const url = application.getUrlForApp('management', { + path: `/data/index_management/component_templates/${el.templateName}`, + }); + + application.navigateToUrl(`${url}?redirect_path=${pageUrl}`); + }, + }, + ], + }, + ]} + /> + +
+ ); +}; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_pipelines.test.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/datastream_pipelines.test.tsx similarity index 84% rename from x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_pipelines.test.tsx rename to x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/datastream_pipelines.test.tsx index 333b16393fd74..a68facb62c3b4 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_pipelines.test.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/datastream_pipelines.test.tsx @@ -7,16 +7,16 @@ import React from 'react'; -import { createFleetTestRendererMock } from '../../../../../../../../mock'; -import { useGetPipeline } from '../../../../../../hooks'; +import { createFleetTestRendererMock } from '../../../../../../mock'; +import { useGetPipeline } from '../../../../hooks'; -import { DatastreamPipelines } from './datastream_pipelines'; +import { PackagePolicyEditorDatastreamPipelines } from './datastream_pipelines'; const mockedUseGetPipeline = useGetPipeline as jest.MockedFunction; -jest.mock('../../../../../../hooks', () => { +jest.mock('../../../../hooks', () => { return { - ...jest.requireActual('../../../../../../hooks'), + ...jest.requireActual('../../../../hooks'), FleetStatusProvider: (props: any) => { return props.children; }, @@ -36,7 +36,7 @@ describe('DatastreamPipelines', () => { } as any); const result = renderer.render( - { } as any); const result = renderer.render( - = ({ - dataStream, - packageInfo, -}) => { +export const PackagePolicyEditorDatastreamPipelines: React.FunctionComponent< + PackagePolicyEditorDatastreamPipelinesProps +> = ({ dataStream, packageInfo }) => { const { params: { packagePolicyId, policyId }, } = useRouteMatch<{ policyId: string; packagePolicyId: string }>(); @@ -100,7 +99,7 @@ export const DatastreamPipelines: React.FunctionComponent = ({
@@ -109,7 +108,7 @@ export const DatastreamPipelines: React.FunctionComponent = ({ = ({ icon: 'pencil', type: 'icon', description: i18n.translate( - 'xpack.fleet.packagePolicyEdotpr.datastreamIngestPipelines.editBtn', + 'xpack.fleet.packagePolicyEditor.datastreamIngestPipelines.editBtn', { defaultMessage: 'Edit pipeline', } diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/index.ts b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/index.ts index 08099f4078a08..b81947f49e65b 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/index.ts +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/index.ts @@ -7,3 +7,7 @@ export { IntegrationBreadcrumb } from './integration_breadcrumb'; export * from './steps'; +export { PackagePolicyEditorDatastreamPipelines } from './datastream_pipelines'; +export type { PackagePolicyEditorDatastreamPipelinesProps } from './datastream_pipelines'; +export { PackagePolicyEditorDatastreamMappings } from './datastream_mappings'; +export type { PackagePolicyEditorDatastreamMappingsProps } from './datastream_mappings'; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx deleted file mode 100644 index 0eae8ba0ea4cb..0000000000000 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/datastream_mappings.tsx +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import React from 'react'; -import { EuiBasicTable, EuiFlexGroup, EuiFlexItem, EuiText, EuiTitle, EuiLink } from '@elastic/eui'; -import { FormattedMessage } from '@kbn/i18n-react'; - -import type { RegistryStream, PackageInfo } from '../../../../../../types'; -import { getPipelineNameForDatastream } from '../../../../../../../../../common'; - -interface Props { - packagePolicyId?: string; - packageInfo: PackageInfo; - packageInputStream: RegistryStream & { data_stream: { dataset: string; type: string } }; -} - -// Work in progress only here for demo for now -export const DatastreamMappings: React.FunctionComponent = ({ - packagePolicyId, - packageInputStream, - packageInfo, -}) => { - if (!packageInputStream.data_stream) { - return null; - } - - const defaultPipelineName = getPipelineNameForDatastream({ - dataStream: packageInputStream.data_stream, - packageVersion: packageInfo.version, - }); - - return ( - - - -
- -
-
-
- - - - - - ), - }} - /> - - - - {}, - }, - ], - }, - ]} - /> - -
- ); -}; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/index.ts b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/index.ts index 72c86584a8da8..a12c67b7d51ad 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/index.ts +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/index.ts @@ -7,5 +7,3 @@ export { PackagePolicyInputPanel } from './package_policy_input_panel'; export { PackagePolicyInputVarField } from './package_policy_input_var_field'; -export { DatastreamPipelines } from './datastream_pipelines'; -export { DatastreamMappings } from './datastream_mappings'; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/package_policy_input_stream.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/package_policy_input_stream.tsx index 7a5722c5922a8..c9d16f6e79fc6 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/package_policy_input_stream.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/package_policy_input_stream.tsx @@ -28,10 +28,10 @@ import type { } from '../../../../../../types'; import type { PackagePolicyConfigValidationResults } from '../../../services'; import { isAdvancedVar, validationHasErrors } from '../../../services'; +import { PackagePolicyEditorDatastreamPipelines } from '../../datastream_pipelines'; +import { PackagePolicyEditorDatastreamMappings } from '../../datastream_mappings'; import { PackagePolicyInputVarField } from './package_policy_input_var_field'; -import { DatastreamPipelines } from './datastream_pipelines'; -import { DatastreamMappings } from './datastream_mappings'; const FlexItemWithMaxWidth = styled(EuiFlexItem)` max-width: calc(50% - ${(props) => props.theme.eui.euiSizeL}); @@ -206,14 +206,14 @@ export const PackagePolicyInputStreamConfig: React.FunctionComponent<{ ); })} - - diff --git a/x-pack/plugins/fleet/public/index.ts b/x-pack/plugins/fleet/public/index.ts index 25714ead50a30..8d61b7a38c8d4 100644 --- a/x-pack/plugins/fleet/public/index.ts +++ b/x-pack/plugins/fleet/public/index.ts @@ -26,3 +26,12 @@ export { pagePathGetters } from './constants'; export { pkgKeyFromPackageInfo } from './services'; export type { CustomAssetsAccordionProps } from './components/custom_assets_accordion'; export { CustomAssetsAccordion } from './components/custom_assets_accordion'; +// Export Package editor components for custom editors +export { + PackagePolicyEditorDatastreamPipelines, + PackagePolicyEditorDatastreamMappings, +} from './applications/fleet/sections/agent_policy/create_package_policy_page/components'; +export type { + PackagePolicyEditorDatastreamPipelinesProps, + PackagePolicyEditorDatastreamMappingsProps, +} from './applications/fleet/sections/agent_policy/create_package_policy_page/components'; diff --git a/x-pack/plugins/fleet/server/constants/fleet_es_assets.ts b/x-pack/plugins/fleet/server/constants/fleet_es_assets.ts index 56aaf450d46e9..ded329ba79bab 100644 --- a/x-pack/plugins/fleet/server/constants/fleet_es_assets.ts +++ b/x-pack/plugins/fleet/server/constants/fleet_es_assets.ts @@ -9,10 +9,6 @@ import { getESAssetMetadata } from '../services/epm/elasticsearch/meta'; const meta = getESAssetMetadata(); -export const PACKAGE_TEMPLATE_SUFFIX = '@package'; - -export const USER_SETTINGS_TEMPLATE_SUFFIX = '@custom'; - export const FLEET_FINAL_PIPELINE_ID = '.fleet_final_pipeline-1'; export const FLEET_GLOBALS_COMPONENT_TEMPLATE_NAME = '.fleet_globals-1'; diff --git a/x-pack/plugins/fleet/server/constants/index.ts b/x-pack/plugins/fleet/server/constants/index.ts index 813f381ecc4fc..3ad16beee9198 100644 --- a/x-pack/plugins/fleet/server/constants/index.ts +++ b/x-pack/plugins/fleet/server/constants/index.ts @@ -55,6 +55,9 @@ export { PRECONFIGURATION_DELETION_RECORD_SAVED_OBJECT_TYPE, PRECONFIGURATION_LATEST_KEYWORD, AUTO_UPDATE_PACKAGES, + // EPM + USER_SETTINGS_TEMPLATE_SUFFIX, + PACKAGE_TEMPLATE_SUFFIX, } from '../../common'; export { @@ -66,6 +69,4 @@ export { FLEET_FINAL_PIPELINE_ID, FLEET_FINAL_PIPELINE_CONTENT, FLEET_FINAL_PIPELINE_VERSION, - USER_SETTINGS_TEMPLATE_SUFFIX, - PACKAGE_TEMPLATE_SUFFIX, } from './fleet_es_assets'; diff --git a/x-pack/plugins/fleet/server/services/epm/elasticsearch/index.test.ts b/x-pack/plugins/fleet/server/services/epm/elasticsearch/index.test.ts deleted file mode 100644 index fb89c117ae16b..0000000000000 --- a/x-pack/plugins/fleet/server/services/epm/elasticsearch/index.test.ts +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import type { RegistryDataStream } from '../../../types'; - -import { getRegistryDataStreamAssetBaseName } from '.'; - -test('getBaseName', () => { - const dataStream: RegistryDataStream = { - dataset: 'nginx.access', - title: 'Nginx Acess Logs', - release: 'beta', - type: 'logs', - ingest_pipeline: 'default', - package: 'nginx', - path: 'access', - }; - const name = getRegistryDataStreamAssetBaseName(dataStream); - expect(name).toStrictEqual('logs-nginx.access'); -}); - -test('getBaseName for hidden index', () => { - const dataStream: RegistryDataStream = { - dataset: 'nginx.access', - title: 'Nginx Acess Logs', - release: 'beta', - type: 'logs', - ingest_pipeline: 'default', - package: 'nginx', - path: 'access', - hidden: true, - }; - const name = getRegistryDataStreamAssetBaseName(dataStream); - expect(name).toStrictEqual('.logs-nginx.access'); -}); diff --git a/x-pack/plugins/fleet/server/services/epm/elasticsearch/index.ts b/x-pack/plugins/fleet/server/services/epm/elasticsearch/index.ts deleted file mode 100644 index 81e05ef7d6314..0000000000000 --- a/x-pack/plugins/fleet/server/services/epm/elasticsearch/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import type { RegistryDataStream } from '../../../types'; - -/** - * Creates the base name for Elasticsearch assets in the form of - * {type}-{dataset} - */ -export function getRegistryDataStreamAssetBaseName(dataStream: RegistryDataStream): string { - const baseName = `${dataStream.type}-${dataStream.dataset}`; - return dataStream.hidden ? `.${baseName}` : baseName; -} diff --git a/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/remove_legacy.ts b/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/remove_legacy.ts index 44b9756edc448..b89f5f8a7355a 100644 --- a/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/remove_legacy.ts +++ b/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/remove_legacy.ts @@ -12,7 +12,7 @@ import type { import type { ElasticsearchClient, Logger } from '@kbn/core/server'; import type { InstallablePackage, RegistryDataStream } from '../../../../types'; -import { getRegistryDataStreamAssetBaseName } from '..'; +import { getRegistryDataStreamAssetBaseName } from '../../../../../common'; const LEGACY_TEMPLATE_SUFFIXES = ['@mappings', '@settings']; const getComponentTemplateWithSuffix = (dataStream: RegistryDataStream, suffix: string) => { diff --git a/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/template.ts b/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/template.ts index c87df0921e745..02c5508321db9 100644 --- a/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/template.ts +++ b/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/template.ts @@ -16,7 +16,7 @@ import type { IndexTemplateMappings, } from '../../../../types'; import { appContextService } from '../../..'; -import { getRegistryDataStreamAssetBaseName } from '..'; +import { getRegistryDataStreamAssetBaseName } from '../../../../../common'; import { FLEET_GLOBALS_COMPONENT_TEMPLATE_NAME, FLEET_AGENT_ID_VERIFY_COMPONENT_TEMPLATE_NAME, From 93ef1b8ce0f07828c16178cd3c21aa15c86a9309 Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Thu, 23 Jun 2022 10:09:07 -0400 Subject: [PATCH 09/13] few fixes --- .../components/datastream_mappings.tsx | 5 +-- .../components/datastream_pipelines.tsx | 36 ++++++++++++++++--- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/datastream_mappings.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/datastream_mappings.tsx index 67fea7d444e00..1044dd0651e56 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/datastream_mappings.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/datastream_mappings.tsx @@ -32,7 +32,6 @@ function useComponentTemplates(dataStream: { dataset: string; type: string }) { ]; } -// Work in progress only here for demo for now export const PackagePolicyEditorDatastreamMappings: React.FunctionComponent< PackagePolicyEditorDatastreamMappingsProps > = ({ dataStream, packageInfo }) => { @@ -47,7 +46,9 @@ export const PackagePolicyEditorDatastreamMappings: React.FunctionComponent< policyId, packagePolicyId, }) - : null; + : getHref('integration_policy_edit', { + packagePolicyId, + }); const { application, docLinks } = useStartServices(); const componentTemplateItems = useComponentTemplates(dataStream); diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/datastream_pipelines.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/datastream_pipelines.tsx index a5efb69f6575e..46132f1690d1f 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/datastream_pipelines.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/datastream_pipelines.tsx @@ -5,7 +5,7 @@ * 2.0. */ -import React, { useMemo } from 'react'; +import React, { useEffect, useMemo, useState } from 'react'; import { useRouteMatch } from 'react-router-dom'; import { i18n } from '@kbn/i18n'; import { @@ -43,8 +43,14 @@ function toPipelineItem(pipelineName: string, canEdit = false): PipelineItem { function useDatastreamIngestPipelines( packageInfo: PackageInfo, - dataStream: { dataset: string; type: string } + dataStream: { dataset: string; type: string }, + pageUrl: string | null ) { + const [addPipelineUrl, setAddPipelineUrl] = useState(''); + + const { share } = useStartServices(); + const ingestPipelineLocator = share.url.locators.get('INGEST_PIPELINES_APP_LOCATOR'); + const defaultPipelineName = getPipelineNameForDatastream({ dataStream, packageVersion: packageInfo.version, @@ -61,10 +67,25 @@ function useDatastreamIngestPipelines( return [toPipelineItem(defaultPipelineName)]; }, [defaultPipelineName, customPipelineName, res.data]); + useEffect(() => { + async function getUrl() { + if (!ingestPipelineLocator) { + return; + } + const createUrl = await ingestPipelineLocator.getUrl({ + page: 'pipeline_create', + }); + setAddPipelineUrl(`${createUrl}?name=${customPipelineName}&redirect_path=${pageUrl}`); + } + + getUrl(); + }, [customPipelineName, pageUrl, ingestPipelineLocator]); + return { isLoading: res.isLoading, hasCustom: !res.isLoading && res.error?.statusCode !== 404, pipelines, + addPipelineUrl, }; } @@ -82,12 +103,18 @@ export const PackagePolicyEditorDatastreamPipelines: React.FunctionComponent< policyId, packagePolicyId, }) - : null; + : getHref('integration_policy_edit', { + packagePolicyId, + }); const { application, share, docLinks } = useStartServices(); const ingestPipelineLocator = share.url.locators.get('INGEST_PIPELINES_APP_LOCATOR'); - const { pipelines, hasCustom, isLoading } = useDatastreamIngestPipelines(packageInfo, dataStream); + const { pipelines, addPipelineUrl, hasCustom, isLoading } = useDatastreamIngestPipelines( + packageInfo, + dataStream, + pageUrl + ); if (!dataStream) { return null; @@ -198,6 +225,7 @@ export const PackagePolicyEditorDatastreamPipelines: React.FunctionComponent< flush="left" iconType="plusInCircle" data-test-subj="datastreamAddCustomIngestPipelineBtn" + href={addPipelineUrl} > Date: Thu, 23 Jun 2022 10:43:06 -0400 Subject: [PATCH 10/13] Remove unused tsconfig --- x-pack/plugins/fleet/tsconfig.json | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/plugins/fleet/tsconfig.json b/x-pack/plugins/fleet/tsconfig.json index b88a2605067e3..d0361f4550576 100644 --- a/x-pack/plugins/fleet/tsconfig.json +++ b/x-pack/plugins/fleet/tsconfig.json @@ -30,7 +30,6 @@ { "path": "../security/tsconfig.json" }, { "path": "../features/tsconfig.json" }, { "path": "../cloud/tsconfig.json" }, - { "path": "../ingest_pipelines/tsconfig.json" }, { "path": "../../../src/plugins/usage_collection/tsconfig.json" }, { "path": "../../../src/plugins/home/tsconfig.json" }, From 3f98301ee5dec899f6ff28fba4122cdf529d8837 Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Thu, 23 Jun 2022 12:13:55 -0400 Subject: [PATCH 11/13] Fix after review --- .../components/datastream_hooks.tsx | 26 +++++++++++++++++++ .../components/datastream_mappings.tsx | 20 +++----------- .../components/datastream_pipelines.tsx | 24 +++++------------ 3 files changed, 36 insertions(+), 34 deletions(-) create mode 100644 x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/datastream_hooks.tsx diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/datastream_hooks.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/datastream_hooks.tsx new file mode 100644 index 0000000000000..b8fd2fdcdc81d --- /dev/null +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/datastream_hooks.tsx @@ -0,0 +1,26 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { useRouteMatch } from 'react-router-dom'; + +import { useLink } from '../../../../hooks'; + +export function usePackagePolicyEditorPageUrl() { + const { + params: { packagePolicyId, policyId }, + } = useRouteMatch<{ policyId: string; packagePolicyId: string }>(); + const { getHref } = useLink(); + + return packagePolicyId && policyId + ? getHref('edit_integration', { + policyId, + packagePolicyId, + }) + : getHref('integration_policy_edit', { + packagePolicyId, + }); +} diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/datastream_mappings.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/datastream_mappings.tsx index 1044dd0651e56..8a2f056233041 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/datastream_mappings.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/datastream_mappings.tsx @@ -9,11 +9,12 @@ import React from 'react'; import { EuiBasicTable, EuiFlexGroup, EuiFlexItem, EuiText, EuiTitle, EuiLink } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n-react'; import { i18n } from '@kbn/i18n'; -import { useRouteMatch } from 'react-router-dom'; import type { PackageInfo } from '../../../../types'; import { getComponentTemplateNameForDatastream } from '../../../../../../../common'; -import { useLink, useStartServices } from '../../../../hooks'; +import { useStartServices } from '../../../../hooks'; + +import { usePackagePolicyEditorPageUrl } from './datastream_hooks'; export interface PackagePolicyEditorDatastreamMappingsProps { packageInfo: PackageInfo; @@ -35,20 +36,7 @@ function useComponentTemplates(dataStream: { dataset: string; type: string }) { export const PackagePolicyEditorDatastreamMappings: React.FunctionComponent< PackagePolicyEditorDatastreamMappingsProps > = ({ dataStream, packageInfo }) => { - const { - params: { packagePolicyId, policyId }, - } = useRouteMatch<{ policyId: string; packagePolicyId: string }>(); - const { getHref } = useLink(); - - const pageUrl = - packagePolicyId && policyId - ? getHref('edit_integration', { - policyId, - packagePolicyId, - }) - : getHref('integration_policy_edit', { - packagePolicyId, - }); + const pageUrl = usePackagePolicyEditorPageUrl(); const { application, docLinks } = useStartServices(); const componentTemplateItems = useComponentTemplates(dataStream); diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/datastream_pipelines.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/datastream_pipelines.tsx index 46132f1690d1f..33c1be4703121 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/datastream_pipelines.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/datastream_pipelines.tsx @@ -6,7 +6,6 @@ */ import React, { useEffect, useMemo, useState } from 'react'; -import { useRouteMatch } from 'react-router-dom'; import { i18n } from '@kbn/i18n'; import { EuiBasicTable, @@ -21,12 +20,14 @@ import { import { FormattedMessage } from '@kbn/i18n-react'; import type { PackageInfo } from '../../../../types'; -import { useStartServices, useGetPipeline, useLink } from '../../../../hooks'; +import { useStartServices, useGetPipeline } from '../../../../hooks'; import { getPipelineNameForDatastream, getCustomPipelineNameForDatastream, } from '../../../../../../../common'; +import { usePackagePolicyEditorPageUrl } from './datastream_hooks'; + export interface PackagePolicyEditorDatastreamPipelinesProps { packageInfo: PackageInfo; dataStream: { dataset: string; type: string }; @@ -92,24 +93,11 @@ function useDatastreamIngestPipelines( export const PackagePolicyEditorDatastreamPipelines: React.FunctionComponent< PackagePolicyEditorDatastreamPipelinesProps > = ({ dataStream, packageInfo }) => { - const { - params: { packagePolicyId, policyId }, - } = useRouteMatch<{ policyId: string; packagePolicyId: string }>(); - const { getHref } = useLink(); - - const pageUrl = - packagePolicyId && policyId - ? getHref('edit_integration', { - policyId, - packagePolicyId, - }) - : getHref('integration_policy_edit', { - packagePolicyId, - }); - const { application, share, docLinks } = useStartServices(); const ingestPipelineLocator = share.url.locators.get('INGEST_PIPELINES_APP_LOCATOR'); + const pageUrl = usePackagePolicyEditorPageUrl(); + const { pipelines, addPipelineUrl, hasCustom, isLoading } = useDatastreamIngestPipelines( packageInfo, dataStream, @@ -136,7 +124,7 @@ export const PackagePolicyEditorDatastreamPipelines: React.FunctionComponent< From a0cbfd5970bc3344e8491ac90e2b08e69ec2068c Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Thu, 23 Jun 2022 12:30:08 -0400 Subject: [PATCH 12/13] test file limit --- x-pack/plugins/fleet/public/index.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/fleet/public/index.ts b/x-pack/plugins/fleet/public/index.ts index 8d61b7a38c8d4..5f97cfa4d2740 100644 --- a/x-pack/plugins/fleet/public/index.ts +++ b/x-pack/plugins/fleet/public/index.ts @@ -27,11 +27,7 @@ export { pkgKeyFromPackageInfo } from './services'; export type { CustomAssetsAccordionProps } from './components/custom_assets_accordion'; export { CustomAssetsAccordion } from './components/custom_assets_accordion'; // Export Package editor components for custom editors -export { - PackagePolicyEditorDatastreamPipelines, - PackagePolicyEditorDatastreamMappings, -} from './applications/fleet/sections/agent_policy/create_package_policy_page/components'; -export type { - PackagePolicyEditorDatastreamPipelinesProps, - PackagePolicyEditorDatastreamMappingsProps, -} from './applications/fleet/sections/agent_policy/create_package_policy_page/components'; +export { PackagePolicyEditorDatastreamPipelines } from './applications/fleet/sections/agent_policy/create_package_policy_page/components/datastream_pipelines'; +export type { PackagePolicyEditorDatastreamPipelinesProps } from './applications/fleet/sections/agent_policy/create_package_policy_page/components/datastream_pipelines'; +export { PackagePolicyEditorDatastreamMappings } from './applications/fleet/sections/agent_policy/create_package_policy_page/components/datastream_mappings'; +export type { PackagePolicyEditorDatastreamMappingsProps } from './applications/fleet/sections/agent_policy/create_package_policy_page/components/datastream_mappings'; From fa64b82e8a61655b5eec9acb6d2787d2781c86b7 Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Thu, 23 Jun 2022 13:48:25 -0400 Subject: [PATCH 13/13] Fix after review --- packages/kbn-optimizer/limits.yml | 2 +- .../package_policy_input_stream.tsx | 150 ++++++++++-------- 2 files changed, 83 insertions(+), 69 deletions(-) diff --git a/packages/kbn-optimizer/limits.yml b/packages/kbn-optimizer/limits.yml index 29a396e371b9d..484f21d3eaac7 100644 --- a/packages/kbn-optimizer/limits.yml +++ b/packages/kbn-optimizer/limits.yml @@ -27,7 +27,7 @@ pageLoadAssetSize: indexLifecycleManagement: 107090 indexManagement: 140608 infra: 184320 - fleet: 100000 + fleet: 126917 ingestPipelines: 58003 inputControlVis: 172675 inspector: 148711 diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/package_policy_input_stream.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/package_policy_input_stream.tsx index c9d16f6e79fc6..54b3c1ac70cbe 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/package_policy_input_stream.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/package_policy_input_stream.tsx @@ -18,6 +18,7 @@ import { EuiSpacer, EuiButtonEmpty, } from '@elastic/eui'; +import { useRouteMatch } from 'react-router-dom'; import type { NewPackagePolicy, @@ -55,6 +56,12 @@ export const PackagePolicyInputStreamConfig: React.FunctionComponent<{ inputStreamValidationResults, forceShowErrors, }) => { + const { + params: { packagePolicyId }, + } = useRouteMatch<{ packagePolicyId?: string }>(); + + const isPackagePolicyEdit = !!packagePolicyId; + // Showing advanced options toggle state const [isShowingAdvanced, setIsShowingAdvanced] = useState(); @@ -146,80 +153,87 @@ export const PackagePolicyInputStreamConfig: React.FunctionComponent<{
); })} - {/* Advenced section */} - - - - - setIsShowingAdvanced(!isShowingAdvanced)} - flush="left" - > - - - - {!isShowingAdvanced && hasErrors && advancedVarsWithErrorsCount ? ( + {/* Advanced section */} + {(isPackagePolicyEdit || advancedVars.length) && ( + + + - + setIsShowingAdvanced(!isShowingAdvanced)} + flush="left" + > - + - ) : null} - - - {isShowingAdvanced ? ( - <> - {advancedVars.map((varDef) => { - if (!packagePolicyInputStream.vars) return null; - const { name: varName, type: varType } = varDef; - const value = packagePolicyInputStream.vars?.[varName]?.value; + {!isShowingAdvanced && hasErrors && advancedVarsWithErrorsCount ? ( + + + + + + ) : null} + + + {isShowingAdvanced ? ( + <> + {advancedVars.map((varDef) => { + if (!packagePolicyInputStream.vars) return null; + const { name: varName, type: varType } = varDef; + const value = packagePolicyInputStream.vars?.[varName]?.value; - return ( - - { - updatePackagePolicyInputStream({ - vars: { - ...packagePolicyInputStream.vars, - [varName]: { - type: varType, - value: newValue, + return ( + + { + updatePackagePolicyInputStream({ + vars: { + ...packagePolicyInputStream.vars, + [varName]: { + type: varType, + value: newValue, + }, }, - }, - }); - }} - errors={inputStreamValidationResults?.vars![varName]} - forceShowErrors={forceShowErrors} - /> - - ); - })} - - - - - - - - ) : null} - + }); + }} + errors={inputStreamValidationResults?.vars![varName]} + forceShowErrors={forceShowErrors} + /> + + ); + })} + {/* Only show datastream pipelines and mappings on edit */} + {isPackagePolicyEdit && ( + <> + + + + + + + + )} + + ) : null} + + )}