TestData: support dropping points from random walk data and send interval (#44683)

pull/44727/head
Ryan McKinley 3 years ago committed by GitHub
parent 8218d81f0e
commit 3749695594
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      packages/grafana-e2e-selectors/src/selectors/components.ts
  2. 16
      pkg/tsdb/testdatasource/scenarios.go
  3. 19
      public/app/plugins/datasource/testdata/components/RandomWalkEditor.tsx

@ -33,6 +33,7 @@ export const Components = {
seriesCount: 'TestData series count',
spread: 'TestData spread',
startValue: 'TestData start value',
drop: 'TestData drop values',
},
},
DataSourceHttpSettings: {

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

@ -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 (
<InlineFieldRow>
{randomWalkFields.map(({ label, id, min, step, placeholder }) => {
{randomWalkFields.map(({ label, id, min, step, placeholder, tooltip }) => {
const selector = testSelectors?.[id as Selector];
return (
<InlineField label={label} labelWidth={14} key={id} aria-label={selector}>
<InlineField label={label} labelWidth={14} key={id} aria-label={selector} tooltip={tooltip}>
<Input
width={32}
name={id}

Loading…
Cancel
Save