Commit 43073da7 by bergquist

feat(renderer): add timeout for the renderer api

closes #4325
parent 0b6fee13
...@@ -31,6 +31,7 @@ func RenderToPng(c *middleware.Context) { ...@@ -31,6 +31,7 @@ func RenderToPng(c *middleware.Context) {
Width: queryReader.Get("width", "800"), Width: queryReader.Get("width", "800"),
Height: queryReader.Get("height", "400"), Height: queryReader.Get("height", "400"),
SessionId: c.Session.ID(), SessionId: c.Session.ID(),
Timeout: queryReader.Get("timeout", "15"),
} }
renderOpts.Url = setting.ToAbsUrl(renderOpts.Url) renderOpts.Url = setting.ToAbsUrl(renderOpts.Url)
......
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
"github.com/grafana/grafana/pkg/log" "github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/util" "github.com/grafana/grafana/pkg/util"
"strconv"
) )
type RenderOpts struct { type RenderOpts struct {
...@@ -18,6 +19,7 @@ type RenderOpts struct { ...@@ -18,6 +19,7 @@ type RenderOpts struct {
Width string Width string
Height string Height string
SessionId string SessionId string
Timeout string
} }
func RenderToPng(params *RenderOpts) (string, error) { func RenderToPng(params *RenderOpts) (string, error) {
...@@ -60,8 +62,13 @@ func RenderToPng(params *RenderOpts) (string, error) { ...@@ -60,8 +62,13 @@ func RenderToPng(params *RenderOpts) (string, error) {
close(done) close(done)
}() }()
timeout, err := strconv.Atoi(params.Timeout)
if err != nil {
timeout = 15
}
select { select {
case <-time.After(15 * time.Second): case <-time.After(time.Duration(timeout) * time.Second):
if err := cmd.Process.Kill(); err != nil { if err := cmd.Process.Kill(); err != nil {
log.Error(4, "failed to kill: %v", err) log.Error(4, "failed to kill: %v", err)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment