mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Fix percent_diff calculation when points are nulls
This commit is contained in:
parent
4f3b9c6c37
commit
3c2f6094b2
@ -131,6 +131,8 @@ func (s *SimpleReducer) Reduce(series *tsdb.TimeSeries) null.Float {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if i >= 1 {
|
||||||
// get the oldest point
|
// get the oldest point
|
||||||
points = points[0:i]
|
points = points[0:i]
|
||||||
for i := 0; i < len(points); i++ {
|
for i := 0; i < len(points); i++ {
|
||||||
@ -141,6 +143,7 @@ func (s *SimpleReducer) Reduce(series *tsdb.TimeSeries) null.Float {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
case "count_non_null":
|
case "count_non_null":
|
||||||
for _, v := range series.Points {
|
for _, v := range series.Points {
|
||||||
if v[0].Valid {
|
if v[0].Valid {
|
||||||
|
@ -157,6 +157,18 @@ func TestSimpleReducer(t *testing.T) {
|
|||||||
result := testReducer("percent_diff", 30, 40, 40)
|
result := testReducer("percent_diff", 30, 40, 40)
|
||||||
So(result, ShouldEqual, float64(33.33333333333333))
|
So(result, ShouldEqual, float64(33.33333333333333))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Convey("percent_diff with only nulls", func() {
|
||||||
|
reducer := NewSimpleReducer("percent_diff")
|
||||||
|
series := &tsdb.TimeSeries{
|
||||||
|
Name: "test time serie",
|
||||||
|
}
|
||||||
|
|
||||||
|
series.Points = append(series.Points, tsdb.NewTimePoint(null.FloatFromPtr(nil), 1))
|
||||||
|
series.Points = append(series.Points, tsdb.NewTimePoint(null.FloatFromPtr(nil), 2))
|
||||||
|
|
||||||
|
So(reducer.Reduce(series).Valid, ShouldEqual, false)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user