Commit d6887bf7 by Ryan McKinley Committed by Torkel Ödegaard

Plugins: Optionally preload some plugins during frontend app boot (#15266)

* auto load

* update comments

* gofmt

* use preload from json

* fix formatting

* change general plugin loader to app

* Refactoring: Plugin preloading #15266
parent 5e487508
...@@ -46,6 +46,14 @@ func (hs *HTTPServer) getFrontendSettingsMap(c *m.ReqContext) (map[string]interf ...@@ -46,6 +46,14 @@ func (hs *HTTPServer) getFrontendSettingsMap(c *m.ReqContext) (map[string]interf
return nil, err return nil, err
} }
pluginsToPreload := []string{}
for _, app := range enabledPlugins.Apps {
if app.Preload {
pluginsToPreload = append(pluginsToPreload, app.Module)
}
}
for _, ds := range orgDataSources { for _, ds := range orgDataSources {
url := ds.Url url := ds.Url
...@@ -66,6 +74,10 @@ func (hs *HTTPServer) getFrontendSettingsMap(c *m.ReqContext) (map[string]interf ...@@ -66,6 +74,10 @@ func (hs *HTTPServer) getFrontendSettingsMap(c *m.ReqContext) (map[string]interf
continue continue
} }
if meta.Preload {
pluginsToPreload = append(pluginsToPreload, meta.Module)
}
dsMap["meta"] = meta dsMap["meta"] = meta
if ds.IsDefault { if ds.IsDefault {
...@@ -137,6 +149,10 @@ func (hs *HTTPServer) getFrontendSettingsMap(c *m.ReqContext) (map[string]interf ...@@ -137,6 +149,10 @@ func (hs *HTTPServer) getFrontendSettingsMap(c *m.ReqContext) (map[string]interf
continue continue
} }
if panel.Preload {
pluginsToPreload = append(pluginsToPreload, panel.Module)
}
panels[panel.Id] = map[string]interface{}{ panels[panel.Id] = map[string]interface{}{
"module": panel.Module, "module": panel.Module,
"baseUrl": panel.BaseUrl, "baseUrl": panel.BaseUrl,
...@@ -169,6 +185,7 @@ func (hs *HTTPServer) getFrontendSettingsMap(c *m.ReqContext) (map[string]interf ...@@ -169,6 +185,7 @@ func (hs *HTTPServer) getFrontendSettingsMap(c *m.ReqContext) (map[string]interf
"viewersCanEdit": setting.ViewersCanEdit, "viewersCanEdit": setting.ViewersCanEdit,
"editorsCanAdmin": hs.Cfg.EditorsCanAdmin, "editorsCanAdmin": hs.Cfg.EditorsCanAdmin,
"disableSanitizeHtml": hs.Cfg.DisableSanitizeHtml, "disableSanitizeHtml": hs.Cfg.DisableSanitizeHtml,
"pluginsToPreload": pluginsToPreload,
"buildInfo": map[string]interface{}{ "buildInfo": map[string]interface{}{
"version": setting.BuildVersion, "version": setting.BuildVersion,
"commit": setting.BuildCommit, "commit": setting.BuildCommit,
......
...@@ -46,6 +46,7 @@ type PluginBase struct { ...@@ -46,6 +46,7 @@ type PluginBase struct {
Module string `json:"module"` Module string `json:"module"`
BaseUrl string `json:"baseUrl"` BaseUrl string `json:"baseUrl"`
HideFromList bool `json:"hideFromList,omitempty"` HideFromList bool `json:"hideFromList,omitempty"`
Preload bool `json:"preload"`
State PluginState `json:"state,omitempty"` State PluginState `json:"state,omitempty"`
IncludedInAppId string `json:"-"` IncludedInAppId string `json:"-"`
......
...@@ -21,6 +21,7 @@ import config from 'app/core/config'; ...@@ -21,6 +21,7 @@ import config from 'app/core/config';
import _ from 'lodash'; import _ from 'lodash';
import moment from 'moment'; import moment from 'moment';
import { addClassIfNoOverlayScrollbar } from 'app/core/utils/scrollbar'; import { addClassIfNoOverlayScrollbar } from 'app/core/utils/scrollbar';
import { importPluginModule } from 'app/features/plugins/plugin_loader';
// add move to lodash for backward compatabiltiy // add move to lodash for backward compatabiltiy
_.move = (array: [], fromIndex: number, toIndex: number) => { _.move = (array: [], fromIndex: number, toIndex: number) => {
...@@ -145,6 +146,11 @@ export class GrafanaApp { ...@@ -145,6 +146,11 @@ export class GrafanaApp {
this.preBootModules = null; this.preBootModules = null;
}); });
// Preload selected app plugins
for (const modulePath of config.pluginsToPreload) {
importPluginModule(modulePath);
}
} }
} }
......
...@@ -40,6 +40,7 @@ export class Settings { ...@@ -40,6 +40,7 @@ export class Settings {
editorsCanAdmin: boolean; editorsCanAdmin: boolean;
disableSanitizeHtml: boolean; disableSanitizeHtml: boolean;
theme: GrafanaTheme; theme: GrafanaTheme;
pluginsToPreload: string[];
constructor(options: Settings) { constructor(options: Settings) {
this.theme = options.bootData.user.lightTheme ? getTheme(GrafanaThemeType.Light) : getTheme(GrafanaThemeType.Dark); this.theme = options.bootData.user.lightTheme ? getTheme(GrafanaThemeType.Light) : getTheme(GrafanaThemeType.Dark);
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
<button type="submit" class="btn btn-primary" ng-click="ctrl.update()" ng-show="ctrl.model.enabled">Update</button> <button type="submit" class="btn btn-primary" ng-click="ctrl.update()" ng-show="ctrl.model.enabled">Update</button>
<button type="submit" class="btn btn-danger" ng-click="ctrl.disable()" ng-show="ctrl.model.enabled">Disable</button> <button type="submit" class="btn btn-danger" ng-click="ctrl.disable()" ng-show="ctrl.model.enabled">Disable</button>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -141,7 +141,7 @@ for (const flotDep of flotDeps) { ...@@ -141,7 +141,7 @@ for (const flotDep of flotDeps) {
exposeToPlugin(flotDep, { fakeDep: 1 }); exposeToPlugin(flotDep, { fakeDep: 1 });
} }
function importPluginModule(path: string): Promise<any> { export function importPluginModule(path: string): Promise<any> {
const builtIn = builtInPlugins[path]; const builtIn = builtInPlugins[path];
if (builtIn) { if (builtIn) {
return Promise.resolve(builtIn); return Promise.resolve(builtIn);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment