From f7e8b725e706b4394f23c7de8cd29409372af74b Mon Sep 17 00:00:00 2001 From: Jialiang Liang Date: Fri, 6 Sep 2024 13:43:37 -0700 Subject: [PATCH] [MDS] Add support for register data sources during the absence of local cluster (#2140) --- public/plugin.tsx | 94 ++++++++++--------- ...ch-observability.release-notes-2.17.0.0.md | 3 +- 2 files changed, 51 insertions(+), 46 deletions(-) diff --git a/public/plugin.tsx b/public/plugin.tsx index 5c56bc5f7c..eaf71e0c07 100644 --- a/public/plugin.tsx +++ b/public/plugin.tsx @@ -169,6 +169,7 @@ export class ObservabilityPlugin constructor(initializerContext: PluginInitializerContext) { this.config = initializerContext.config.get(); } + private featureFlagStatus: boolean = false; public setup( core: CoreSetup, @@ -184,6 +185,7 @@ export class ObservabilityPlugin }); setupOverviewPage(setupDeps.contentManagement!); + this.featureFlagStatus = !!setupDeps.dataSource; // redirect legacy notebooks URL to current URL under observability if (window.location.pathname.includes('notebooks-dashboards')) { @@ -459,55 +461,57 @@ export class ObservabilityPlugin return `${type.charAt(0).toUpperCase()}${type.slice(1)}`; }; - // register all s3 datasources - const registerDataSources = () => { - try { - core.http.get(`${DATACONNECTIONS_BASE}`).then((s3DataSources) => { - s3DataSources.map((s3ds) => { - dataSourceService.registerDataSource( - dataSourceFactory.getDataSourceInstance(S3_DATA_SOURCE_TYPE, { - id: htmlIdGenerator(OBS_S3_DATA_SOURCE)(), - name: s3ds.name, - type: s3ds.connector.toLowerCase(), - metadata: { - ...s3ds.properties, - ui: { - label: s3ds.name, - typeLabel: getDataSourceTypeLabel(s3ds.connector.toLowerCase()), - groupType: s3ds.connector.toLowerCase(), - selector: { - displayDatasetsAsSource: false, + // register all s3 datasources only if mds feature flag is disabled + if (!this.featureFlagStatus) { + const registerDataSources = () => { + try { + core.http.get(`${DATACONNECTIONS_BASE}`).then((s3DataSources) => { + s3DataSources.map((s3ds) => { + dataSourceService.registerDataSource( + dataSourceFactory.getDataSourceInstance(S3_DATA_SOURCE_TYPE, { + id: htmlIdGenerator(OBS_S3_DATA_SOURCE)(), + name: s3ds.name, + type: s3ds.connector.toLowerCase(), + metadata: { + ...s3ds.properties, + ui: { + label: s3ds.name, + typeLabel: getDataSourceTypeLabel(s3ds.connector.toLowerCase()), + groupType: s3ds.connector.toLowerCase(), + selector: { + displayDatasetsAsSource: false, + }, }, }, - }, - }) - ); + }) + ); + }); }); - }); - } catch (error) { - console.error('Error registering S3 datasources', error); - } - }; - - dataSourceService.registerDataSourceFetchers([ - { type: S3_DATA_SOURCE_TYPE, registerDataSources }, - ]); - - if (startDeps.securityDashboards) { - core.http - .get(SECURITY_PLUGIN_ACCOUNT_API) - .then(() => { - registerDataSources(); - }) - .catch((e) => { - if (e?.response?.status !== 401) { - // accounts api should not return any error status other than 401 if security installed, - // this datasource register is included just in case + } catch (error) { + console.error('Error registering S3 datasources', error); + } + }; + + dataSourceService.registerDataSourceFetchers([ + { type: S3_DATA_SOURCE_TYPE, registerDataSources }, + ]); + + if (startDeps.securityDashboards) { + core.http + .get(SECURITY_PLUGIN_ACCOUNT_API) + .then(() => { registerDataSources(); - } - }); - } else { - registerDataSources(); + }) + .catch((e) => { + if (e?.response?.status !== 401) { + // accounts api should not return any error status other than 401 if security installed, + // this datasource register is included just in case + registerDataSources(); + } + }); + } else { + registerDataSources(); + } } core.http.intercept({ diff --git a/release-notes/opensearch-observability.release-notes-2.17.0.0.md b/release-notes/opensearch-observability.release-notes-2.17.0.0.md index 8fd954f63e..6cd441c83c 100644 --- a/release-notes/opensearch-observability.release-notes-2.17.0.0.md +++ b/release-notes/opensearch-observability.release-notes-2.17.0.0.md @@ -12,7 +12,7 @@ Compatible with OpenSearch and OpenSearch Dashboards version 2.17.0 * [FEATURE] MDS support in Integrations for observability plugin ([#2051](https://github.com/opensearch-project/dashboards-observability/pull/2051)) * [Feature] Logs UI update ([#2092](https://github.com/opensearch-project/dashboards-observability/pull/2092)) * feat: make createAssets API compatible with workspace ([#2101](https://github.com/opensearch-project/dashboards-observability/pull/2101)) -* [Page Header] New page header for notebooks and UI updates ([#2099](https://github.com/opensearch-project/dashboards-observability/pull/2099), [#2103](https://github.com/opensearch-project/dashboards-observability/pull/2203)) +* [Page Header] New page header for notebooks and UI updates ([#2099](https://github.com/opensearch-project/dashboards-observability/pull/2099), [#2103](https://github.com/opensearch-project/dashboards-observability/pull/2099)) * [Feature] OverviewPage made with Content Management ([#2077](https://github.com/opensearch-project/dashboards-observability/pull/2077)) ### Enhancement @@ -24,6 +24,7 @@ Compatible with OpenSearch and OpenSearch Dashboards version 2.17.0 * [query assist] update api handler to accommodate new ml-commons config response ([#2111](https://github.com/opensearch-project/dashboards-observability/pull/2111)) * Update trace analytics landing page ([#2125](https://github.com/opensearch-project/dashboards-observability/pull/2125)) * [query assist] update ml-commons response schema ([#2124](https://github.com/opensearch-project/dashboards-observability/pull/2124)) +* [MDS] Add support for register data sources during the absence of local cluster ([#2140](https://github.com/opensearch-project/dashboards-observability/pull/2140)) ### Bug Fixes * [Bug] Trace Analytics bug fix for local cluster being rendered ([#2006](https://github.com/opensearch-project/dashboards-observability/pull/2006))