From e9dc7fb85c74fef199a7b830f888fa52d4aeac2b Mon Sep 17 00:00:00 2001 From: Villena Guillaume Date: Thu, 3 Nov 2022 12:06:55 +0100 Subject: [PATCH] Rendering: Add configuration options for `renderKey` lifetime (#57339) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add configuration options for `renderKey` lifetime * Rename config key to `render_key_lifetime` * Update conf/defaults.ini Co-authored-by: Joan López de la Franca Beltran <5459617+joanlopez@users.noreply.github.com> * Add `render_key_lifetime` to sample.ini Co-authored-by: Joan López de la Franca Beltran <5459617+joanlopez@users.noreply.github.com> --- conf/defaults.ini | 5 +++++ conf/sample.ini | 7 ++++++- pkg/services/rendering/rendering.go | 2 +- pkg/setting/setting.go | 2 ++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/conf/defaults.ini b/conf/defaults.ini index f237b1bdd5f..e2e58ed8445 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -1134,6 +1134,11 @@ renderer_token = - # 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 +# Determines the lifetime of the render key used by the image renderer to access and render Grafana. +# This setting should be expressed as a duration. Examples: 10s (seconds), 5m (minutes), 2h (hours). +# Default is 5m. This should be more than enough for most deployments. +# Change the value only if image rendering is failing and you see `Failed to get the render key from cache` in Grafana logs. +render_key_lifetime = 5m [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 5ba3e8fd309..b482b0ea0ea 100644 --- a/conf/sample.ini +++ b/conf/sample.ini @@ -1099,6 +1099,11 @@ # 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 +# Determines the lifetime of the render key used by the image renderer to access and render Grafana. +# This setting should be expressed as a duration. Examples: 10s (seconds), 5m (minutes), 2h (hours). +# Default is 5m. This should be more than enough for most deployments. +# Change the value only if image rendering is failing and you see `Failed to get the render key from cache` in Grafana logs. +;render_key_lifetime = 5m [panels] # If set to true Grafana will allow script tags in text panels. Not recommended as it enable XSS vulnerabilities. @@ -1260,4 +1265,4 @@ # Move a specific app plugin page (referenced by its `path` field) to a specific navigation section [navigation.app_standalone_pages] # The following will move the page with the path "/a/my-app-id/starred-content" from `my-app-id` to the `starred` section -# /a/my-app-id/starred-content = starred \ No newline at end of file +# /a/my-app-id/starred-content = starred diff --git a/pkg/services/rendering/rendering.go b/pkg/services/rendering/rendering.go index 1ea316187d2..eccf441d887 100644 --- a/pkg/services/rendering/rendering.go +++ b/pkg/services/rendering/rendering.go @@ -91,7 +91,7 @@ func ProvideService(cfg *setting.Cfg, remoteCache *remotecache.RemoteCache, rm p perRequestRenderKeyProvider: &perRequestRenderKeyProvider{ cache: remoteCache, log: logger, - keyExpiry: 5 * time.Minute, + keyExpiry: cfg.RendererRenderKeyLifeTime, }, capabilities: []Capability{ { diff --git a/pkg/setting/setting.go b/pkg/setting/setting.go index 419f30a91ea..cf48a800f44 100644 --- a/pkg/setting/setting.go +++ b/pkg/setting/setting.go @@ -247,6 +247,7 @@ type Cfg struct { RendererCallbackUrl string RendererAuthToken string RendererConcurrentRequestLimit int + RendererRenderKeyLifeTime time.Duration // Security DisableInitAdminCreation bool @@ -1486,6 +1487,7 @@ func (cfg *Cfg) readRenderingSettings(iniFile *ini.File) error { } cfg.RendererConcurrentRequestLimit = renderSec.Key("concurrent_render_request_limit").MustInt(30) + cfg.RendererRenderKeyLifeTime = renderSec.Key("render_key_lifetime").MustDuration(5 * time.Minute) cfg.ImagesDir = filepath.Join(cfg.DataPath, "png") cfg.CSVsDir = filepath.Join(cfg.DataPath, "csv")