mirror of
https://github.com/grafana/grafana.git
synced 2025-09-23 05:43:19 +08:00
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
This commit is contained in:

committed by
Torkel Ödegaard

parent
5e48750868
commit
d6887bf77f
@ -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,
|
||||
|
@ -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:"-"`
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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-danger" ng-click="ctrl.disable()" ng-show="ctrl.model.enabled">Disable</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -141,7 +141,7 @@ for (const flotDep of flotDeps) {
|
||||
exposeToPlugin(flotDep, { fakeDep: 1 });
|
||||
}
|
||||
|
||||
function importPluginModule(path: string): Promise<any> {
|
||||
export function importPluginModule(path: string): Promise<any> {
|
||||
const builtIn = builtInPlugins[path];
|
||||
if (builtIn) {
|
||||
return Promise.resolve(builtIn);
|
||||
|
Reference in New Issue
Block a user