39 Star 144 Fork 3

Gitee 极速下载 / grafana

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/grafana/grafana
克隆/下载
plugin_mode.go 2.30 KB
一键复制 编辑 原始数据 按行查看 历史
package rendering
import (
"context"
"fmt"
"os/exec"
"path"
"time"
pluginModel "github.com/grafana/grafana-plugin-model/go/renderer"
"github.com/grafana/grafana/pkg/plugins"
plugin "github.com/hashicorp/go-plugin"
)
func (rs *RenderingService) startPlugin(ctx context.Context) error {
cmd := plugins.ComposePluginStartCommmand("plugin_start")
fullpath := path.Join(rs.pluginInfo.PluginDir, cmd)
var handshakeConfig = plugin.HandshakeConfig{
ProtocolVersion: 1,
MagicCookieKey: "grafana_plugin_type",
MagicCookieValue: "renderer",
}
rs.log.Info("Renderer plugin found, starting", "cmd", cmd)
rs.pluginClient = plugin.NewClient(&plugin.ClientConfig{
HandshakeConfig: handshakeConfig,
Plugins: map[string]plugin.Plugin{
plugins.Renderer.Id: &pluginModel.RendererPluginImpl{},
},
Cmd: exec.Command(fullpath),
AllowedProtocols: []plugin.Protocol{plugin.ProtocolGRPC},
Logger: plugins.LogWrapper{Logger: rs.log},
})
rpcClient, err := rs.pluginClient.Client()
if err != nil {
return err
}
raw, err := rpcClient.Dispense(rs.pluginInfo.Id)
if err != nil {
return err
}
rs.grpcPlugin = raw.(pluginModel.RendererPlugin)
return nil
}
func (rs *RenderingService) watchAndRestartPlugin(ctx context.Context) error {
ticker := time.NewTicker(time.Second * 1)
for {
select {
case <-ctx.Done():
return ctx.Err()
case <-ticker.C:
if rs.pluginClient.Exited() {
err := rs.startPlugin(ctx)
rs.log.Debug("Render plugin existed, restarting...")
if err != nil {
rs.log.Error("Failed to start render plugin", err)
}
}
}
}
}
func (rs *RenderingService) renderViaPlugin(ctx context.Context, opts Opts) (*RenderResult, error) {
pngPath := rs.getFilePathForNewImage()
rsp, err := rs.grpcPlugin.Render(ctx, &pluginModel.RenderRequest{
Url: rs.getURL(opts.Path),
Width: int32(opts.Width),
Height: int32(opts.Height),
FilePath: pngPath,
Timeout: int32(opts.Timeout.Seconds()),
RenderKey: rs.getRenderKey(opts.OrgId, opts.UserId, opts.OrgRole),
Encoding: opts.Encoding,
Timezone: isoTimeOffsetToPosixTz(opts.Timezone),
Domain: rs.domain,
})
if err != nil {
return nil, err
}
if rsp.Error != "" {
return nil, fmt.Errorf("Rendering failed: %v", rsp.Error)
}
return &RenderResult{FilePath: pngPath}, err
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/mirrors/grafana.git
git@gitee.com:mirrors/grafana.git
mirrors
grafana
grafana
v5.4.4

搜索帮助

344bd9b3 5694891 D2dac590 5694891