mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 20:24:18 -06:00
80d694d205
* 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
66 lines
1.6 KiB
Go
66 lines
1.6 KiB
Go
package api
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"strconv"
|
|
"time"
|
|
|
|
m "github.com/grafana/grafana/pkg/models"
|
|
"github.com/grafana/grafana/pkg/services/rendering"
|
|
"github.com/grafana/grafana/pkg/util"
|
|
)
|
|
|
|
func (hs *HTTPServer) RenderToPng(c *m.ReqContext) {
|
|
queryReader, err := util.NewUrlQueryReader(c.Req.URL)
|
|
if err != nil {
|
|
c.Handle(400, "Render parameters error", err)
|
|
return
|
|
}
|
|
|
|
queryParams := fmt.Sprintf("?%s", c.Req.URL.RawQuery)
|
|
|
|
width, err := strconv.Atoi(queryReader.Get("width", "800"))
|
|
if err != nil {
|
|
c.Handle(400, "Render parameters error", fmt.Errorf("Cannot parse width as int: %s", err))
|
|
return
|
|
}
|
|
|
|
height, err := strconv.Atoi(queryReader.Get("height", "400"))
|
|
if err != nil {
|
|
c.Handle(400, "Render parameters error", fmt.Errorf("Cannot parse height as int: %s", err))
|
|
return
|
|
}
|
|
|
|
timeout, err := strconv.Atoi(queryReader.Get("timeout", "60"))
|
|
if err != nil {
|
|
c.Handle(400, "Render parameters error", fmt.Errorf("Cannot parse timeout as int: %s", err))
|
|
return
|
|
}
|
|
|
|
result, err := hs.RenderService.Render(c.Req.Context(), rendering.Opts{
|
|
Width: width,
|
|
Height: height,
|
|
Timeout: time.Duration(timeout) * time.Second,
|
|
OrgId: c.OrgId,
|
|
UserId: c.UserId,
|
|
OrgRole: c.OrgRole,
|
|
Path: c.Params("*") + queryParams,
|
|
Timezone: queryReader.Get("tz", ""),
|
|
Encoding: queryReader.Get("encoding", ""),
|
|
})
|
|
|
|
if err != nil && err == rendering.ErrTimeout {
|
|
c.Handle(500, err.Error(), err)
|
|
return
|
|
}
|
|
|
|
if err != nil {
|
|
c.Handle(500, "Rendering failed.", err)
|
|
return
|
|
}
|
|
|
|
c.Resp.Header().Set("Content-Type", "image/png")
|
|
http.ServeFile(c.Resp, c.Req.Request, result.FilePath)
|
|
}
|