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',
|
seriesCount: 'TestData series count',
|
||||||
spread: 'TestData spread',
|
spread: 'TestData spread',
|
||||||
startValue: 'TestData start value',
|
startValue: 'TestData start value',
|
||||||
|
drop: 'TestData drop values',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
DataSourceHttpSettings: {
|
DataSourceHttpSettings: {
|
||||||
|
@@ -630,6 +630,7 @@ func RandomWalk(query backend.DataQuery, model *simplejson.Json, index int) *dat
|
|||||||
startValue := model.Get("startValue").MustFloat64(rand.Float64() * 100)
|
startValue := model.Get("startValue").MustFloat64(rand.Float64() * 100)
|
||||||
spread := model.Get("spread").MustFloat64(1)
|
spread := model.Get("spread").MustFloat64(1)
|
||||||
noise := model.Get("noise").MustFloat64(0)
|
noise := model.Get("noise").MustFloat64(0)
|
||||||
|
drop := model.Get("drop").MustFloat64(0) / 100.0 // value is 0-100
|
||||||
|
|
||||||
min, err := model.Get("min").Float64()
|
min, err := model.Get("min").Float64()
|
||||||
hasMin := err == nil
|
hasMin := err == nil
|
||||||
@@ -654,16 +655,23 @@ func RandomWalk(query backend.DataQuery, model *simplejson.Json, index int) *dat
|
|||||||
walker = max
|
walker = max
|
||||||
}
|
}
|
||||||
|
|
||||||
t := time.Unix(timeWalkerMs/int64(1e+3), (timeWalkerMs%int64(1e+3))*int64(1e+6))
|
if drop > 0 && rand.Float64() < drop {
|
||||||
timeVec = append(timeVec, &t)
|
// skip value
|
||||||
floatVec = append(floatVec, &nextValue)
|
} 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
|
walker += (rand.Float64() - 0.5) * spread
|
||||||
timeWalkerMs += query.Interval.Milliseconds()
|
timeWalkerMs += query.Interval.Milliseconds()
|
||||||
}
|
}
|
||||||
|
|
||||||
return data.NewFrame("",
|
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),
|
data.NewField(frameNameForQuery(query, model, index), parseLabels(model), floatVec),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@@ -7,22 +7,31 @@ import { TestDataQuery } from '../types';
|
|||||||
const randomWalkFields = [
|
const randomWalkFields = [
|
||||||
{ label: 'Series count', id: 'seriesCount', placeholder: '1', min: 1, step: 1 },
|
{ label: 'Series count', id: 'seriesCount', placeholder: '1', min: 1, step: 1 },
|
||||||
{ label: 'Start value', id: 'startValue', placeholder: 'auto', 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: 'Min', id: 'min', placeholder: 'none', step: 0.1 },
|
||||||
{ label: 'Max', id: 'max', 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;
|
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) => {
|
export const RandomWalkEditor = ({ onChange, query }: EditorProps) => {
|
||||||
return (
|
return (
|
||||||
<InlineFieldRow>
|
<InlineFieldRow>
|
||||||
{randomWalkFields.map(({ label, id, min, step, placeholder }) => {
|
{randomWalkFields.map(({ label, id, min, step, placeholder, tooltip }) => {
|
||||||
const selector = testSelectors?.[id as Selector];
|
const selector = testSelectors?.[id as Selector];
|
||||||
return (
|
return (
|
||||||
<InlineField label={label} labelWidth={14} key={id} aria-label={selector}>
|
<InlineField label={label} labelWidth={14} key={id} aria-label={selector} tooltip={tooltip}>
|
||||||
<Input
|
<Input
|
||||||
width={32}
|
width={32}
|
||||||
name={id}
|
name={id}
|
||||||
|
Reference in New Issue
Block a user