Chore: Change so we cache loading plugins by its version (#41367)

* making it possible to cache plugins based on the version.

* feat(plugincache): introduce function to invalidate entries

* removed todo's

* added tests for the cache buster.

* fixed tests.

* fixed failing tests.

Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com>
This commit is contained in:
Marcus Andersson
2021-11-10 11:54:58 +01:00
committed by GitHub
parent baab021fec
commit e5421dd53e
10 changed files with 138 additions and 21 deletions

View File

@@ -15,6 +15,11 @@ import (
"github.com/grafana/grafana/pkg/util"
)
type PreloadPlugin struct {
Path string `json:"path"`
Version string `json:"version"`
}
func (hs *HTTPServer) getFSDataSources(c *models.ReqContext, enabledPlugins EnabledPlugins) (map[string]interface{}, error) {
orgDataSources := make([]*models.DataSource, 0)
@@ -150,10 +155,13 @@ func (hs *HTTPServer) getFrontendSettingsMap(c *models.ReqContext) (map[string]i
return nil, err
}
pluginsToPreload := []string{}
pluginsToPreload := []*PreloadPlugin{}
for _, app := range enabledPlugins[plugins.App] {
if app.Preload {
pluginsToPreload = append(pluginsToPreload, app.Module)
pluginsToPreload = append(pluginsToPreload, &PreloadPlugin{
Path: app.Module,
Version: app.Info.Version,
})
}
}
@@ -171,7 +179,10 @@ func (hs *HTTPServer) getFrontendSettingsMap(c *models.ReqContext) (map[string]i
module, _ := dsM["module"].(string)
if preload, _ := dsM["preload"].(bool); preload && module != "" {
pluginsToPreload = append(pluginsToPreload, module)
pluginsToPreload = append(pluginsToPreload, &PreloadPlugin{
Path: module,
Version: dsM["info"].(map[string]interface{})["version"].(string),
})
}
}
@@ -182,7 +193,10 @@ func (hs *HTTPServer) getFrontendSettingsMap(c *models.ReqContext) (map[string]i
}
if panel.Preload {
pluginsToPreload = append(pluginsToPreload, panel.Module)
pluginsToPreload = append(pluginsToPreload, &PreloadPlugin{
Path: panel.Module,
Version: panel.Info.Version,
})
}
panels[panel.ID] = map[string]interface{}{