mirror of
https://github.com/grafana/grafana.git
synced 2025-07-29 06:02:13 +08:00

By storing render key in remote cache it will enable image renderer to use public facing url or load balancer url to render images and thereby remove the requirement of image renderer having to use the url of the originating Grafana instance when running HA setup (multiple Grafana instances). Fixes #17704 Ref grafana/grafana-image-renderer#91
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package rendering
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
pluginModel "github.com/grafana/grafana-plugin-model/go/renderer"
|
|
)
|
|
|
|
func (rs *RenderingService) startPlugin(ctx context.Context) error {
|
|
return rs.pluginInfo.Start(ctx)
|
|
}
|
|
|
|
func (rs *RenderingService) renderViaPlugin(ctx context.Context, renderKey string, opts Opts) (*RenderResult, error) {
|
|
pngPath, err := rs.getFilePathForNewImage()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// gives plugin some additional time to timeout and return possible errors.
|
|
ctx, cancel := context.WithTimeout(ctx, opts.Timeout+time.Second*2)
|
|
defer cancel()
|
|
|
|
req := &pluginModel.RenderRequest{
|
|
Url: rs.getURL(opts.Path),
|
|
Width: int32(opts.Width),
|
|
Height: int32(opts.Height),
|
|
FilePath: pngPath,
|
|
Timeout: int32(opts.Timeout.Seconds()),
|
|
RenderKey: renderKey,
|
|
Encoding: opts.Encoding,
|
|
Timezone: isoTimeOffsetToPosixTz(opts.Timezone),
|
|
Domain: rs.domain,
|
|
}
|
|
rs.log.Debug("calling renderer plugin", "req", req)
|
|
|
|
rsp, err := rs.pluginInfo.GrpcPlugin.Render(ctx, req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if rsp.Error != "" {
|
|
return nil, fmt.Errorf("Rendering failed: %v", rsp.Error)
|
|
}
|
|
|
|
return &RenderResult{FilePath: pngPath}, err
|
|
}
|