From 7333f7ca17932bfda5815cafe2a9c8fa1a9289a3 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Tue, 14 May 2019 08:47:41 -0700 Subject: [PATCH] Streaming: support streaming in MetricsPanelCtrl (#17034) * support streaming in angular panels * keep the same dashboard number --- .../app/features/panel/metrics_panel_ctrl.ts | 41 ++++--- .../testdata/dashboards/streaming.json | 103 +++++++++++++++++- 2 files changed, 126 insertions(+), 18 deletions(-) diff --git a/public/app/features/panel/metrics_panel_ctrl.ts b/public/app/features/panel/metrics_panel_ctrl.ts index 068aa03d0f9..f7f4552d76b 100644 --- a/public/app/features/panel/metrics_panel_ctrl.ts +++ b/public/app/features/panel/metrics_panel_ctrl.ts @@ -129,25 +129,36 @@ class MetricsPanelCtrl extends PanelCtrl { if (data.state === LoadingState.Error) { this.loading = false; this.processDataError(data.error); - } else if (data.state === LoadingState.Done) { - this.loading = false; + return; + } - // The result should already be processed, but just in case - if (!data.legacy) { - data.legacy = data.series.map(v => { - if (isSeriesData(v)) { - return toLegacyResponseData(v); - } - return v; - }); - } + this.loading = false; - // Make the results look like they came directly from a <6.2 datasource request - // NOTE: any object other than 'data' is no longer supported supported - this.handleQueryResult({ - data: data.legacy, + // The result should already be processed, but just in case + if (!data.legacy) { + data.legacy = data.series.map(v => { + if (isSeriesData(v)) { + return toLegacyResponseData(v); + } + return v; }); } + + if (data.request) { + const { range, timeInfo } = data.request; + if (range) { + this.range = range; + } + if (timeInfo) { + this.timeInfo = timeInfo; + } + } + + // Make the results look like they came directly from a <6.2 datasource request + // NOTE: any object other than 'data' is no longer supported supported + this.handleQueryResult({ + data: data.legacy, + }); }, }; diff --git a/public/app/plugins/datasource/testdata/dashboards/streaming.json b/public/app/plugins/datasource/testdata/dashboards/streaming.json index b2f2e9ecb6b..9f38d2096ef 100644 --- a/public/app/plugins/datasource/testdata/dashboards/streaming.json +++ b/public/app/plugins/datasource/testdata/dashboards/streaming.json @@ -14,7 +14,13 @@ "type": "grafana", "id": "grafana", "name": "Grafana", - "version": "6.2.0-pre" + "version": "6.3.0-pre" + }, + { + "type": "panel", + "id": "graph", + "name": "Graph", + "version": "" }, { "type": "panel", @@ -48,6 +54,97 @@ "id": null, "links": [], "panels": [ + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "fill": 1, + "gridPos": { + "h": 7, + "w": 24, + "x": 0, + "y": 0 + }, + "id": 4, + "legend": { + "alignAsTable": true, + "avg": false, + "current": true, + "max": false, + "min": false, + "rightSide": true, + "show": true, + "total": false, + "values": true + }, + "lines": true, + "linewidth": 1, + "links": [], + "nullPointMode": "null", + "percentage": false, + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "refId": "A", + "scenarioId": "streaming_client", + "stream": { + "noise": 2.2, + "speed": 100, + "spread": 3.5, + "type": "signal" + }, + "stringInput": "" + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Angular Graph", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "decimals": 2, + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, { "datasource": "${DS_TESTDATA_DB}", "description": "", @@ -55,7 +152,7 @@ "h": 6, "w": 24, "x": 0, - "y": 0 + "y": 7 }, "id": 2, "links": [], @@ -110,5 +207,5 @@ "timezone": "", "title": "Simple Streaming Example", "uid": "TXSTREZ", - "version": 2 + "version": 3 }