Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support 2.17 BWC with latest backend integrations #612

Merged
merged 4 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions public/pages/workflow_detail/tools/query/query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
containsEmptyValues,
containsSameValues,
getDataSourceId,
getEffectiveVersion,
getPlaceholdersFromQuery,
getSearchPipelineErrors,
injectParameters,
Expand Down Expand Up @@ -64,6 +65,17 @@ const SEARCH_OPTIONS = [
export function Query(props: QueryProps) {
const dispatch = useAppDispatch();
const dataSourceId = getDataSourceId();
const [dataSourceVersion, setDataSourceVersion] = useState<
string | undefined
>(undefined);
useEffect(() => {
async function getVersion() {
if (dataSourceId !== undefined) {
setDataSourceVersion(await getEffectiveVersion(dataSourceId));
}
}
getVersion();
}, [dataSourceId]);

const { loading } = useSelector((state: AppState) => state.opensearch);

Expand Down Expand Up @@ -204,6 +216,7 @@ export function Query(props: QueryProps) {
: '_none',
},
dataSourceId,
dataSourceVersion,
verbose: includePipeline,
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ import {
WorkflowConfig,
WorkflowFormValues,
} from '../../../../common';
import { formikToUiConfig, getDataSourceFromURL } from '../../../utils';
import { getEffectiveVersion } from '../../../pages/workflows/new_workflow/new_workflow';
import {
formikToUiConfig,
getDataSourceFromURL,
getEffectiveVersion,
} from '../../../utils';
import {
CollapseProcessor,
CopyIngestProcessor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import {
WorkflowConfig,
} from '../../../../../common';
import { catIndices, useAppDispatch } from '../../../../store';
import { getDataSourceId } from '../../../../utils';
import { getEffectiveVersion } from '../../../workflows/new_workflow/new_workflow';
import { getDataSourceId, getEffectiveVersion } from '../../../../utils';

interface SearchInputsProps {
uiConfig: WorkflowConfig;
Expand All @@ -42,8 +41,10 @@ export function SearchInputs(props: SearchInputsProps) {
useEffect(() => {
const checkVersion = async () => {
try {
const version = await getEffectiveVersion(dataSourceId);
setShowTransformQuery(semver.gte(version, '2.19.0'));
if (dataSourceId !== undefined) {
const version = await getEffectiveVersion(dataSourceId);
setShowTransformQuery(semver.gte(version, '2.19.0'));
}
} catch (error) {
console.error('Error checking version:', error);
setShowTransformQuery(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import React, { useEffect, useState } from 'react';
import { getIn, useFormikContext } from 'formik';
import { isEmpty, isEqual } from 'lodash';
import semver from 'semver';
import {
EuiSmallButton,
EuiSmallButtonEmpty,
Expand All @@ -23,6 +24,7 @@ import {
import {
CONFIG_STEP,
CachedFormikState,
MINIMUM_FULL_SUPPORTED_VERSION,
SimulateIngestPipelineResponseVerbose,
TemplateNode,
WORKFLOW_STEP_TYPE,
Expand Down Expand Up @@ -56,6 +58,8 @@ import {
getDataSourceId,
prepareDocsForSimulate,
getIngestPipelineErrors,
getEffectiveVersion,
sleep,
} from '../../../utils';
import { BooleanField } from './input_fields';
import '../workspace/workspace-styles.scss';
Expand Down Expand Up @@ -97,6 +101,21 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
} = useFormikContext<WorkflowFormValues>();
const dispatch = useAppDispatch();
const dataSourceId = getDataSourceId();
const [dataSourceVersion, setDataSourceVersion] = useState<
string | undefined
>(undefined);
useEffect(() => {
async function getVersion() {
if (dataSourceId !== undefined) {
setDataSourceVersion(await getEffectiveVersion(dataSourceId));
}
}
getVersion();
}, [dataSourceId]);
const isPreV219 =
dataSourceVersion !== undefined
? semver.lt(dataSourceVersion, MINIMUM_FULL_SUPPORTED_VERSION)
: false;

// transient running states
const [isUpdatingSearchPipeline, setIsUpdatingSearchPipeline] = useState<
Expand Down Expand Up @@ -390,10 +409,16 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
reprovision: true,
},
dataSourceId,
dataSourceVersion,
})
)
.unwrap()
.then(async (result) => {
// if the datasource < 2.19, only async provisioning/reprovisioning is supported.
// so, we manually wait some time before trying to fetch the updated workflow
if (isPreV219) {
await sleep(1000);
}
props.setUnsavedIngestProcessors(false);
props.setUnsavedSearchProcessors(false);
success = true;
Expand Down Expand Up @@ -426,6 +451,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
)
.unwrap()
.then(async (result) => {
await sleep(100);
await dispatch(
updateWorkflow({
apiBody: {
Expand All @@ -438,16 +464,24 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
)
.unwrap()
.then(async (result) => {
await sleep(100);
props.setUnsavedIngestProcessors(false);
props.setUnsavedSearchProcessors(false);
await dispatch(
provisionWorkflow({
workflowId: updatedWorkflow.id as string,
dataSourceId,
dataSourceVersion,
})
)
.unwrap()
.then(async (result) => {
await sleep(100);
// if the datasource < 2.19, only async provisioning/reprovisioning is supported.
// so, we manually wait some time before trying to fetch the updated workflow
if (isPreV219) {
await sleep(1000);
}
await dispatch(
getWorkflow({
workflowId: updatedWorkflow.id as string,
Expand Down
29 changes: 5 additions & 24 deletions public/pages/workflows/new_workflow/new_workflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ import {
searchConnectors,
} from '../../../store';
import { enrichPresetWorkflowWithUiMetadata } from './utils';
import { getDataSourceId, isDataSourceReady } from '../../../utils';
import {
getDataSourceId,
isDataSourceReady,
getEffectiveVersion,
} from '../../../utils';
import { getDataSourceEnabled } from '../../../services';
import semver from 'semver';
import { DataSourceAttributes } from '../../../../../../src/plugins/data_source/common/data_sources';
import { getSavedObjectsClient } from '../../../../public/services';
import {
WORKFLOW_TYPE,
MIN_SUPPORTED_VERSION,
Expand All @@ -40,27 +42,6 @@ import {

interface NewWorkflowProps {}

export const getEffectiveVersion = async (
dataSourceId: string | undefined
): Promise<string> => {
try {
if (dataSourceId === undefined) {
throw new Error('Data source is required');
}

const dataSource = await getSavedObjectsClient().get<DataSourceAttributes>(
'data-source',
dataSourceId
);
const version =
dataSource?.attributes?.dataSourceVersion || MIN_SUPPORTED_VERSION;
return version;
} catch (error) {
console.error('Error getting version:', error);
return MIN_SUPPORTED_VERSION;
}
};

const filterPresetsByVersion = async (
workflows: WorkflowTemplate[],
dataSourceId: string | undefined
Expand Down
30 changes: 25 additions & 5 deletions public/route_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ export interface RouteService {
workflowTemplate: WorkflowTemplate,
updateFields: boolean,
reprovision: boolean,
dataSourceId?: string
dataSourceId?: string,
dataSourceVersion?: string
) => Promise<any | HttpFetchError>;
provisionWorkflow: (
workflowId: string,
dataSourceId?: string
dataSourceId?: string,
dataSourceVersion?: string
) => Promise<any | HttpFetchError>;
deprovisionWorkflow: ({
workflowId,
Expand Down Expand Up @@ -96,12 +98,14 @@ export interface RouteService {
index,
body,
dataSourceId,
dataSourceVersion,
searchPipeline,
verbose,
}: {
index: string;
body: {};
dataSourceId?: string;
dataSourceVersion?: string;
searchPipeline?: string;
verbose?: boolean;
}) => Promise<any | HttpFetchError>;
Expand Down Expand Up @@ -205,7 +209,8 @@ export function configureRoutes(core: CoreStart): RouteService {
workflowTemplate: WorkflowTemplate,
updateFields: boolean,
reprovision: boolean,
dataSourceId?: string
dataSourceId?: string,
dataSourceVersion?: string
) => {
try {
const url = dataSourceId
Expand All @@ -215,20 +220,32 @@ export function configureRoutes(core: CoreStart): RouteService {
`${url}/${workflowId}/${updateFields}/${reprovision}`,
{
body: JSON.stringify(workflowTemplate),
query: {
data_source_version: dataSourceVersion,
},
}
);
return response;
} catch (e: any) {
return e as HttpFetchError;
}
},
provisionWorkflow: async (workflowId: string, dataSourceId?: string) => {
provisionWorkflow: async (
workflowId: string,
dataSourceId?: string,
dataSourceVersion?: string
) => {
try {
const url = dataSourceId
? `${BASE_NODE_API_PATH}/${dataSourceId}/workflow/provision`
: PROVISION_WORKFLOW_NODE_API_PATH;
const response = await core.http.post<{ respString: string }>(
`${url}/${workflowId}`
`${url}/${workflowId}`,
{
query: {
data_source_version: dataSourceVersion,
},
}
);
return response;
} catch (e: any) {
Expand Down Expand Up @@ -323,12 +340,14 @@ export function configureRoutes(core: CoreStart): RouteService {
index,
body,
dataSourceId,
dataSourceVersion,
searchPipeline,
verbose,
}: {
index: string;
body: {};
dataSourceId?: string;
dataSourceVersion?: string;
searchPipeline?: string;
verbose?: boolean;
}) => {
Expand All @@ -344,6 +363,7 @@ export function configureRoutes(core: CoreStart): RouteService {
body: JSON.stringify(body),
query: {
verbose: verbose ?? false,
data_source_version: dataSourceVersion,
},
});
return response;
Expand Down
3 changes: 3 additions & 0 deletions public/store/reducers/opensearch_reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ export const searchIndex = createAsyncThunk(
{
apiBody,
dataSourceId,
dataSourceVersion,
verbose,
}: {
apiBody: { index: string; body: {}; searchPipeline?: string };
dataSourceId?: string;
dataSourceVersion?: string;
verbose?: boolean;
},
{ rejectWithValue }
Expand All @@ -123,6 +125,7 @@ export const searchIndex = createAsyncThunk(
index,
body,
dataSourceId,
dataSourceVersion,
searchPipeline,
verbose,
});
Expand Down
18 changes: 15 additions & 3 deletions public/store/reducers/workflows_reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export const updateWorkflow = createAsyncThunk(
{
apiBody,
dataSourceId,
dataSourceVersion,
}: {
apiBody: {
workflowId: string;
Expand All @@ -124,6 +125,7 @@ export const updateWorkflow = createAsyncThunk(
reprovision?: boolean;
};
dataSourceId?: string;
dataSourceVersion?: string;
},
{ rejectWithValue }
) => {
Expand All @@ -135,7 +137,8 @@ export const updateWorkflow = createAsyncThunk(
workflowTemplate,
updateFields || false,
reprovision || false,
dataSourceId
dataSourceId,
dataSourceVersion
);
if (response instanceof HttpFetchError) {
return rejectWithValue(
Expand All @@ -150,14 +153,23 @@ export const updateWorkflow = createAsyncThunk(
export const provisionWorkflow = createAsyncThunk(
PROVISION_WORKFLOW_ACTION,
async (
{ workflowId, dataSourceId }: { workflowId: string; dataSourceId?: string },
{
workflowId,
dataSourceId,
dataSourceVersion,
}: {
workflowId: string;
dataSourceId?: string;
dataSourceVersion?: string;
},
{ rejectWithValue }
) => {
const response:
| any
| HttpFetchError = await getRouteService().provisionWorkflow(
workflowId,
dataSourceId
dataSourceId,
dataSourceVersion
);
if (response instanceof HttpFetchError) {
return rejectWithValue(
Expand Down
Loading
Loading