TestData: allow negative values for random_walk parameters (#21627)

This commit is contained in:
Ryan McKinley
2020-01-20 10:50:42 -08:00
committed by GitHub
parent 2021a2df74
commit 5f14d62c0d
2 changed files with 7 additions and 7 deletions

View File

@@ -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
}