diff --git a/packages/grafana-e2e-selectors/src/selectors/components.ts b/packages/grafana-e2e-selectors/src/selectors/components.ts index 26f2fc7bd91..75b38bc2107 100644 --- a/packages/grafana-e2e-selectors/src/selectors/components.ts +++ b/packages/grafana-e2e-selectors/src/selectors/components.ts @@ -33,6 +33,7 @@ export const Components = { seriesCount: 'TestData series count', spread: 'TestData spread', startValue: 'TestData start value', + drop: 'TestData drop values', }, }, DataSourceHttpSettings: { diff --git a/pkg/tsdb/testdatasource/scenarios.go b/pkg/tsdb/testdatasource/scenarios.go index b93cfe0ae9b..1c4e5b4d26f 100644 --- a/pkg/tsdb/testdatasource/scenarios.go +++ b/pkg/tsdb/testdatasource/scenarios.go @@ -630,6 +630,7 @@ func RandomWalk(query backend.DataQuery, model *simplejson.Json, index int) *dat startValue := model.Get("startValue").MustFloat64(rand.Float64() * 100) spread := model.Get("spread").MustFloat64(1) noise := model.Get("noise").MustFloat64(0) + drop := model.Get("drop").MustFloat64(0) / 100.0 // value is 0-100 min, err := model.Get("min").Float64() hasMin := err == nil @@ -654,16 +655,23 @@ func RandomWalk(query backend.DataQuery, model *simplejson.Json, index int) *dat walker = max } - t := time.Unix(timeWalkerMs/int64(1e+3), (timeWalkerMs%int64(1e+3))*int64(1e+6)) - timeVec = append(timeVec, &t) - floatVec = append(floatVec, &nextValue) + if drop > 0 && rand.Float64() < drop { + // skip value + } else { + t := time.Unix(timeWalkerMs/int64(1e+3), (timeWalkerMs%int64(1e+3))*int64(1e+6)) + timeVec = append(timeVec, &t) + floatVec = append(floatVec, &nextValue) + } walker += (rand.Float64() - 0.5) * spread timeWalkerMs += query.Interval.Milliseconds() } return data.NewFrame("", - data.NewField("time", nil, timeVec), + data.NewField("time", nil, timeVec). + SetConfig(&data.FieldConfig{ + Interval: float64(query.Interval.Milliseconds()), + }), data.NewField(frameNameForQuery(query, model, index), parseLabels(model), floatVec), ) } diff --git a/public/app/plugins/datasource/testdata/components/RandomWalkEditor.tsx b/public/app/plugins/datasource/testdata/components/RandomWalkEditor.tsx index 42353b02708..aa842e4bda6 100644 --- a/public/app/plugins/datasource/testdata/components/RandomWalkEditor.tsx +++ b/public/app/plugins/datasource/testdata/components/RandomWalkEditor.tsx @@ -7,22 +7,31 @@ import { TestDataQuery } from '../types'; const randomWalkFields = [ { label: 'Series count', id: 'seriesCount', placeholder: '1', min: 1, step: 1 }, { label: 'Start value', id: 'startValue', placeholder: 'auto', step: 1 }, - { label: 'Spread', id: 'spread', placeholder: '1', min: 0.5, step: 0.1 }, - { label: 'Noise', id: 'noise', placeholder: '0', min: 0, step: 0.1 }, { label: 'Min', id: 'min', placeholder: 'none', step: 0.1 }, { label: 'Max', id: 'max', placeholder: 'none', step: 0.1 }, + { label: 'Spread', id: 'spread', placeholder: '1', min: 0.5, step: 0.1 }, + { label: 'Noise', id: 'noise', placeholder: '0', min: 0, step: 0.1 }, + { + label: 'Drop (%)', + id: 'drop', + placeholder: '0', + min: 0, + max: 100, + step: 1, + tooltip: 'Exclude some percent (chance) points', + }, ]; const testSelectors = selectors.components.DataSource.TestData.QueryTab; -type Selector = 'max' | 'min' | 'noise' | 'seriesCount' | 'spread' | 'startValue'; +type Selector = 'max' | 'min' | 'noise' | 'seriesCount' | 'spread' | 'startValue' | 'drop'; export const RandomWalkEditor = ({ onChange, query }: EditorProps) => { return ( - {randomWalkFields.map(({ label, id, min, step, placeholder }) => { + {randomWalkFields.map(({ label, id, min, step, placeholder, tooltip }) => { const selector = testSelectors?.[id as Selector]; return ( - +