From d18ac27126727e61230140bba25b459f498ecbc2 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Wed, 21 Oct 2020 10:52:08 +0200 Subject: [PATCH] App Plugins: Add backend support (#28272) (#28423) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add backend support for app plugins Co-authored-by: Marcus Efraimsson Co-authored-by: Arve Knudsen (cherry picked from commit 68efedfa88cd8b907aff2d101e88c7577014cb17) Co-authored-by: Joan López de la Franca Beltran --- pkg/plugins/app_plugin.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/plugins/app_plugin.go b/pkg/plugins/app_plugin.go index a6cbc3e279e..495b3a56a6f 100644 --- a/pkg/plugins/app_plugin.go +++ b/pkg/plugins/app_plugin.go @@ -2,12 +2,15 @@ package plugins import ( "encoding/json" + "path/filepath" "strings" "github.com/gosimple/slug" "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/plugins/backendplugin" + "github.com/grafana/grafana/pkg/plugins/backendplugin/grpcplugin" "github.com/grafana/grafana/pkg/setting" + "github.com/grafana/grafana/pkg/util/errutil" ) type AppPluginCss struct { @@ -21,6 +24,8 @@ type AppPlugin struct { FoundChildPlugins []*PluginInclude `json:"-"` Pinned bool `json:"-"` + + Executable string `json:"executable,omitempty"` } // AppPluginRoute describes a plugin route that is defined in @@ -67,6 +72,15 @@ func (app *AppPlugin) Load(decoder *json.Decoder, base *PluginBase, backendPlugi return err } + if app.Backend { + cmd := ComposePluginStartCommand(app.Executable) + fullpath := filepath.Join(app.PluginDir, cmd) + factory := grpcplugin.NewBackendPlugin(app.Id, fullpath, grpcplugin.PluginStartFuncs{}) + if err := backendPluginManager.Register(app.Id, factory); err != nil { + return errutil.Wrapf(err, "failed to register backend plugin") + } + } + Apps[app.Id] = app return nil }