Skip to content

Commit

Permalink
Add support for rigister plugin during the absence of local cluster
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Liang <[email protected]>
  • Loading branch information
RyanL1997 committed Sep 6, 2024
1 parent 3ad2bf0 commit 395190a
Showing 1 changed file with 50 additions and 45 deletions.
95 changes: 50 additions & 45 deletions public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ export class ObservabilityPlugin
constructor(initializerContext: PluginInitializerContext) {
this.config = initializerContext.config.get<PublicConfig>();
}
private featureFlagStatus: boolean = false;

public setup(
core: CoreSetup<AppPluginStartDependencies>,
Expand All @@ -184,6 +185,8 @@ export class ObservabilityPlugin
});

setupOverviewPage(setupDeps.contentManagement!);
this.featureFlagStatus = !!setupDeps.dataSource;
console.log('Feature Flag Status:', this.featureFlagStatus);

// redirect legacy notebooks URL to current URL under observability
if (window.location.pathname.includes('notebooks-dashboards')) {
Expand Down Expand Up @@ -459,55 +462,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({
Expand Down

0 comments on commit 395190a

Please sign in to comment.