Skip to content

Commit

Permalink
Add applicable_data_sources field to workflows definition (#1868)
Browse files Browse the repository at this point in the history
* Add applicable_data_sources field to workflows definition

Signed-off-by: Simeon Widdis <[email protected]>

* Add workflow filtering by applicable data sources

Signed-off-by: Simeon Widdis <[email protected]>

* Add tests for new functionality

Signed-off-by: Simeon Widdis <[email protected]>

* Only use applicable workflows in index-based install

Signed-off-by: Simeon Widdis <[email protected]>

* Rename flint dashboards workflow since there's no collision

Signed-off-by: Simeon Widdis <[email protected]>

---------

Signed-off-by: Simeon Widdis <[email protected]>
  • Loading branch information
Swiddis authored Jun 10, 2024
1 parent 2a446bb commit fe25bf1
Show file tree
Hide file tree
Showing 7 changed files with 250 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,17 @@ exports[`Integration Setup Inputs Renders the S3 connector form as expected 1`]
</EuiFormRow>
<EuiSpacer />
<IntegrationWorkflowsInputs
config={
Object {
"checkpointLocation": "",
"connectionDataSource": "ss4o_logs-nginx-test",
"connectionLocation": "",
"connectionTableName": "",
"connectionType": "s3",
"displayName": "Test Instance Name",
"enabledWorkflows": Array [],
}
}
updateConfig={[Function]}
workflows={
Array [
Expand Down Expand Up @@ -423,6 +434,17 @@ exports[`Integration Setup Inputs Renders the S3 connector form without workflow
</EuiFormRow>
<EuiSpacer />
<IntegrationWorkflowsInputs
config={
Object {
"checkpointLocation": "",
"connectionDataSource": "ss4o_logs-nginx-test",
"connectionLocation": "",
"connectionTableName": "",
"connectionType": "s3",
"displayName": "Test Instance Name",
"enabledWorkflows": Array [],
}
}
updateConfig={[Function]}
workflows={
Array [
Expand Down Expand Up @@ -2125,6 +2147,17 @@ exports[`Integration Setup Inputs Renders the query inputs 1`] = `

exports[`Integration Setup Inputs Renders the workflows inputs 1`] = `
<IntegrationWorkflowsInputs
config={
Object {
"checkpointLocation": "",
"connectionDataSource": "ss4o_logs-nginx-test",
"connectionLocation": "",
"connectionTableName": "",
"connectionType": "index",
"displayName": "Test Instance Name",
"enabledWorkflows": Array [],
}
}
integration={
Object {
"assets": Array [
Expand Down Expand Up @@ -2180,6 +2213,130 @@ exports[`Integration Setup Inputs Renders the workflows inputs 1`] = `
>
<SetupWorkflowSelector
aria-describedby="random_html_id-error-0"
config={
Object {
"checkpointLocation": "",
"connectionDataSource": "ss4o_logs-nginx-test",
"connectionLocation": "",
"connectionTableName": "",
"connectionType": "index",
"displayName": "Test Instance Name",
"enabledWorkflows": Array [],
}
}
id="random_html_id"
onBlur={[Function]}
onFocus={[Function]}
toggleWorkflow={[Function]}
useWorkflows={Array []}
/>
<EuiFormErrorText
className="euiFormRow__text"
id="random_html_id-error-0"
key="Must select at least one workflow."
>
<div
aria-live="polite"
className="euiFormErrorText euiFormRow__text"
id="random_html_id-error-0"
>
Must select at least one workflow.
</div>
</EuiFormErrorText>
</div>
</div>
</EuiFormRow>
</IntegrationWorkflowsInputs>
`;

exports[`Integration Setup Inputs Renders the workflows inputs with conditional workflows 1`] = `
<IntegrationWorkflowsInputs
config={
Object {
"checkpointLocation": "",
"connectionDataSource": "ss4o_logs-nginx-test",
"connectionLocation": "",
"connectionTableName": "",
"connectionType": "s3",
"displayName": "Test Instance Name",
"enabledWorkflows": Array [],
}
}
integration={
Object {
"assets": Array [
Object {
"extension": "ndjson",
"name": "sample",
"type": "savedObjectBundle",
"version": "1.0.1",
},
],
"components": Array [
Object {
"name": "logs",
"version": "1.0.0",
},
],
"license": "Apache-2.0",
"name": "sample",
"type": "logs",
"version": "2.0.0",
"workflows": Array [
Object {
"description": "This is a test workflow.",
"enabled_by_default": true,
"label": "Workflow 1",
"name": "workflow1",
},
Object {
"applicable_data_sources": Array [
"index",
],
"description": "This should not render.",
"enabled_by_default": true,
"label": "Workflow 2",
"name": "workflow2",
},
],
}
}
updateConfig={[Function]}
>
<EuiFormRow
describedByIds={Array []}
display="row"
error={
Array [
"Must select at least one workflow.",
]
}
fullWidth={false}
hasChildLabel={true}
hasEmptyLabelSpace={false}
isInvalid={true}
labelType="label"
>
<div
className="euiFormRow"
id="random_html_id-row"
>
<div
className="euiFormRow__fieldWrapper"
>
<SetupWorkflowSelector
aria-describedby="random_html_id-error-0"
config={
Object {
"checkpointLocation": "",
"connectionDataSource": "ss4o_logs-nginx-test",
"connectionLocation": "",
"connectionTableName": "",
"connectionType": "s3",
"displayName": "Test Instance Name",
"enabledWorkflows": Array [],
}
}
id="random_html_id"
onBlur={[Function]}
onFocus={[Function]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,42 @@ describe('Integration Setup Inputs', () => {

it('Renders the workflows inputs', async () => {
const wrapper = mount(
<IntegrationWorkflowsInputs updateConfig={() => {}} integration={TEST_INTEGRATION_CONFIG} />
<IntegrationWorkflowsInputs
config={TEST_INTEGRATION_SETUP_INPUTS}
updateConfig={() => {}}
integration={TEST_INTEGRATION_CONFIG}
/>
);

await waitFor(() => {
expect(wrapper).toMatchSnapshot();
});
});

it('Renders the workflows inputs with conditional workflows', async () => {
const wrapper = mount(
<IntegrationWorkflowsInputs
config={{ ...TEST_INTEGRATION_SETUP_INPUTS, connectionType: 's3' }}
updateConfig={() => {}}
integration={{
...TEST_INTEGRATION_CONFIG,
workflows: [
{
name: 'workflow1',
label: 'Workflow 1',
description: 'This is a test workflow.',
enabled_by_default: true,
},
{
name: 'workflow2',
label: 'Workflow 2',
description: 'This should not render.',
enabled_by_default: true,
applicable_data_sources: ['index'],
},
],
}}
/>
);

await waitFor(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ const addIntegration = async ({
let sessionId: string | null = null;

if (config.connectionType === 'index') {
let enabledWorkflows: string[] | undefined;
if (integration.workflows) {
enabledWorkflows = integration.workflows
.filter((w) =>
w.applicable_data_sources ? w.applicable_data_sources.includes('index') : true
)
.map((w) => w.name);
}
const res = await addIntegrationRequest({
addSample: false,
templateName: integration.name,
Expand All @@ -152,6 +160,7 @@ const addIntegration = async ({
name: config.displayName,
indexPattern: config.connectionDataSource,
skipRedirect: setIsInstalling ? true : false,
workflows: enabledWorkflows,
});
if (setIsInstalling) {
setIsInstalling(false, res);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ const suggestDataSources = async (
}>;
const filterCondition =
type === 's3'
? (item: any) => item.connector === 'S3GLUE'
: (item: any) => item.connector === 'SECURITYLAKE';
? (item: { connector: string }) => item.connector === 'S3GLUE'
: (item: { connector: string }) => item.connector === 'SECURITYLAKE';

return (
result?.filter(filterCondition).map((item) => {
Expand All @@ -121,33 +121,41 @@ export function SetupWorkflowSelector({
integrationWorkflows,
useWorkflows,
toggleWorkflow,
config,
}: {
integrationWorkflows?: IntegrationWorkflow[];
useWorkflows: Map<string, boolean>;
toggleWorkflow: (name: string) => void;
config: IntegrationSetupInputs;
}) {
if (!integrationWorkflows) {
return null;
}

const cards = integrationWorkflows.map((workflow) => {
return (
<>
<EuiCheckableCard
id={`workflow-checkbox-${workflow.name}`}
key={workflow.name}
label={workflow.label}
checkableType="checkbox"
value={workflow.name}
checked={useWorkflows.get(workflow.name)}
onChange={() => toggleWorkflow(workflow.name)}
>
{workflow.description}
</EuiCheckableCard>
<EuiSpacer size="s" />
</>
);
});
const cards = integrationWorkflows
.filter((workflow) =>
workflow.applicable_data_sources
? workflow.applicable_data_sources.includes(config.connectionType)
: true
)
.map((workflow) => {
return (
<>
<EuiCheckableCard
id={`workflow-checkbox-${workflow.name}`}
key={workflow.name}
label={workflow.label}
checkableType="checkbox"
value={workflow.name}
checked={useWorkflows.get(workflow.name)}
onChange={() => toggleWorkflow(workflow.name)}
>
{workflow.description}
</EuiCheckableCard>
<EuiSpacer size="s" />
</>
);
});

return <>{cards}</>;
}
Expand Down Expand Up @@ -343,9 +351,11 @@ export function IntegrationQueryInputs({
}

export function IntegrationWorkflowsInputs({
config,
updateConfig,
workflows,
}: {
config: IntegrationSetupInputs;
updateConfig: (updates: Partial<IntegrationSetupInputs>) => void;
workflows?: IntegrationWorkflow[];
}) {
Expand Down Expand Up @@ -378,6 +388,7 @@ export function IntegrationWorkflowsInputs({
error={['Must select at least one workflow.']}
>
<SetupWorkflowSelector
config={config}
integrationWorkflows={workflows}
useWorkflows={useWorkflows}
toggleWorkflow={toggleWorkflow}
Expand Down Expand Up @@ -458,6 +469,7 @@ export function SetupIntegrationFormInputs(props: IntegrationConfigProps) {
</EuiFormRow>
<EuiSpacer />
<IntegrationWorkflowsInputs
config={config}
updateConfig={updateConfig}
workflows={integration.workflows}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
"name": "dashboards",
"label": "Dashboards & Visualizations",
"description": "Dashboards and indices that enable you to easily visualize important metrics.",
"enabled_by_default": false
"enabled_by_default": false,
"applicable_data_sources": ["index"]
},
{
"name": "flint-live-dashboards",
"label": "Dashboards & Visualizations For Flint Integrations using live queries",
"description": "Dashboards and visualizations aligned with Flint S3 datasource ",
"enabled_by_default": false
"label": "Dashboards & Visualizations",
"description": "Dashboards and indices that enable you to easily visualize important metrics.",
"enabled_by_default": false,
"applicable_data_sources": ["s3"]
}
],
"statics": {
Expand Down
1 change: 1 addition & 0 deletions server/adaptors/integrations/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ interface IntegrationWorkflow {
label: string;
description: string;
enabled_by_default: boolean;
applicable_data_sources?: string[];
}

type ParsedIntegrationAsset =
Expand Down
Loading

0 comments on commit fe25bf1

Please sign in to comment.