Skip to content

Commit 67ad903

Browse files
committed
feat(test metrics): fixed issue with built in Grafana test data source, fixes grafana#5299
1 parent 36b0802 commit 67ad903

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

pkg/api/metrics.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/grafana/grafana/pkg/util"
1313
)
1414

15-
func GetTestMetrics(c *middleware.Context) {
15+
func GetTestMetrics(c *middleware.Context) Response {
1616
from := c.QueryInt64("from")
1717
to := c.QueryInt64("to")
1818
maxDataPoints := c.QueryInt64("maxDataPoints")
@@ -37,7 +37,7 @@ func GetTestMetrics(c *middleware.Context) {
3737
result.Data[seriesIndex].DataPoints = points
3838
}
3939

40-
c.JSON(200, &result)
40+
return Json(200, &result)
4141
}
4242

4343
func GetInternalMetrics(c *middleware.Context) Response {

public/app/features/panel/metrics_panel_ctrl.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ class MetricsPanelCtrl extends PanelCtrl {
200200
this.panel.snapshotData = result.data;
201201
}
202202

203+
if (!result || !result.data) {
204+
console.log('Data source query result invalid, missing data field:', result);
205+
result = {data: []};
206+
}
207+
203208
return this.events.emit('data-received', result.data);
204209
}
205210

0 commit comments

Comments
 (0)