mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Image Rendering: Make it work using serve_from_sub_path configured (#23706)
Make rendering work when using serve_from_sub_path and not have rendering.renderer_url configured. Fixes #21925
This commit is contained in:
parent
ea1dd9e4da
commit
61de19250d
@ -186,8 +186,13 @@ func (rs *RenderingService) getURL(path string) string {
|
|||||||
protocol = "https"
|
protocol = "https"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
subPath := ""
|
||||||
|
if rs.Cfg.ServeFromSubPath {
|
||||||
|
subPath = rs.Cfg.AppSubUrl
|
||||||
|
}
|
||||||
|
|
||||||
// &render=1 signals to the legacy redirect layer to
|
// &render=1 signals to the legacy redirect layer to
|
||||||
return fmt.Sprintf("%s://%s:%s/%s&render=1", protocol, rs.domain, setting.HttpPort, path)
|
return fmt.Sprintf("%s://%s:%s%s/%s&render=1", protocol, rs.domain, setting.HttpPort, subPath, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *RenderingService) generateAndStoreRenderKey(orgId, userId int64, orgRole models.RoleType) (string, error) {
|
func (rs *RenderingService) generateAndStoreRenderKey(orgId, userId int64, orgRole models.RoleType) (string, error) {
|
||||||
|
59
pkg/services/rendering/rendering_test.go
Normal file
59
pkg/services/rendering/rendering_test.go
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
package rendering
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetUrl(t *testing.T) {
|
||||||
|
path := "render/d-solo/5SdHCadmz/panel-tests-graph?orgId=1&from=1587390211965&to=1587393811965&panelId=5&width=1000&height=500&tz=Europe%2FStockholm"
|
||||||
|
rs := &RenderingService{
|
||||||
|
Cfg: setting.NewCfg(),
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Run("When renderer and callback url configured should return callback url plus path", func(t *testing.T) {
|
||||||
|
rs.Cfg.RendererUrl = "http://localhost:8081/render"
|
||||||
|
rs.Cfg.RendererCallbackUrl = "http://public-grafana.com/"
|
||||||
|
url := rs.getURL(path)
|
||||||
|
require.Equal(t, rs.Cfg.RendererCallbackUrl+path+"&render=1", url)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("When renderer url not configured", func(t *testing.T) {
|
||||||
|
rs.Cfg.RendererUrl = ""
|
||||||
|
rs.domain = "localhost"
|
||||||
|
setting.HttpPort = "3000"
|
||||||
|
|
||||||
|
t.Run("And protocol HTTP configured should return expected path", func(t *testing.T) {
|
||||||
|
rs.Cfg.ServeFromSubPath = false
|
||||||
|
rs.Cfg.AppSubUrl = ""
|
||||||
|
setting.Protocol = setting.HTTP
|
||||||
|
url := rs.getURL(path)
|
||||||
|
require.Equal(t, "http://localhost:3000/"+path+"&render=1", url)
|
||||||
|
|
||||||
|
t.Run("And serve from sub path should return expected path", func(t *testing.T) {
|
||||||
|
rs.Cfg.ServeFromSubPath = true
|
||||||
|
rs.Cfg.AppSubUrl = "/grafana"
|
||||||
|
url := rs.getURL(path)
|
||||||
|
require.Equal(t, "http://localhost:3000/grafana/"+path+"&render=1", url)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("And protocol HTTPS configured should return expected path", func(t *testing.T) {
|
||||||
|
rs.Cfg.ServeFromSubPath = false
|
||||||
|
rs.Cfg.AppSubUrl = ""
|
||||||
|
setting.Protocol = setting.HTTPS
|
||||||
|
url := rs.getURL(path)
|
||||||
|
require.Equal(t, "https://localhost:3000/"+path+"&render=1", url)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("And protocol HTTP2 configured should return expected path", func(t *testing.T) {
|
||||||
|
rs.Cfg.ServeFromSubPath = false
|
||||||
|
rs.Cfg.AppSubUrl = ""
|
||||||
|
setting.Protocol = setting.HTTP2
|
||||||
|
url := rs.getURL(path)
|
||||||
|
require.Equal(t, "https://localhost:3000/"+path+"&render=1", url)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user