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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user