From 5f14d62c0d9b62798cde0085a1c7f952910f2605 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Mon, 20 Jan 2020 10:50:42 -0800 Subject: [PATCH] TestData: allow negative values for random_walk parameters (#21627) --- pkg/tsdb/testdatasource/scenarios.go | 11 +++++++---- .../datasource/testdata/partials/query.editor.html | 3 --- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/tsdb/testdatasource/scenarios.go b/pkg/tsdb/testdatasource/scenarios.go index 9f8bee65009..109b57319f9 100644 --- a/pkg/tsdb/testdatasource/scenarios.go +++ b/pkg/tsdb/testdatasource/scenarios.go @@ -542,8 +542,11 @@ func getRandomWalk(query *tsdb.Query, tsdbQuery *tsdb.TsdbQuery, index int) *tsd startValue := query.Model.Get("startValue").MustFloat64(rand.Float64() * 100) spread := query.Model.Get("spread").MustFloat64(1) noise := query.Model.Get("noise").MustFloat64(0) - min, hasMin := query.Model.Get("min").Float64() - max, hasMax := query.Model.Get("max").Float64() + + min, err := query.Model.Get("min").Float64() + hasMin := err == nil + max, err := query.Model.Get("max").Float64() + hasMax := err == nil points := make(tsdb.TimeSeriesPoints, 0) walker := startValue @@ -551,12 +554,12 @@ func getRandomWalk(query *tsdb.Query, tsdbQuery *tsdb.TsdbQuery, index int) *tsd for i := int64(0); i < 10000 && timeWalkerMs < to; i++ { nextValue := walker + (rand.Float64() * noise) - if hasMin == nil && nextValue < min { + if hasMin && nextValue < min { nextValue = min walker = min } - if hasMax == nil && nextValue > max { + if hasMax && nextValue > max { nextValue = max walker = max } diff --git a/public/app/plugins/datasource/testdata/partials/query.editor.html b/public/app/plugins/datasource/testdata/partials/query.editor.html index ac387f5deed..abd5b716b7e 100644 --- a/public/app/plugins/datasource/testdata/partials/query.editor.html +++ b/public/app/plugins/datasource/testdata/partials/query.editor.html @@ -65,7 +65,6 @@ class="gf-form-input width-6" placeholder="auto" ng-model="ctrl.target.startValue" - min="1" step="1" ng-change="ctrl.refresh()" /> @@ -95,7 +94,6 @@ class="gf-form-input width-6" placeholder="none" ng-model="ctrl.target.min" - min="0" step="0.1" ng-change="ctrl.refresh()" /> @@ -105,7 +103,6 @@ class="gf-form-input width-6" placeholder="none" ng-model="ctrl.target.max" - min="0" step="0.1" ng-change="ctrl.refresh()" />