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

[MDS] Fix showing DQS sources list in workspaces #8838

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions changelogs/fragments/8838.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- [MDS] Fix showing DQS sources list in workspaces ([#8838](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8838))
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@
deleteMultipleDataSources,
setFirstDataSourceAsDefault,
getHideLocalCluster,
getDataConnections,
} from '../../utils';
import { LoadingMask } from '../../loading_mask';
import { useOpenSearchDashboards } from '../../../../../opensearch_dashboards_react/public';
import { DATACONNECTIONS_BASE, LOCAL_CLUSTER } from '../../../constants';
import { DEFAULT_DATA_SOURCE_UI_SETTINGS_ID } from '../../constants';
import { DataConnectionType } from '../../../../../data_source/common';

interface DirectQueryDataConnectionsProps extends RouteComponentProps {
featureFlagStatus: boolean;
Expand Down Expand Up @@ -128,50 +130,68 @@
const fetchDataSources = useCallback(() => {
setIsLoading(true);

const fetchConnections = featureFlagStatus
? getDataSources(savedObjects.client)
: http.get(`${DATACONNECTIONS_BASE}`);

return fetchConnections
.then((response) => {
return featureFlagStatus
? fetchDataSourceConnections(
response,
http,
notifications,
true,
getHideLocalCluster().enabled
)
: response.map((dataConnection: DirectQueryDatasourceDetails) => ({
id: dataConnection.name,
title: dataConnection.name,
type:
{
S3GLUE: 'Amazon S3',
PROMETHEUS: 'Prometheus',
}[dataConnection.connector] || dataConnection.connector,
connectionType: dataConnection.connector,
description: dataConnection.description,
}));
})
.then((finalData) => {
setData(
featureFlagStatus
const fetchOpenSearchConnections = async (): Promise<DataSourceTableItem[]> => {
const fetchConnections = featureFlagStatus
? getDataSources(savedObjects.client)
: http.get(`${DATACONNECTIONS_BASE}`);

return fetchConnections
.then((response) => {
return featureFlagStatus
? fetchDataSourceConnections(
response,
http,
notifications,
true,
getHideLocalCluster().enabled
)
: response.map((dataConnection: DirectQueryDatasourceDetails) => ({

Check warning on line 148 in src/plugins/data_source_management/public/components/direct_query_data_sources_components/direct_query_data_connection/manage_direct_query_data_connections_table.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data_source_management/public/components/direct_query_data_sources_components/direct_query_data_connection/manage_direct_query_data_connections_table.tsx#L148

Added line #L148 was not covered by tests
id: dataConnection.name,
title: dataConnection.name,
type:
{
S3GLUE: 'Amazon S3',
PROMETHEUS: 'Prometheus',
Comment on lines +152 to +154
Copy link
Collaborator

Choose a reason for hiding this comment

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

Plz use DatasourceTypeToDisplayName

}[dataConnection.connector] || dataConnection.connector,
connectionType: dataConnection.connector,
description: dataConnection.description,
}));
})
.then((finalData) => {
return featureFlagStatus
? finalData.filter((item) => item.relatedConnections?.length > 0)
: finalData
);
})
.catch(() => {
setData([]);
notifications.toasts.addDanger(
i18n.translate('dataSourcesManagement.directQueryTable.fetchDataSources', {
defaultMessage: 'Could not fetch data sources',
})
);
})
.finally(() => {
setIsLoading(false);
});
: finalData;
})
.catch(() => {
notifications.toasts.addDanger(
i18n.translate('dataSourcesManagement.directQueryTable.fetchDataSources', {
defaultMessage: 'Could not fetch data sources',
})
);
return [];
});
};

const fetchDirectQueryConnections = async (): Promise<DataSourceTableItem[]> => {
try {
const dataConnectionSavedObjects = await getDataConnections(savedObjects.client);
return dataConnectionSavedObjects.map((obj) => ({

Check warning on line 178 in src/plugins/data_source_management/public/components/direct_query_data_sources_components/direct_query_data_connection/manage_direct_query_data_connections_table.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data_source_management/public/components/direct_query_data_sources_components/direct_query_data_connection/manage_direct_query_data_connections_table.tsx#L178

Added line #L178 was not covered by tests
id: obj.id,
title: obj.attributes.connectionId,
type: obj.attributes.type,
}));
} catch (error: any) {
return [];
}
};
Comment on lines +175 to +186
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should make sure this is covered as its new functionality


const fetchAllData = async () => {
const newData = await fetchOpenSearchConnections();
setData(newData.concat(await fetchDirectQueryConnections()));
setIsLoading(false);
};

fetchAllData();
}, [http, savedObjects, notifications, featureFlagStatus]);

/* Delete selected data sources*/
Expand Down Expand Up @@ -385,17 +405,25 @@
record.connectionType !== DataSourceConnectionType.OpenSearchConnection
? { marginLeft: '20px' }
: {};
return (
<EuiButtonEmpty
size="xs"
href={`${window.location.href.replace(/\/$/, '')}/${path}`}
style={indentStyle}
disabled={record.id === LOCAL_CLUSTER}
flush="left"
>
{name}
</EuiButtonEmpty>
);
if (
record.type === DataConnectionType.SecurityLake ||
record.type === DataConnectionType.CloudWatch
) {
// TODO: link to details page for security lake and cloudwatch
return <span style={indentStyle}> {name}</span>;

Check warning on line 413 in src/plugins/data_source_management/public/components/direct_query_data_sources_components/direct_query_data_connection/manage_direct_query_data_connections_table.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data_source_management/public/components/direct_query_data_sources_components/direct_query_data_connection/manage_direct_query_data_connections_table.tsx#L413

Added line #L413 was not covered by tests
} else {
Comment on lines +408 to +414
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should make sure this is covered as its new functionality

return (
<EuiButtonEmpty
size="xs"
href={`${window.location.href.replace(/\/$/, '')}/${path}`}
style={indentStyle}
disabled={record.id === LOCAL_CLUSTER}
flush="left"
>
{name}
</EuiButtonEmpty>
);
}
},
},
{
Expand Down
12 changes: 12 additions & 0 deletions src/plugins/data_source_management/public/components/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
} from '../service/data_source_selection_service';
import { DataSourceError } from '../types';
import { DATACONNECTIONS_BASE, LOCAL_CLUSTER } from '../constants';
import { DataConnectionSavedObjectAttributes } from '../../../data_source/common/data_connections';

export const getDirectQueryConnections = async (dataSourceId: string, http: HttpSetup) => {
const endpoint = `${DATACONNECTIONS_BASE}/dataSourceMDSId=${dataSourceId}`;
Expand Down Expand Up @@ -181,6 +182,17 @@
);
}

export async function getDataConnections(savedObjectsClient: SavedObjectsClientContract) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we type response?

return savedObjectsClient
.find<DataConnectionSavedObjectAttributes>({
type: 'data-connection',
perPage: 10000,
})
.then((response) => {
return response?.savedObjects;

Check warning on line 192 in src/plugins/data_source_management/public/components/utils.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data_source_management/public/components/utils.ts#L192

Added line #L192 was not covered by tests
});
Comment on lines +186 to +193
Copy link
Collaborator

Choose a reason for hiding this comment

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

given this is new, can we cover with tests?

}

export async function getDataSourcesWithFields(
savedObjectsClient: SavedObjectsClientContract,
fields: string[]
Expand Down
Loading