diff --git a/pkg/api/frontendsettings.go b/pkg/api/frontendsettings.go index cd61c2f3ebc..e19c5732467 100644 --- a/pkg/api/frontendsettings.go +++ b/pkg/api/frontendsettings.go @@ -46,6 +46,14 @@ func (hs *HTTPServer) getFrontendSettingsMap(c *m.ReqContext) (map[string]interf return nil, err } + pluginsToPreload := []string{} + + for _, app := range enabledPlugins.Apps { + if app.Preload { + pluginsToPreload = append(pluginsToPreload, app.Module) + } + } + for _, ds := range orgDataSources { url := ds.Url @@ -66,6 +74,10 @@ func (hs *HTTPServer) getFrontendSettingsMap(c *m.ReqContext) (map[string]interf continue } + if meta.Preload { + pluginsToPreload = append(pluginsToPreload, meta.Module) + } + dsMap["meta"] = meta if ds.IsDefault { @@ -137,6 +149,10 @@ func (hs *HTTPServer) getFrontendSettingsMap(c *m.ReqContext) (map[string]interf continue } + if panel.Preload { + pluginsToPreload = append(pluginsToPreload, panel.Module) + } + panels[panel.Id] = map[string]interface{}{ "module": panel.Module, "baseUrl": panel.BaseUrl, @@ -169,6 +185,7 @@ func (hs *HTTPServer) getFrontendSettingsMap(c *m.ReqContext) (map[string]interf "viewersCanEdit": setting.ViewersCanEdit, "editorsCanAdmin": hs.Cfg.EditorsCanAdmin, "disableSanitizeHtml": hs.Cfg.DisableSanitizeHtml, + "pluginsToPreload": pluginsToPreload, "buildInfo": map[string]interface{}{ "version": setting.BuildVersion, "commit": setting.BuildCommit, diff --git a/pkg/plugins/models.go b/pkg/plugins/models.go index 5ac436205c1..feeae936680 100644 --- a/pkg/plugins/models.go +++ b/pkg/plugins/models.go @@ -46,6 +46,7 @@ type PluginBase struct { Module string `json:"module"` BaseUrl string `json:"baseUrl"` HideFromList bool `json:"hideFromList,omitempty"` + Preload bool `json:"preload"` State PluginState `json:"state,omitempty"` IncludedInAppId string `json:"-"` diff --git a/public/app/app.ts b/public/app/app.ts index a54c9270e2c..7e898e52339 100644 --- a/public/app/app.ts +++ b/public/app/app.ts @@ -21,6 +21,7 @@ import config from 'app/core/config'; import _ from 'lodash'; import moment from 'moment'; import { addClassIfNoOverlayScrollbar } from 'app/core/utils/scrollbar'; +import { importPluginModule } from 'app/features/plugins/plugin_loader'; // add move to lodash for backward compatabiltiy _.move = (array: [], fromIndex: number, toIndex: number) => { @@ -145,6 +146,11 @@ export class GrafanaApp { this.preBootModules = null; }); + + // Preload selected app plugins + for (const modulePath of config.pluginsToPreload) { + importPluginModule(modulePath); + } } } diff --git a/public/app/core/config.ts b/public/app/core/config.ts index 26c7fa17698..58aaedffa7c 100644 --- a/public/app/core/config.ts +++ b/public/app/core/config.ts @@ -40,6 +40,7 @@ export class Settings { editorsCanAdmin: boolean; disableSanitizeHtml: boolean; theme: GrafanaTheme; + pluginsToPreload: string[]; constructor(options: Settings) { this.theme = options.bootData.user.lightTheme ? getTheme(GrafanaThemeType.Light) : getTheme(GrafanaThemeType.Dark); diff --git a/public/app/features/plugins/partials/plugin_edit.html b/public/app/features/plugins/partials/plugin_edit.html index d84196c47b0..56e0769757e 100644 --- a/public/app/features/plugins/partials/plugin_edit.html +++ b/public/app/features/plugins/partials/plugin_edit.html @@ -17,6 +17,7 @@ + diff --git a/public/app/features/plugins/plugin_loader.ts b/public/app/features/plugins/plugin_loader.ts index dd7667f5ae0..dfd61e80c6d 100644 --- a/public/app/features/plugins/plugin_loader.ts +++ b/public/app/features/plugins/plugin_loader.ts @@ -141,7 +141,7 @@ for (const flotDep of flotDeps) { exposeToPlugin(flotDep, { fakeDep: 1 }); } -function importPluginModule(path: string): Promise { +export function importPluginModule(path: string): Promise { const builtIn = builtInPlugins[path]; if (builtIn) { return Promise.resolve(builtIn);