diff --git a/pkg/api/metrics.go b/pkg/api/metrics.go index 35359d57cdd..dc674e770ae 100644 --- a/pkg/api/metrics.go +++ b/pkg/api/metrics.go @@ -12,7 +12,7 @@ import ( "github.com/grafana/grafana/pkg/util" ) -func GetTestMetrics(c *middleware.Context) { +func GetTestMetrics(c *middleware.Context) Response { from := c.QueryInt64("from") to := c.QueryInt64("to") maxDataPoints := c.QueryInt64("maxDataPoints") @@ -37,7 +37,7 @@ func GetTestMetrics(c *middleware.Context) { result.Data[seriesIndex].DataPoints = points } - c.JSON(200, &result) + return Json(200, &result) } func GetInternalMetrics(c *middleware.Context) Response { diff --git a/public/app/features/panel/metrics_panel_ctrl.ts b/public/app/features/panel/metrics_panel_ctrl.ts index 0bccee8ff35..0a283cd983f 100644 --- a/public/app/features/panel/metrics_panel_ctrl.ts +++ b/public/app/features/panel/metrics_panel_ctrl.ts @@ -200,6 +200,11 @@ class MetricsPanelCtrl extends PanelCtrl { this.panel.snapshotData = result.data; } + if (!result || !result.data) { + console.log('Data source query result invalid, missing data field:', result); + result = {data: []}; + } + return this.events.emit('data-received', result.data); }