mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Prevent preloaded plugins from crashing Grafana (#41490)
* if a plugin fails to load, we will not crash grafana. * preventing the preloaded plugings to crash the whole app on failure. * updated to unkown. * fixed issue with angular by moving the preloadPlugin import to the same row as we did import the importPluginModule.
This commit is contained in:
parent
e0a60cf459
commit
e926126d63
@ -25,7 +25,7 @@ import {
|
||||
standardTransformersRegistry,
|
||||
} from '@grafana/data';
|
||||
import { arrayMove } from 'app/core/utils/arrayMove';
|
||||
import { importPluginModule } from 'app/features/plugins/plugin_loader';
|
||||
import { preloadPlugins } from './features/plugins/pluginPreloader';
|
||||
import {
|
||||
locationService,
|
||||
registerEchoBackend,
|
||||
@ -125,12 +125,7 @@ export class GrafanaApp {
|
||||
this.angularApp.init();
|
||||
|
||||
// Preload selected app plugins
|
||||
const promises: Array<Promise<any>> = [];
|
||||
for (const plugin of config.pluginsToPreload) {
|
||||
promises.push(importPluginModule(plugin.path, plugin.version));
|
||||
}
|
||||
|
||||
await Promise.all(promises);
|
||||
await preloadPlugins(config.pluginsToPreload);
|
||||
|
||||
ReactDOM.render(
|
||||
React.createElement(AppWrapper, {
|
||||
|
15
public/app/features/plugins/pluginPreloader.ts
Normal file
15
public/app/features/plugins/pluginPreloader.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { PreloadPlugin } from '@grafana/data';
|
||||
import { importPluginModule } from './plugin_loader';
|
||||
|
||||
export async function preloadPlugins(pluginsToPreload: PreloadPlugin[] = []): Promise<void> {
|
||||
await Promise.all(pluginsToPreload.map(preloadPlugin));
|
||||
}
|
||||
|
||||
async function preloadPlugin(plugin: PreloadPlugin): Promise<void> {
|
||||
const { path, version } = plugin;
|
||||
try {
|
||||
await importPluginModule(path, version);
|
||||
} catch (error: unknown) {
|
||||
console.error(`Failed to load plugin: ${path} (version: ${version})`, error);
|
||||
}
|
||||
}
|
@ -78,7 +78,6 @@ grafanaRuntime.SystemJS.config({
|
||||
|
||||
function exposeToPlugin(name: string, component: any) {
|
||||
grafanaRuntime.SystemJS.registerDynamic(name, [], true, (require: any, exports: any, module: { exports: any }) => {
|
||||
console.log('registerDynamic callback', name);
|
||||
module.exports = component;
|
||||
});
|
||||
}
|
||||
@ -184,7 +183,7 @@ export async function importPluginModule(path: string, version?: string): Promis
|
||||
if (typeof builtIn === 'function') {
|
||||
return await builtIn();
|
||||
} else {
|
||||
return Promise.resolve(builtIn);
|
||||
return builtIn;
|
||||
}
|
||||
}
|
||||
return grafanaRuntime.SystemJS.import(path);
|
||||
|
Loading…
Reference in New Issue
Block a user