Skip to content

Commit

Permalink
Use new fields in original integration creation request
Browse files Browse the repository at this point in the history
Signed-off-by: Simeon Widdis <[email protected]>
  • Loading branch information
Swiddis committed Apr 16, 2024
1 parent c1e8fdd commit 27890d0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
2 changes: 2 additions & 0 deletions docs/integrations/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ the author in hindsight.
If working on S3-based integrations, it's worth noting that queries have some values
[substituted](https://github.com/opensearch-project/dashboards-observability/blob/4e1e0e585/public/components/integrations/components/setup_integration.tsx#L438) when installing. They are:

- `{table_name}` is the fully qualified name of the Flint table, typically `datasource.database.object_name`.
This is also substituted in any linked Saved Queries when using S3-based integrations.
- `{s3_bucket_location}` to locate data.
- `{s3_checkpoint_location}` to store intermediate results, which is required by Spark.
- `{object_name}` used for giving tables a unique name per-integration to avoid collisions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ export async function addIntegrationRequest(
name?: string,
indexPattern?: string,
workflows?: string[],
skipRedirect?: boolean
skipRedirect?: boolean,
dataSourceInfo?: { dataSource: string; tableName: string }
): Promise<boolean> {
const http = coreRefs.http!;
if (addSample) {
Expand All @@ -300,9 +301,25 @@ export async function addIntegrationRequest(
indexPattern = `ss4o_${integration.type}-${integrationTemplateId}-sample-sample`;
}

const createReqBody: {
name?: string;
indexPattern?: string;
workflows?: string[];
dataSource?: string;
tableName?: string;
} = {
name,
indexPattern,
workflows,
};
if (dataSourceInfo) {
createReqBody.dataSource = dataSourceInfo.dataSource;
createReqBody.tableName = dataSourceInfo.dataSource;
}

let response: boolean = await http
.post(`${INTEGRATIONS_BASE}/store/${templateName}`, {
body: JSON.stringify({ name, indexPattern, workflows }),
body: JSON.stringify(createReqBody),
})
.then((res) => {
setToast(`${name} integration successfully added!`, 'success');
Expand Down
12 changes: 7 additions & 5 deletions public/components/integrations/components/setup_integration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,12 @@ export function SetupIntegrationFormInputs({
);
}

const makeTableName = (config: IntegrationSetupInputs): string => {
return `${config.connectionDataSource}.default.${config.connectionTableName}`;
};

const prepareQuery = (query: string, config: IntegrationSetupInputs): string => {
let queryStr = query.replaceAll(
'{table_name}',
`${config.connectionDataSource}.default.${config.connectionTableName}`
);
let queryStr = query.replaceAll('{table_name}', makeTableName(config));
queryStr = queryStr.replaceAll('{s3_bucket_location}', config.connectionLocation);
queryStr = queryStr.replaceAll('{s3_checkpoint_location}', config.checkpointLocation);
queryStr = queryStr.replaceAll('{object_name}', config.connectionTableName);
Expand Down Expand Up @@ -516,7 +517,8 @@ const addIntegration = async ({
config.displayName,
`flint_${config.connectionDataSource}_default_${config.connectionTableName}__*`,
config.enabledWorkflows,
setIsInstalling ? true : false
setIsInstalling ? true : false,
{ dataSource: config.connectionDataSource, tableName: makeTableName(config) }
);
if (setIsInstalling) {
setIsInstalling(false, res);
Expand Down

0 comments on commit 27890d0

Please sign in to comment.