Chore: Prevent preloaded plugins from crashing Grafana (#41490) (#44143)

* 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.

(cherry picked from commit e926126d63)
This commit is contained in:
Marcus Andersson
2022-01-18 14:06:04 +01:00
committed by GitHub
parent 60c64449b3
commit 723286cc8e
3 changed files with 18 additions and 8 deletions
+2 -7
View File
@@ -24,8 +24,8 @@ import {
standardTransformersRegistry,
} from '@grafana/data';
import { arrayMove } from 'app/core/utils/arrayMove';
import { importPluginModule } from 'app/features/plugins/plugin_loader';
import { registerEchoBackend, setEchoSrv, setPanelRenderer, setQueryRunnerFactory } from '@grafana/runtime';
import { preloadPlugins } from './features/plugins/pluginPreloader';
import { Echo } from './core/services/echo/Echo';
import { reportPerformance } from './core/services/echo/EchoSrv';
import { PerformanceBackend } from './core/services/echo/backends/PerformanceBackend';
@@ -106,12 +106,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, {
@@ -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);
}
}
+1 -1
View File
@@ -180,7 +180,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);