mirror of
https://github.com/grafana/grafana.git
synced 2025-08-06 20:59:35 +08: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:
@ -25,7 +25,7 @@ import {
|
|||||||
standardTransformersRegistry,
|
standardTransformersRegistry,
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
import { arrayMove } from 'app/core/utils/arrayMove';
|
import { arrayMove } from 'app/core/utils/arrayMove';
|
||||||
import { importPluginModule } from 'app/features/plugins/plugin_loader';
|
import { preloadPlugins } from './features/plugins/pluginPreloader';
|
||||||
import {
|
import {
|
||||||
locationService,
|
locationService,
|
||||||
registerEchoBackend,
|
registerEchoBackend,
|
||||||
@ -125,12 +125,7 @@ export class GrafanaApp {
|
|||||||
this.angularApp.init();
|
this.angularApp.init();
|
||||||
|
|
||||||
// Preload selected app plugins
|
// Preload selected app plugins
|
||||||
const promises: Array<Promise<any>> = [];
|
await preloadPlugins(config.pluginsToPreload);
|
||||||
for (const plugin of config.pluginsToPreload) {
|
|
||||||
promises.push(importPluginModule(plugin.path, plugin.version));
|
|
||||||
}
|
|
||||||
|
|
||||||
await Promise.all(promises);
|
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
React.createElement(AppWrapper, {
|
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) {
|
function exposeToPlugin(name: string, component: any) {
|
||||||
grafanaRuntime.SystemJS.registerDynamic(name, [], true, (require: any, exports: any, module: { exports: any }) => {
|
grafanaRuntime.SystemJS.registerDynamic(name, [], true, (require: any, exports: any, module: { exports: any }) => {
|
||||||
console.log('registerDynamic callback', name);
|
|
||||||
module.exports = component;
|
module.exports = component;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -184,7 +183,7 @@ export async function importPluginModule(path: string, version?: string): Promis
|
|||||||
if (typeof builtIn === 'function') {
|
if (typeof builtIn === 'function') {
|
||||||
return await builtIn();
|
return await builtIn();
|
||||||
} else {
|
} else {
|
||||||
return Promise.resolve(builtIn);
|
return builtIn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return grafanaRuntime.SystemJS.import(path);
|
return grafanaRuntime.SystemJS.import(path);
|
||||||
|
Reference in New Issue
Block a user