From eba763fc7413c93e2e63a4e6c63633341b72281c Mon Sep 17 00:00:00 2001 From: liugq Date: Mon, 13 Jun 2022 09:40:46 +0800 Subject: [PATCH] update alert preview data --- plugin/api/alerting/rule.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/plugin/api/alerting/rule.go b/plugin/api/alerting/rule.go index 1d78d66d..c08ab234 100644 --- a/plugin/api/alerting/rule.go +++ b/plugin/api/alerting/rule.go @@ -676,8 +676,21 @@ func (alertAPI *AlertAPI) getPreviewMetricData(w http.ResponseWriter, req *http. minStr = alertAPI.Get(req, "min", "") maxStr = alertAPI.Get(req, "max", "") ) + var bkSize float64 = 60 + if rule.Metrics.PeriodInterval != "" { + duration, err := time.ParseDuration(rule.Metrics.PeriodInterval) + if err != nil { + log.Error(err) + alertAPI.WriteJSON(w, util.MapStr{ + "error": err.Error(), + }, http.StatusInternalServerError) + return + } + bkSize = duration.Seconds() + } - bucketSize, min, max, err := api.GetMetricRangeAndBucketSize(minStr, maxStr, 60, 15) + + bucketSize, min, max, err := api.GetMetricRangeAndBucketSize(minStr, maxStr, int(bkSize), 15) filterParam := &alerting.FilterParam{ Start: min, End: max,