mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Add last
downsampling function to Resample expression (#57379)
This commit is contained in:
parent
cd0e0fcc53
commit
245c1ee3d3
@ -54,6 +54,8 @@ func (s Series) Resample(refID string, interval time.Duration, downsampler strin
|
||||
default:
|
||||
return s, fmt.Errorf("upsampling %v not implemented", upsampler)
|
||||
}
|
||||
} else if len(vals) == 1 {
|
||||
value = vals[0]
|
||||
} else { // downsampling
|
||||
fVec := data.NewField("", s.GetLabels(), vals)
|
||||
ff := Float64Field(*fVec)
|
||||
@ -67,6 +69,8 @@ func (s Series) Resample(refID string, interval time.Duration, downsampler strin
|
||||
tmp = Min(&ff)
|
||||
case "max":
|
||||
tmp = Max(&ff)
|
||||
case "last":
|
||||
tmp = Last(&ff)
|
||||
default:
|
||||
return s, fmt.Errorf("downsampling %v not implemented", downsampler)
|
||||
}
|
||||
|
@ -245,6 +245,38 @@ func TestResampleSeries(t *testing.T) {
|
||||
time.Unix(10, 0), nil,
|
||||
}),
|
||||
},
|
||||
{
|
||||
name: "resample series: downsampling (last / pad )",
|
||||
interval: time.Second * 3,
|
||||
downsampler: "last",
|
||||
upsampler: "pad",
|
||||
timeRange: backend.TimeRange{
|
||||
From: time.Unix(0, 0),
|
||||
To: time.Unix(11, 0),
|
||||
},
|
||||
seriesToResample: makeSeries("", nil, tp{
|
||||
time.Unix(0, 0), float64Pointer(0),
|
||||
}, tp{
|
||||
time.Unix(2, 0), float64Pointer(2),
|
||||
}, tp{
|
||||
time.Unix(4, 0), float64Pointer(3),
|
||||
}, tp{
|
||||
time.Unix(6, 0), float64Pointer(4),
|
||||
}, tp{
|
||||
time.Unix(8, 0), float64Pointer(0),
|
||||
}, tp{
|
||||
time.Unix(10, 0), float64Pointer(1),
|
||||
}),
|
||||
series: makeSeries("", nil, tp{
|
||||
time.Unix(0, 0), float64Pointer(0),
|
||||
}, tp{
|
||||
time.Unix(3, 0), float64Pointer(2),
|
||||
}, tp{
|
||||
time.Unix(6, 0), float64Pointer(4),
|
||||
}, tp{
|
||||
time.Unix(9, 0), float64Pointer(0),
|
||||
}),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
@ -75,6 +75,7 @@ export const reducerMode: Array<SelectableValue<ReducerMode>> = [
|
||||
];
|
||||
|
||||
export const downsamplingTypes: Array<SelectableValue<string>> = [
|
||||
{ value: ReducerID.last, label: 'Last', description: 'Fill with the last value' },
|
||||
{ value: ReducerID.min, label: 'Min', description: 'Fill with the minimum value' },
|
||||
{ value: ReducerID.max, label: 'Max', description: 'Fill with the maximum value' },
|
||||
{ value: ReducerID.mean, label: 'Mean', description: 'Fill with the average value' },
|
||||
|
Loading…
Reference in New Issue
Block a user