Skip to content

Commit 53fe3b5

Browse files
authored
feat(rendering): support image legacy d-solo render mode, close #750 (#751)
1 parent 4ecce85 commit 53fe3b5

2 files changed

Lines changed: 27 additions & 17 deletions

File tree

tools/rendering.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,18 @@ func buildRenderURL(baseURL string, args GetPanelImageParams) (string, error) {
174174
// Strip trailing slashes from base URL for consistent URL construction
175175
baseURL = strings.TrimRight(baseURL, "/")
176176

177-
// Build the render path
178-
renderPath := fmt.Sprintf("/render/d/%s", args.DashboardUID)
179-
180177
// Build query parameters
181178
params := url.Values{}
182179

180+
// Single-panel renders use the purpose-built /d-solo route (lighter than loading
181+
// the full dashboard with viewPanel). Full dashboard renders use /d as default.
182+
renderPath := fmt.Sprintf("/render/d/%s", args.DashboardUID)
183+
184+
if args.PanelID != nil {
185+
renderPath = fmt.Sprintf("/render/d-solo/%s", args.DashboardUID)
186+
params.Set("panelId", strconv.Itoa(*args.PanelID))
187+
}
188+
183189
// Set dimensions
184190
width := 1000
185191
height := 500
@@ -199,11 +205,6 @@ func buildRenderURL(baseURL string, args GetPanelImageParams) (string, error) {
199205
}
200206
params.Set("scale", strconv.Itoa(scale))
201207

202-
// Add panel ID if specified (for single panel rendering)
203-
if args.PanelID != nil {
204-
params.Set("viewPanel", strconv.Itoa(*args.PanelID))
205-
}
206-
207208
// Add time range
208209
if args.TimeRange != nil {
209210
if args.TimeRange.From != "" {

tools/rendering_test.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,11 @@ func TestGetPanelImageParams_UnmarshalVariables(t *testing.T) {
148148

149149
func TestBuildRenderURL(t *testing.T) {
150150
tests := []struct {
151-
name string
152-
baseURL string
153-
args GetPanelImageParams
154-
contains []string
151+
name string
152+
baseURL string
153+
args GetPanelImageParams
154+
contains []string
155+
notContains []string
155156
}{
156157
{
157158
name: "Basic dashboard render",
@@ -168,7 +169,7 @@ func TestBuildRenderURL(t *testing.T) {
168169
},
169170
},
170171
{
171-
name: "Panel render with custom dimensions",
172+
name: "Panel render with custom dimensions uses d-solo path",
172173
baseURL: "http://localhost:3000",
173174
args: GetPanelImageParams{
174175
DashboardUID: "abc123",
@@ -177,11 +178,15 @@ func TestBuildRenderURL(t *testing.T) {
177178
Height: intPtr(600),
178179
},
179180
contains: []string{
180-
"http://localhost:3000/render/d/abc123",
181-
"viewPanel=5",
181+
"http://localhost:3000/render/d-solo/abc123",
182+
"panelId=5",
182183
"width=800",
183184
"height=600",
184185
},
186+
notContains: []string{
187+
"/render/d/abc123",
188+
"viewPanel=",
189+
},
185190
},
186191
{
187192
name: "With time range",
@@ -269,6 +274,9 @@ func TestBuildRenderURL(t *testing.T) {
269274
for _, expected := range tt.contains {
270275
assert.Contains(t, result, expected)
271276
}
277+
for _, unexpected := range tt.notContains {
278+
assert.NotContains(t, result, unexpected)
279+
}
272280
})
273281
}
274282
}
@@ -328,9 +336,10 @@ func TestGetPanelImage(t *testing.T) {
328336
}
329337
})
330338

331-
t.Run("Panel image with specific panel ID", func(t *testing.T) {
339+
t.Run("Panel image with specific panel ID uses d-solo path and panelId param", func(t *testing.T) {
332340
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
333-
assert.Equal(t, "5", r.URL.Query().Get("viewPanel"))
341+
assert.Contains(t, r.URL.Path, "/render/d-solo/test-dash")
342+
assert.Equal(t, "5", r.URL.Query().Get("panelId"))
334343

335344
w.Header().Set("Content-Type", "image/png")
336345
w.WriteHeader(http.StatusOK)

0 commit comments

Comments
 (0)