From 6bef36bcacb635195514a9559ba168fca33cc333 Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Sat, 1 Jun 2024 20:41:05 +0800 Subject: [PATCH] feat(monitor): remove precision of float when using max or min function (#20431) --- pkg/monitor/alerting/conditions/reducer.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/pkg/monitor/alerting/conditions/reducer.go b/pkg/monitor/alerting/conditions/reducer.go index a4f4b35694..0c46c5b4c8 100644 --- a/pkg/monitor/alerting/conditions/reducer.go +++ b/pkg/monitor/alerting/conditions/reducer.go @@ -47,6 +47,14 @@ func (s *queryReducer) GetType() string { return s.Type } +func getRoundFloat(point monitor.TimePoint) float64 { + pv := point.Value() + if pv < 1 { + return pv + } + return math.Trunc(pv) +} + func (s *queryReducer) Reduce(series *monitor.TimeSeries) (*float64, []string) { if len(series.Points) == 0 { return nil, nil @@ -80,8 +88,9 @@ func (s *queryReducer) Reduce(series *monitor.TimeSeries) (*float64, []string) { for _, point := range series.Points { if point.IsValid() { allNull = false - if value > point.Value() { - value = point.Value() + pv := getRoundFloat(point) + if value > pv { + value = pv } } } @@ -90,8 +99,9 @@ func (s *queryReducer) Reduce(series *monitor.TimeSeries) (*float64, []string) { for _, point := range series.Points { if point.IsValid() { allNull = false - if value < point.Value() { - value = point.Value() + pv := getRoundFloat(point) + if value < pv { + value = pv } } }