mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
TestData: support dropping points from random walk data and send interval (#44683)
This commit is contained in:
@@ -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}
|
||||
|
Reference in New Issue
Block a user