From 76650e60e472d173c071ff2dcec7f09643d86e07 Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Mon, 27 Apr 2020 17:25:08 +0200 Subject: [PATCH] Image Rendering: New setting to control render request concurrency (#23950) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #23806 Co-Authored-By: Torkel Ödegaard Co-Authored-By: Arve Knudsen --- conf/defaults.ini | 3 +++ conf/sample.ini | 3 +++ docs/sources/installation/configuration.md | 5 +++++ pkg/api/render.go | 3 +-- pkg/setting/setting.go | 11 ++++++----- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/conf/defaults.ini b/conf/defaults.ini index e36da638225..8574ab35498 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -683,6 +683,9 @@ container_name = server_url = # If the remote HTTP image renderer service runs on a different server than the Grafana server you may have to configure this to a URL where Grafana is reachable, e.g. http://grafana.domain/. callback_url = +# Concurrent render request limit affects when the /render HTTP endpoint is used. Rendering many images at the same time can overload the server, +# which this setting can help protect against by only allowing a certain amount of concurrent requests. +concurrent_render_request_limit = 30 [panels] # here for to support old env variables, can remove after a few months diff --git a/conf/sample.ini b/conf/sample.ini index 650e3f51f94..6d180436415 100644 --- a/conf/sample.ini +++ b/conf/sample.ini @@ -673,6 +673,9 @@ ;server_url = # If the remote HTTP image renderer service runs on a different server than the Grafana server you may have to configure this to a URL where Grafana is reachable, e.g. http://grafana.domain/. ;callback_url = +# Concurrent render request limit affects when the /render HTTP endpoint is used. Rendering many images at the same time can overload the server, +# which this setting can help protect against by only allowing a certain amount of concurrent requests. +;concurrent_render_request_limit = 30 [panels] # If set to true Grafana will allow script tags in text panels. Not recommended as it enable XSS vulnerabilities. diff --git a/docs/sources/installation/configuration.md b/docs/sources/installation/configuration.md index b495f2187c4..3a9a9611f48 100644 --- a/docs/sources/installation/configuration.md +++ b/docs/sources/installation/configuration.md @@ -822,6 +822,11 @@ URL to a remote HTTP image renderer service, e.g. http://localhost:8081/render, If the remote HTTP image renderer service runs on a different server than the Grafana server you may have to configure this to a URL where Grafana is reachable, e.g. http://grafana.domain/. +### concurrent_render_request_limit + +Concurrent render request limit affects when the /render HTTP endpoint is used. Rendering many images at the same time can overload the server, +which this setting can help protect against by only allowing a certain amount of concurrent requests. + ## [panels] ### disable_sanitize_html diff --git a/pkg/api/render.go b/pkg/api/render.go index bc1a20b076e..898e7ff929d 100644 --- a/pkg/api/render.go +++ b/pkg/api/render.go @@ -52,7 +52,6 @@ func (hs *HTTPServer) RenderToPng(c *models.ReqContext) { headers["Accept-Language"] = acceptLanguageHeader } - maxConcurrentLimitForApiCalls := 30 result, err := hs.RenderService.Render(c.Req.Context(), rendering.Opts{ Width: width, Height: height, @@ -63,7 +62,7 @@ func (hs *HTTPServer) RenderToPng(c *models.ReqContext) { Path: c.Params("*") + queryParams, Timezone: queryReader.Get("tz", ""), Encoding: queryReader.Get("encoding", ""), - ConcurrentLimit: maxConcurrentLimitForApiCalls, + ConcurrentLimit: hs.Cfg.RendererConcurrentRequestLimit, DeviceScaleFactor: scale, Headers: headers, }) diff --git a/pkg/setting/setting.go b/pkg/setting/setting.go index 15d343b5c54..c7838457ef7 100644 --- a/pkg/setting/setting.go +++ b/pkg/setting/setting.go @@ -238,11 +238,10 @@ type Cfg struct { Smtp SmtpSettings // Rendering - ImagesDir string - RendererUrl string - RendererCallbackUrl string - RendererLimit int - RendererLimitAlerting int + ImagesDir string + RendererUrl string + RendererCallbackUrl string + RendererConcurrentRequestLimit int // Security DisableInitAdminCreation bool @@ -938,6 +937,8 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error { log.Fatal(4, "Invalid callback_url(%s): %s", cfg.RendererCallbackUrl, err) } } + cfg.RendererConcurrentRequestLimit = renderSec.Key("concurrent_render_request_limit").MustInt(30) + cfg.ImagesDir = filepath.Join(cfg.DataPath, "png") cfg.TempDataLifetime = iniFile.Section("paths").Key("temp_data_lifetime").MustDuration(time.Second * 3600 * 24) cfg.MetricsEndpointEnabled = iniFile.Section("metrics").Key("enabled").MustBool(true)