From 9171827333ea846b5d914b50454ebf5e274ada02 Mon Sep 17 00:00:00 2001 From: Simeon Widdis Date: Thu, 3 Aug 2023 09:58:55 -0700 Subject: [PATCH 1/5] Add integration name to created index mapping Signed-off-by: Simeon Widdis --- public/components/integrations/components/integration.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/public/components/integrations/components/integration.tsx b/public/components/integrations/components/integration.tsx index ad1a1dfe6..a85f82856 100644 --- a/public/components/integrations/components/integration.tsx +++ b/public/components/integrations/components/integration.tsx @@ -31,7 +31,7 @@ export function Integration(props: AvailableIntegrationProps) { const [isFlyoutVisible, setIsFlyoutVisible] = useState(false); const { setToast } = useToast(); - const [integration, setIntegration] = useState({}); + const [integration, setIntegration] = useState({} as { name: string; type: string }); const [integrationMapping, setMapping] = useState(null); const [integrationAssets, setAssets] = useState([]); @@ -67,7 +67,7 @@ export function Integration(props: AvailableIntegrationProps) { } else { payload.index_patterns = [dataSourceName]; return fetch( - `/api/console/proxy?path=_index_template/${componentName}_${version}&method=POST`, + `/api/console/proxy?path=_index_template/${integration.name}_${componentName}_${version}&method=POST`, { method: 'POST', headers: [ @@ -256,7 +256,7 @@ export function Integration(props: AvailableIntegrationProps) { const [selectedTabId, setSelectedTabId] = useState('assets'); - const onSelectedTabChanged = (id) => { + const onSelectedTabChanged = (id: string) => { setSelectedTabId(id); }; From d96c3bf985fb22b185e27e9a67c9be8b1e47c24e Mon Sep 17 00:00:00 2001 From: Simeon Widdis Date: Thu, 3 Aug 2023 10:03:46 -0700 Subject: [PATCH 2/5] Switch template naming to loosely reflect SS4O convention Signed-off-by: Simeon Widdis --- public/components/integrations/components/integration.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/components/integrations/components/integration.tsx b/public/components/integrations/components/integration.tsx index a85f82856..75f12bf52 100644 --- a/public/components/integrations/components/integration.tsx +++ b/public/components/integrations/components/integration.tsx @@ -67,7 +67,7 @@ export function Integration(props: AvailableIntegrationProps) { } else { payload.index_patterns = [dataSourceName]; return fetch( - `/api/console/proxy?path=_index_template/${integration.name}_${componentName}_${version}&method=POST`, + `/api/console/proxy?path=_index_template/ss4o_${componentName}_${version}_${integration.name}&method=POST`, { method: 'POST', headers: [ From ed1f2d71d228011af937b6f55ee7623ac8539edf Mon Sep 17 00:00:00 2001 From: Simeon Widdis Date: Thu, 3 Aug 2023 11:31:28 -0700 Subject: [PATCH 3/5] Split mapping creation by type for code clarity Signed-off-by: Simeon Widdis --- .../integrations/components/integration.tsx | 83 ++++++++++--------- 1 file changed, 43 insertions(+), 40 deletions(-) diff --git a/public/components/integrations/components/integration.tsx b/public/components/integrations/components/integration.tsx index 4ca8957d8..54c0b3001 100644 --- a/public/components/integrations/components/integration.tsx +++ b/public/components/integrations/components/integration.tsx @@ -37,7 +37,7 @@ export function Integration(props: AvailableIntegrationProps) { const [integrationAssets, setAssets] = useState([]); const [loading, setLoading] = useState(false); - const createMappings = async ( + const createComponentMapping = async ( componentName: string, payload: { template: { mappings: { _meta: { version: string } } }; @@ -47,39 +47,48 @@ export function Integration(props: AvailableIntegrationProps) { dataSourceName: string ): Promise<{ [key: string]: { properties: any } } | null> => { const version = payload.template.mappings._meta.version; - if (componentName !== integration.type) { - return http - .post('/api/console/proxy', { - body: JSON.stringify(payload), - query: { - path: `_component_template/ss4o_${componentName}_${version}_template`, - method: 'POST', - }, - }) - .catch((err: any) => { - console.error(err); - return err; - }); - } else { - payload.index_patterns = [dataSourceName]; - return http - .post('/api/console/proxy', { - body: JSON.stringify(payload), - query: { - path: `_index_template/ss4o_${componentName}_${version}_${integration.name}`, - method: 'POST', - }, - }) - .catch((err: any) => { - console.error(err); - return err; - }); - } + return http + .post('/api/console/proxy', { + body: JSON.stringify(payload), + query: { + path: `_component_template/ss4o_${componentName}_${version}_template`, + method: 'POST', + }, + }) + .catch((err: any) => { + console.error(err); + return err; + }); + }; + + const createIndexMapping = async ( + componentName: string, + payload: { + template: { mappings: { _meta: { version: string } } }; + composed_of: string[]; + index_patterns: string[]; + }, + dataSourceName: string + ): Promise<{ [key: string]: { properties: any } } | null> => { + const version = payload.template.mappings._meta.version; + payload.index_patterns = [dataSourceName]; + return http + .post('/api/console/proxy', { + body: JSON.stringify(payload), + query: { + path: `_index_template/ss4o_${componentName}_${version}_${integration.name}`, + method: 'POST', + }, + }) + .catch((err: any) => { + console.error(err); + return err; + }); }; const createDataSourceMappings = async (targetDataSource: string): Promise => { const data = await http.get(`${INTEGRATIONS_BASE}/repository/${integrationTemplateId}/schema`); - let error = null; + const error = null; const mappings = data.data.mappings; mappings[integration.type].composed_of = mappings[integration.type].composed_of.map( (templateName: string) => { @@ -87,21 +96,15 @@ export function Integration(props: AvailableIntegrationProps) { return `ss4o_${templateName}_${version}_template`; } ); + // Create component mappings before the index mapping + // The assumption is that index mapping relies on component mappings for creation Object.entries(mappings).forEach(async ([key, mapping]) => { if (key === integration.type) { return; } - await createMappings(key, mapping as any, targetDataSource); + await createComponentMapping(key, mapping as any, targetDataSource); }); - await createMappings(integration.type, mappings[integration.type], targetDataSource); - - for (const [key, mapping] of Object.entries(data.data.mappings)) { - const result = await createMappings(key, mapping as any, targetDataSource); - - if (result && result.error) { - error = (result.error as any).reason; - } - } + await createIndexMapping(integration.type, mappings[integration.type], targetDataSource); if (error !== null) { setToast('Failure creating index template', 'danger', error); From 0980a07da5c7db319e38015ce19a40e1d56d9d36 Mon Sep 17 00:00:00 2001 From: Simeon Widdis Date: Thu, 3 Aug 2023 14:17:43 -0700 Subject: [PATCH 4/5] Re-introduce confusing result block Signed-off-by: Simeon Widdis --- .../integrations/components/integration.tsx | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/public/components/integrations/components/integration.tsx b/public/components/integrations/components/integration.tsx index 54c0b3001..6f99c73dd 100644 --- a/public/components/integrations/components/integration.tsx +++ b/public/components/integrations/components/integration.tsx @@ -43,8 +43,7 @@ export function Integration(props: AvailableIntegrationProps) { template: { mappings: { _meta: { version: string } } }; composed_of: string[]; index_patterns: string[]; - }, - dataSourceName: string + } ): Promise<{ [key: string]: { properties: any } } | null> => { const version = payload.template.mappings._meta.version; return http @@ -88,7 +87,7 @@ export function Integration(props: AvailableIntegrationProps) { const createDataSourceMappings = async (targetDataSource: string): Promise => { const data = await http.get(`${INTEGRATIONS_BASE}/repository/${integrationTemplateId}/schema`); - const error = null; + let error = null; const mappings = data.data.mappings; mappings[integration.type].composed_of = mappings[integration.type].composed_of.map( (templateName: string) => { @@ -102,10 +101,21 @@ export function Integration(props: AvailableIntegrationProps) { if (key === integration.type) { return; } - await createComponentMapping(key, mapping as any, targetDataSource); + await createComponentMapping(key, mapping as any); }); await createIndexMapping(integration.type, mappings[integration.type], targetDataSource); + for (const [key, mapping] of Object.entries(data.data.mappings)) { + const result = + key === integration.type + ? await createIndexMapping(key, mapping as any, targetDataSource) + : await createComponentMapping(key, mapping as any); + + if (result && result.error) { + error = (result.error as any).reason; + } + } + if (error !== null) { setToast('Failure creating index template', 'danger', error); } else { From a3cecd3482aab72cade5341a0cd3e2407142f7d7 Mon Sep 17 00:00:00 2001 From: Simeon Widdis Date: Thu, 3 Aug 2023 17:09:23 -0700 Subject: [PATCH 5/5] Modify naming template to better match SS4O convention Signed-off-by: Simeon Widdis --- .../components/integrations/components/integration.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/public/components/integrations/components/integration.tsx b/public/components/integrations/components/integration.tsx index 6f99c73dd..93b934221 100644 --- a/public/components/integrations/components/integration.tsx +++ b/public/components/integrations/components/integration.tsx @@ -50,7 +50,7 @@ export function Integration(props: AvailableIntegrationProps) { .post('/api/console/proxy', { body: JSON.stringify(payload), query: { - path: `_component_template/ss4o_${componentName}_${version}_template`, + path: `_component_template/ss4o_${componentName}-${version}-template`, method: 'POST', }, }) @@ -75,7 +75,7 @@ export function Integration(props: AvailableIntegrationProps) { .post('/api/console/proxy', { body: JSON.stringify(payload), query: { - path: `_index_template/ss4o_${componentName}_${version}_${integration.name}`, + path: `_index_template/ss4o_${componentName}-${integration.name}-${version}-sample`, method: 'POST', }, }) @@ -90,9 +90,9 @@ export function Integration(props: AvailableIntegrationProps) { let error = null; const mappings = data.data.mappings; mappings[integration.type].composed_of = mappings[integration.type].composed_of.map( - (templateName: string) => { - const version = mappings[templateName].template.mappings._meta.version; - return `ss4o_${templateName}_${version}_template`; + (componentName: string) => { + const version = mappings[componentName].template.mappings._meta.version; + return `ss4o_${componentName}-${version}-template`; } ); // Create component mappings before the index mapping