From 27dcd0edb1ce59425753dbdf6235006aae76ccf6 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Tue, 30 Apr 2019 00:20:38 -0700 Subject: [PATCH] TestData: add log level in dummy message (#16815) --- .../datasource/testdata/StreamHandler.ts | 33 ++++++++++++++++--- .../testdata/partials/query.editor.html | 4 +-- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/public/app/plugins/datasource/testdata/StreamHandler.ts b/public/app/plugins/datasource/testdata/StreamHandler.ts index 02159a72a65..11ede1346bd 100644 --- a/public/app/plugins/datasource/testdata/StreamHandler.ts +++ b/public/app/plugins/datasource/testdata/StreamHandler.ts @@ -8,6 +8,7 @@ import { DataStreamObserver, DataStreamState, LoadingState, + LogLevel, } from '@grafana/ui'; import { TestDataQuery, StreamingQuery } from './types'; @@ -218,21 +219,44 @@ export class LogsWorker extends StreamWorker { }, 10); } + getRandomLogLevel(): LogLevel { + const v = Math.random(); + if (v > 0.9) { + return LogLevel.critical; + } + if (v > 0.8) { + return LogLevel.error; + } + if (v > 0.7) { + return LogLevel.warning; + } + if (v > 0.4) { + return LogLevel.info; + } + if (v > 0.3) { + return LogLevel.debug; + } + if (v > 0.1) { + return LogLevel.trace; + } + return LogLevel.unknown; + } + getNextWord() { this.index = (this.index + Math.floor(Math.random() * 5)) % words.length; return words[this.index]; } - getRandomLine() { + getRandomLine(length = 60) { let line = this.getNextWord(); - while (line.length < 80) { + while (line.length < length) { line += ' ' + this.getNextWord(); } return line; } nextRow = (time: number) => { - return [time, this.getRandomLine()]; + return [time, '[' + this.getRandomLogLevel() + '] ' + this.getRandomLine()]; }; initBuffer(refId: string): SeriesData { @@ -270,9 +294,10 @@ export class LogsWorker extends StreamWorker { if (query.speed < 5) { query.speed = 5; } + const variance = query.speed * 0.2 * (Math.random() - 0.5); // +-10% this.appendRows([this.nextRow(Date.now())]); - this.timeoutId = window.setTimeout(this.looper, query.speed); + this.timeoutId = window.setTimeout(this.looper, query.speed + variance); }; } diff --git a/public/app/plugins/datasource/testdata/partials/query.editor.html b/public/app/plugins/datasource/testdata/partials/query.editor.html index 78fd3b44f89..bd54f503a5e 100644 --- a/public/app/plugins/datasource/testdata/partials/query.editor.html +++ b/public/app/plugins/datasource/testdata/partials/query.editor.html @@ -58,7 +58,7 @@ step="10" ng-change="ctrl.streamChanged()" /> -
+
-
+