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

[BUG] Updated cache for the sub tree in Workbench #2351

Merged
merged 7 commits into from
Feb 20, 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
1 change: 1 addition & 0 deletions common/types/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
}

export interface ITabQueryResults {
[tabId: string]: any;

Check warning on line 70 in common/types/explorer.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
}

export interface ITabQueries {
Expand Down Expand Up @@ -133,17 +133,17 @@
side?: string | undefined
) => void;
http: CoreStart['http'];
tabCreatedTypes?: any;

Check warning on line 136 in common/types/explorer.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
searchBarConfigs?: any;

Check warning on line 137 in common/types/explorer.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
appId?: string;
addVisualizationToPanel?: any;

Check warning on line 139 in common/types/explorer.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
startTime?: string;
endTime?: string;
setStartTime?: any;

Check warning on line 142 in common/types/explorer.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
setEndTime?: any;

Check warning on line 143 in common/types/explorer.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
appBaseQuery?: string;
callback?: any;

Check warning on line 145 in common/types/explorer.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
callbackInApp?: any;

Check warning on line 146 in common/types/explorer.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
queryManager?: QueryManager;
}

Expand Down Expand Up @@ -210,10 +210,10 @@

export interface IVisualizationContainerPropsData {
appData?: { fromApp: boolean };
rawVizData?: any;

Check warning on line 213 in common/types/explorer.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
query?: IQuery;
indexFields?: IField[];
userConfigs?: any;

Check warning on line 216 in common/types/explorer.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
defaultAxes?: {
xaxis: IField[];
yaxis: IField[];
Expand Down Expand Up @@ -438,4 +438,5 @@
lang: string;
datasource: string;
sessionId?: string;
dataSourceMDSId?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,63 @@ describe('AccelerationDetailsFlyout Component Tests', () => {
index="mockIndex"
acceleration={mockAcceleration}
dataSourceName="mockDataSource"
dataSourceMDSId=""
/>
);

expect(coreRefsModule.coreRefs.dslService!.fetchFields).toHaveBeenCalledWith('testIndex');
expect(coreRefsModule.coreRefs.dslService!.fetchSettings).toHaveBeenCalledWith('testIndex');
expect(coreRefsModule.coreRefs.dslService!.fetchIndices).toHaveBeenCalledWith('testIndex');
expect(coreRefsModule.coreRefs.dslService!.fetchFields).toHaveBeenCalledWith('testIndex', '');
expect(coreRefsModule.coreRefs.dslService!.fetchSettings).toHaveBeenCalledWith('testIndex', '');
expect(coreRefsModule.coreRefs.dslService!.fetchIndices).toHaveBeenCalledWith('testIndex', '');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be add test cases with MDS enabled as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay sure

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test added

});

it('fetches acceleration details with specific mdsId', async () => {
mount(
<AccelerationDetailsFlyout
index="mockIndex"
acceleration={mockAcceleration}
dataSourceName="mockDataSource"
dataSourceMDSId="746ebe20-ee4a-11ef-823a-bd0a7d9fd697"
/>
);

expect(coreRefsModule.coreRefs.dslService!.fetchFields).toHaveBeenCalledWith(
'testIndex',
'746ebe20-ee4a-11ef-823a-bd0a7d9fd697'
);
expect(coreRefsModule.coreRefs.dslService!.fetchSettings).toHaveBeenCalledWith(
'testIndex',
'746ebe20-ee4a-11ef-823a-bd0a7d9fd697'
);
expect(coreRefsModule.coreRefs.dslService!.fetchIndices).toHaveBeenCalledWith(
'testIndex',
'746ebe20-ee4a-11ef-823a-bd0a7d9fd697'
);
});

it('renders the correct tab content on tab switch', async () => {
const wrapper = mount(
<AccelerationDetailsFlyout
index="mockIndex"
acceleration={mockAcceleration}
dataSourceName="mockDataSource"
/>
);
await new Promise(setImmediate);
wrapper.update();

const detailsTab = wrapper.find('EuiTab').filterWhere((node) => node.text() === 'Details');
detailsTab.simulate('click');
await new Promise(setImmediate);
wrapper.update();

expect(wrapper.find('AccelerationDetailsTab').exists()).toBe(true);

const schemaTab = wrapper.find('EuiTab').filterWhere((node) => node.text() === 'Schema');
schemaTab.simulate('click');
await new Promise(setImmediate);
wrapper.update();

expect(wrapper.find('AccelerationSchemaTab').exists()).toBe(true);
});

it('switches tabs correctly', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,25 @@ export interface AccelerationDetailsFlyoutProps {
dataSourceMDSId?: string;
}

const getMappings = (index: string): Promise<OpenSearchDashboardsResponse> | undefined => {
return coreRefs.dslService?.fetchFields(index);
const getMappings = (
index: string,
dataSourceMDSId?: string
): Promise<OpenSearchDashboardsResponse> | undefined => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return Promise or undefined? is it supposed to be Promise<OpenSearchDashboardsResponse | undefined>?

return coreRefs.dslService?.fetchFields(index, dataSourceMDSId);
};

const getSettings = (index: string): Promise<OpenSearchDashboardsResponse> | undefined => {
return coreRefs.dslService?.fetchSettings(index);
const getSettings = (
index: string,
dataSourceMDSId?: string
): Promise<OpenSearchDashboardsResponse> | undefined => {
return coreRefs.dslService?.fetchSettings(index, dataSourceMDSId);
};

const getIndexInfo = (index: string): Promise<OpenSearchDashboardsResponse> | undefined => {
return coreRefs.dslService?.fetchIndices(index);
const getIndexInfo = (
index: string,
dataSourceMDSId?: string
): Promise<OpenSearchDashboardsResponse> | undefined => {
return coreRefs.dslService?.fetchIndices(index, dataSourceMDSId);
};

const handleDetailsFetchingPromise = (
Expand All @@ -59,7 +68,7 @@ const handleDetailsFetchingPromise = (
};

export const AccelerationDetailsFlyout = (props: AccelerationDetailsFlyoutProps) => {
const { dataSourceName, acceleration, resetFlyout, handleRefresh } = props;
const { dataSourceName, acceleration, resetFlyout, handleRefresh, dataSourceMDSId } = props;
const { flintIndexName } = acceleration;
const [selectedTab, setSelectedTab] = useState('details');
const tabsMap: { [key: string]: any } = {
Expand Down Expand Up @@ -113,9 +122,9 @@ export const AccelerationDetailsFlyout = (props: AccelerationDetailsFlyoutProps)

const getAccDetail = (selectedIndex: string) => {
Promise.all([
handleDetailsFetchingPromise(getMappings(selectedIndex), 'getMappings'),
handleDetailsFetchingPromise(getSettings(selectedIndex), 'getSettings'),
handleDetailsFetchingPromise(getIndexInfo(selectedIndex), 'getIndexInfo'),
handleDetailsFetchingPromise(getMappings(selectedIndex, dataSourceMDSId), 'getMappings'),
handleDetailsFetchingPromise(getSettings(selectedIndex, dataSourceMDSId), 'getSettings'),
handleDetailsFetchingPromise(getIndexInfo(selectedIndex, dataSourceMDSId), 'getIndexInfo'),
])
.then((results) => {
updateMapping(results[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ export const CreateAcceleration = ({
setAccelerationFormData={setAccelerationFormData}
resetFlyout={resetFlyout}
refreshHandler={refreshHandler}
dataSourceMDSId={dataSourceMDSId}
/>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ interface CreateAccelerationButtonProps {
setAccelerationFormData: React.Dispatch<React.SetStateAction<CreateAccelerationForm>>;
resetFlyout: () => void;
refreshHandler?: () => void;
dataSourceMDSId?: string;
}

export const CreateAccelerationButton = ({
accelerationFormData,
setAccelerationFormData,
resetFlyout,
refreshHandler,
dataSourceMDSId,
}: CreateAccelerationButtonProps) => {
const { setToast } = useToast();
const { loadStatus: directqueryLoadStatus, startLoading: startDirectQuery } = useDirectQuery();
Expand All @@ -45,8 +47,7 @@ export const CreateAccelerationButton = ({
query: accelerationQueryBuilder(accelerationFormData).replaceAll(SANITIZE_QUERY_REGEX, ' '),
datasource: accelerationFormData.dataSource,
};

startDirectQuery(requestPayload);
startDirectQuery(requestPayload, dataSourceMDSId);
setIsLoading(true);
};

Expand Down
33 changes: 18 additions & 15 deletions public/framework/catalog_cache/cache_loader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,15 @@ export const updateAccelerationsToCache = (
const currentTime = new Date().toUTCString();

if (!pollingResult) {
CatalogCacheManager.addOrUpdateAccelerationsByDataSource({
name: dataSourceName,
accelerations: [],
lastUpdated: currentTime,
status: CachedDataSourceStatus.Failed,
...(dataSourceMDSId && { dataSourceMDSId }),
});
CatalogCacheManager.addOrUpdateAccelerationsByDataSource(
{
name: dataSourceName,
accelerations: [],
lastUpdated: currentTime,
status: CachedDataSourceStatus.Failed,
},
dataSourceMDSId
);
return;
}

Expand All @@ -155,14 +157,15 @@ export const updateAccelerationsToCache = (
autoRefresh: row.auto_refresh,
status: row.status,
}));

CatalogCacheManager.addOrUpdateAccelerationsByDataSource({
name: dataSourceName,
accelerations: newAccelerations,
lastUpdated: currentTime,
status: CachedDataSourceStatus.Updated,
...(dataSourceMDSId && { dataSourceMDSId }),
});
CatalogCacheManager.addOrUpdateAccelerationsByDataSource(
{
name: dataSourceName,
accelerations: newAccelerations,
lastUpdated: currentTime,
status: CachedDataSourceStatus.Updated,
},
dataSourceMDSId
);
};

export const updateTableColumnsToCache = (
Expand Down
10 changes: 6 additions & 4 deletions public/framework/catalog_cache/cache_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,11 @@ export class CatalogCacheManager {
);
} else {
index = accCacheData.dataSources.findIndex(
(ds: CachedAccelerationByDataSource) =>
ds.name === dataSource.name && ds.dataSourceMDSId === dataSourceMDSId
(ds: CachedAccelerationByDataSource) => ds.name === dataSource.name
);
}
if (index !== -1) {
accCacheData.dataSources[index] = dataSource;
accCacheData.dataSources[index] = { ...dataSource, dataSourceMDSId };
} else {
accCacheData.dataSources.push(dataSource);
}
Expand Down Expand Up @@ -161,8 +160,11 @@ export class CatalogCacheManager {
(ds: CachedDataSource) =>
ds.name === dataSource.name && ds.dataSourceMDSId === dataSourceMDSId
);
} else {
index = cacheData.dataSources.findIndex(
(ds: CachedDataSource) => ds.name === dataSource.name
);
}
index = cacheData.dataSources.findIndex((ds: CachedDataSource) => ds.name === dataSource.name);
if (index !== -1) {
cacheData.dataSources[index] = dataSource;
} else {
Expand Down
12 changes: 6 additions & 6 deletions public/services/requests/dsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export default class DSLService {
.catch((error) => console.error(error));
};

fetchIndices = async (index: string = '') => {
fetchIndices = async (index: string = '', dataSourceMDSId?: string) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure how this is handled when MDS is diabled. should we have a default value here?
dataSourceMDSId = ''

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have tested it, works when is the id is empty as well

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will update it to '' when MDS is disabled

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a place that when mds is disabled we set mds id to ''? Or we should just handle the undefined instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return this.http
.get(`${DSL_BASE}${DSL_CAT}`, {
.get(`${DSL_BASE}${DSL_CAT}/dataSourceMDSId=${dataSourceMDSId}`, {
query: {
format: 'json',
index,
Expand All @@ -39,16 +39,16 @@ export default class DSLService {
.catch((error) => console.error(error));
};

fetchFields = async (index: string) => {
return this.http.get(`${DSL_BASE}${DSL_MAPPING}`, {
fetchFields = async (index: string, dataSourceMDSId?: string) => {
return this.http.get(`${DSL_BASE}${DSL_MAPPING}/dataSourceMDSId=${dataSourceMDSId}`, {
query: {
index,
},
});
};

fetchSettings = async (index: string) => {
return this.http.get(`${DSL_BASE}${DSL_SETTINGS}`, {
fetchSettings = async (index: string, dataSourceMDSId?: string) => {
return this.http.get(`${DSL_BASE}${DSL_SETTINGS}/dataSourceMDSId=${dataSourceMDSId}`, {
query: {
index,
},
Expand Down
Loading