Sfoglia il codice sorgente

TestData: add option to increase the number of test streams (#17789)

* variable number of points

* add variable number of bands
Ryan McKinley 6 anni fa
parent
commit
021f5351fa

+ 22 - 13
public/app/plugins/datasource/testdata/StreamHandler.ts

@@ -18,6 +18,7 @@ export const defaultQuery: StreamingQuery = {
   speed: 250, // ms
   spread: 3.5,
   noise: 2.2,
+  bands: 1,
 };
 
 type StreamWorkers = {
@@ -42,7 +43,7 @@ export class StreamHandler {
       // set stream option defaults
       query.stream = defaults(query.stream, defaultQuery);
       // create stream key
-      const key = req.dashboardId + '/' + req.panelId + '/' + query.refId;
+      const key = req.dashboardId + '/' + req.panelId + '/' + query.refId + '@' + query.stream.bands;
 
       if (this.workers[key]) {
         const existing = this.workers[key];
@@ -146,39 +147,47 @@ export class StreamWorker {
 export class SignalWorker extends StreamWorker {
   value: number;
 
+  bands = 1;
+
   constructor(key: string, query: TestDataQuery, request: DataQueryRequest, observer: DataStreamObserver) {
     super(key, query, request, observer);
     setTimeout(() => {
       this.stream.series = [this.initBuffer(query.refId)];
       this.looper();
     }, 10);
+
+    this.bands = query.stream.bands ? query.stream.bands : 0;
   }
 
   nextRow = (time: number) => {
     const { spread, noise } = this.query;
     this.value += (Math.random() - 0.5) * spread;
-    return [
-      time,
-      this.value, // Value
-      this.value - Math.random() * noise, // MIN
-      this.value + Math.random() * noise, // MAX
-    ];
+    const row = [time, this.value];
+    for (let i = 0; i < this.bands; i++) {
+      const v = row[row.length - 1];
+      row.push(v - Math.random() * noise); // MIN
+      row.push(v + Math.random() * noise); // MAX
+    }
+    return row;
   };
 
   initBuffer(refId: string): SeriesData {
     const { speed, buffer } = this.query;
     const data = {
-      fields: [
-        { name: 'Time', type: FieldType.time },
-        { name: 'Value', type: FieldType.number },
-        { name: 'Min', type: FieldType.number },
-        { name: 'Max', type: FieldType.number },
-      ],
+      fields: [{ name: 'Time', type: FieldType.time }, { name: 'Value', type: FieldType.number }],
       rows: [],
       refId,
       name: 'Signal ' + refId,
     } as SeriesData;
 
+    for (let i = 0; i < this.bands; i++) {
+      const suffix = this.bands > 1 ? ` ${i + 1}` : '';
+      data.fields.push({ name: 'Min' + suffix, type: FieldType.number });
+      data.fields.push({ name: 'Max' + suffix, type: FieldType.number });
+    }
+
+    console.log('START', data);
+
     const request = this.stream.request;
 
     this.value = Math.random() * 100;

+ 11 - 1
public/app/plugins/datasource/testdata/partials/query.editor.html

@@ -43,7 +43,7 @@
 				<select
 				  ng-model="ctrl.target.stream.type"
 				  class="gf-form-input"
-					ng-options="type for type in ['signal','logs', 'fetch']"
+				  ng-options="type for type in ['signal','logs', 'fetch']"
 				  ng-change="ctrl.streamChanged()" />
 				</select>
 			</div>
@@ -78,6 +78,16 @@
 				step="0.1"
 				ng-change="ctrl.streamChanged()" />
 		</div>
+		<div class="gf-form" ng-if="ctrl.target.stream.type === 'signal'">
+			<label class="gf-form-label query-keyword">Bands</label>
+			<input type="number"
+				class="gf-form-input width-5"
+				placeholder="bands"
+				ng-model="ctrl.target.stream.bands"
+				min="0"
+				step="1"
+				ng-change="ctrl.streamChanged()" />
+		</div>
 		<div class="gf-form gf-form--grow" ng-if="ctrl.target.stream.type === 'fetch'">
 			<label class="gf-form-label query-keyword">URL</label>
 			<input type="string"

+ 1 - 0
public/app/plugins/datasource/testdata/types.ts

@@ -18,6 +18,7 @@ export interface StreamingQuery {
   speed: number;
   spread: number;
   noise: number; // wiggle around the signal for min/max
+  bands?: number; // number of bands around the middle van
   buffer?: number;
   url?: string; // the Fetch URL
 }