Backend image rendering as plugin (#11966)

* rendering: headless chrome progress

* renderer: minor change

* grpc: version hell

* updated grpc libs

* wip: minor progess

* rendering: new image rendering plugin is starting to work

* feat: now phantomjs works as well and updated alerting to use new rendering service

* refactor: renamed renderer package and service to rendering to make renderer name less confusing (rendering is internal service that handles the renderer plugin now)

* rendering: now render key is passed and render auth is working in plugin mode

* removed unneeded lines from gitignore

* rendering: now plugin mode supports waiting for all panels to complete rendering

* fix: LastSeenAt fix for render calls, was not set which causes a lot of updates to Last Seen at during rendering, this should fix sqlite db locked issues in seen in previous releases

* change: changed render tz url parameter to use proper timezone name as chrome does not handle UTC offset TZ values

* fix: another update to tz param generation

* renderer: added http mode to renderer service, new ini setting [rendering] server_url
This commit is contained in:
Torkel Ödegaard
2018-05-24 15:26:27 +02:00
committed by GitHub
parent ca7bbc44c0
commit 80d694d205
435 changed files with 35938 additions and 18443 deletions

View File

@@ -3,14 +3,15 @@ package alerting
import (
"errors"
"fmt"
"time"
"golang.org/x/sync/errgroup"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/components/imguploader"
"github.com/grafana/grafana/pkg/components/renderer"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/metrics"
"github.com/grafana/grafana/pkg/services/rendering"
m "github.com/grafana/grafana/pkg/models"
)
@@ -27,18 +28,16 @@ type NotificationService interface {
SendIfNeeded(context *EvalContext) error
}
func NewNotificationService() NotificationService {
return newNotificationService()
func NewNotificationService(renderService rendering.Service) NotificationService {
return &notificationService{
log: log.New("alerting.notifier"),
renderService: renderService,
}
}
type notificationService struct {
log log.Logger
}
func newNotificationService() *notificationService {
return &notificationService{
log: log.New("alerting.notifier"),
}
log log.Logger
renderService rendering.Service
}
func (n *notificationService) SendIfNeeded(context *EvalContext) error {
@@ -79,26 +78,27 @@ func (n *notificationService) uploadImage(context *EvalContext) (err error) {
return err
}
renderOpts := &renderer.RenderOpts{
Width: "800",
Height: "400",
Timeout: "30",
OrgId: context.Rule.OrgId,
IsAlertContext: true,
renderOpts := rendering.Opts{
Width: 1000,
Height: 500,
Timeout: time.Second * 30,
OrgId: context.Rule.OrgId,
OrgRole: m.ROLE_ADMIN,
}
ref, err := context.GetDashboardUID()
if err != nil {
return err
}
renderOpts.Path = fmt.Sprintf("d-solo/%s/%s?panelId=%d", ref.Uid, ref.Slug, context.Rule.PanelId)
imagePath, err := renderer.RenderToPng(renderOpts)
result, err := n.renderService.Render(context.Ctx, renderOpts)
if err != nil {
return err
}
context.ImageOnDiskPath = imagePath
context.ImageOnDiskPath = result.FilePath
context.ImagePublicUrl, err = uploader.Upload(context.Ctx, context.ImageOnDiskPath)
if err != nil {
return err