Jelajahi Sumber

Streaming: support streaming in MetricsPanelCtrl (#17034)

* support streaming in angular panels

* keep the same dashboard number
Ryan McKinley 6 tahun lalu
induk
melakukan
7333f7ca17

+ 26 - 15
public/app/features/panel/metrics_panel_ctrl.ts

@@ -129,25 +129,36 @@ class MetricsPanelCtrl extends PanelCtrl {
       if (data.state === LoadingState.Error) {
       if (data.state === LoadingState.Error) {
         this.loading = false;
         this.loading = false;
         this.processDataError(data.error);
         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,
+      });
     },
     },
   };
   };
 
 

+ 100 - 3
public/app/plugins/datasource/testdata/dashboards/streaming.json

@@ -14,7 +14,13 @@
       "type": "grafana",
       "type": "grafana",
       "id": "grafana",
       "id": "grafana",
       "name": "Grafana",
       "name": "Grafana",
-      "version": "6.2.0-pre"
+      "version": "6.3.0-pre"
+    },
+    {
+      "type": "panel",
+      "id": "graph",
+      "name": "Graph",
+      "version": ""
     },
     },
     {
     {
       "type": "panel",
       "type": "panel",
@@ -48,6 +54,97 @@
   "id": null,
   "id": null,
   "links": [],
   "links": [],
   "panels": [
   "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}",
       "datasource": "${DS_TESTDATA_DB}",
       "description": "",
       "description": "",
@@ -55,7 +152,7 @@
         "h": 6,
         "h": 6,
         "w": 24,
         "w": 24,
         "x": 0,
         "x": 0,
-        "y": 0
+        "y": 7
       },
       },
       "id": 2,
       "id": 2,
       "links": [],
       "links": [],
@@ -110,5 +207,5 @@
   "timezone": "",
   "timezone": "",
   "title": "Simple Streaming Example",
   "title": "Simple Streaming Example",
   "uid": "TXSTREZ",
   "uid": "TXSTREZ",
-  "version": 2
+  "version": 3
 }
 }