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