2018-05-24 15:26:27 +02:00
|
|
|
package rendering
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2020-01-17 12:07:16 +01:00
|
|
|
"time"
|
2018-05-24 15:26:27 +02:00
|
|
|
|
|
|
|
pluginModel "github.com/grafana/grafana-plugin-model/go/renderer"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (rs *RenderingService) startPlugin(ctx context.Context) error {
|
2020-01-08 17:43:28 +01:00
|
|
|
return rs.pluginInfo.Start(ctx)
|
2018-05-24 15:26:27 +02:00
|
|
|
}
|
|
|
|
|
2020-02-19 19:47:39 +01:00
|
|
|
func (rs *RenderingService) renderViaPlugin(ctx context.Context, renderKey string, opts Opts) (*RenderResult, error) {
|
2019-10-23 10:40:12 +02:00
|
|
|
pngPath, err := rs.getFilePathForNewImage()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-01-17 12:07:16 +01:00
|
|
|
// gives plugin some additional time to timeout and return possible errors.
|
|
|
|
ctx, cancel := context.WithTimeout(ctx, opts.Timeout+time.Second*2)
|
2019-11-18 16:58:15 +01:00
|
|
|
defer cancel()
|
|
|
|
|
2019-12-11 15:06:59 +01:00
|
|
|
req := &pluginModel.RenderRequest{
|
2018-05-24 15:26:27 +02:00
|
|
|
Url: rs.getURL(opts.Path),
|
|
|
|
Width: int32(opts.Width),
|
|
|
|
Height: int32(opts.Height),
|
|
|
|
FilePath: pngPath,
|
|
|
|
Timeout: int32(opts.Timeout.Seconds()),
|
2019-10-23 10:40:12 +02:00
|
|
|
RenderKey: renderKey,
|
2018-05-24 15:26:27 +02:00
|
|
|
Encoding: opts.Encoding,
|
|
|
|
Timezone: isoTimeOffsetToPosixTz(opts.Timezone),
|
2018-09-04 19:42:55 +08:00
|
|
|
Domain: rs.domain,
|
2019-12-11 15:06:59 +01:00
|
|
|
}
|
|
|
|
rs.log.Debug("calling renderer plugin", "req", req)
|
|
|
|
|
2020-01-08 17:43:28 +01:00
|
|
|
rsp, err := rs.pluginInfo.GrpcPlugin.Render(ctx, req)
|
2018-05-24 15:26:27 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if rsp.Error != "" {
|
|
|
|
return nil, fmt.Errorf("Rendering failed: %v", rsp.Error)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &RenderResult{FilePath: pngPath}, err
|
|
|
|
}
|