improve remote image rendering (#13102)
* improve remote image rendering - determine "domain" during Init() so we are not re-parsing settings on every request - if using http-mode via a rednererUrl, then use the AppUrl for the page that the renderer loads. When in http-mode the renderer is likely running on another server so trying to use the localhost or even the specific IP:PORT grafana is listening on wont work. - apply the request timeout via a context rather then directly on the http client. - use a global http client so we can take advantage of connection re-use - log and handle errors better. * ensure imagesDir exists * allow users to define callback_url for remote rendering - allow users to define the url that a remote rendering service should use for connecting back to the grafana instance. By default the "root_url" is used. * improve remote image rendering - determine "domain" during Init() so we are not re-parsing settings on every request - if using http-mode via a rednererUrl, then use the AppUrl for the page that the renderer loads. When in http-mode the renderer is likely running on another server so trying to use the localhost or even the specific IP:PORT grafana is listening on wont work. - apply the request timeout via a context rather then directly on the http client. - use a global http client so we can take advantage of connection re-use - log and handle errors better. * ensure imagesDir exists * allow users to define callback_url for remote rendering - allow users to define the url that a remote rendering service should use for connecting back to the grafana instance. By default the "root_url" is used. * rendering: fixed issue with renderKey where userId and orgId was in mixed up, added test for RenderCallbackUrl reading logic
This commit is contained in:
committed by
Torkel Ödegaard
parent
ce538007d8
commit
5c0fbbf7c8
@@ -197,6 +197,7 @@ type Cfg struct {
|
||||
ImagesDir string
|
||||
PhantomDir string
|
||||
RendererUrl string
|
||||
RendererCallbackUrl string
|
||||
DisableBruteForceLoginProtection bool
|
||||
|
||||
TempDataLifetime time.Duration
|
||||
@@ -641,6 +642,18 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error {
|
||||
// Rendering
|
||||
renderSec := iniFile.Section("rendering")
|
||||
cfg.RendererUrl = renderSec.Key("server_url").String()
|
||||
cfg.RendererCallbackUrl = renderSec.Key("callback_url").String()
|
||||
if cfg.RendererCallbackUrl == "" {
|
||||
cfg.RendererCallbackUrl = AppUrl
|
||||
} else {
|
||||
if cfg.RendererCallbackUrl[len(cfg.RendererCallbackUrl)-1] != '/' {
|
||||
cfg.RendererCallbackUrl += "/"
|
||||
}
|
||||
_, err := url.Parse(cfg.RendererCallbackUrl)
|
||||
if err != nil {
|
||||
log.Fatal(4, "Invalid callback_url(%s): %s", cfg.RendererCallbackUrl, err)
|
||||
}
|
||||
}
|
||||
cfg.ImagesDir = filepath.Join(DataPath, "png")
|
||||
cfg.PhantomDir = filepath.Join(HomePath, "tools/phantomjs")
|
||||
cfg.TempDataLifetime = iniFile.Section("paths").Key("temp_data_lifetime").MustDuration(time.Second * 3600 * 24)
|
||||
|
||||
@@ -20,6 +20,7 @@ func TestLoadingSettings(t *testing.T) {
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
So(AdminUser, ShouldEqual, "admin")
|
||||
So(cfg.RendererCallbackUrl, ShouldEqual, "http://localhost:3000/")
|
||||
})
|
||||
|
||||
Convey("Should be able to override via environment variables", func() {
|
||||
@@ -178,5 +179,15 @@ func TestLoadingSettings(t *testing.T) {
|
||||
So(InstanceName, ShouldEqual, hostname)
|
||||
})
|
||||
|
||||
Convey("Reading callback_url should add trailing slash", func() {
|
||||
cfg := NewCfg()
|
||||
cfg.Load(&CommandLineArgs{
|
||||
HomePath: "../../",
|
||||
Args: []string{"cfg:rendering.callback_url=http://myserver/renderer"},
|
||||
})
|
||||
|
||||
So(cfg.RendererCallbackUrl, ShouldEqual, "http://myserver/renderer/")
|
||||
})
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user