Merge pull request #6446 from utkarshcmu/graphite_alerting_fix
Fixed intervalFormat for Graphite Alerting
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/net/context/ctxhttp"
|
||||
@@ -49,9 +50,9 @@ func (e *GraphiteExecutor) Execute(ctx context.Context, queries tsdb.QuerySlice,
|
||||
|
||||
for _, query := range queries {
|
||||
if fullTarget, err := query.Model.Get("targetFull").String(); err == nil {
|
||||
formData["target"] = []string{fullTarget}
|
||||
formData["target"] = []string{fixIntervalFormat(fullTarget)}
|
||||
} else {
|
||||
formData["target"] = []string{query.Model.Get("target").MustString()}
|
||||
formData["target"] = []string{fixIntervalFormat(query.Model.Get("target").MustString())}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,3 +142,17 @@ func formatTimeRange(input string) string {
|
||||
}
|
||||
return strings.Replace(strings.Replace(input, "m", "min", -1), "M", "mon", -1)
|
||||
}
|
||||
|
||||
func fixIntervalFormat(target string) string {
|
||||
rMinute := regexp.MustCompile(`'(\d+)m'`)
|
||||
rMin := regexp.MustCompile("m")
|
||||
target = rMinute.ReplaceAllStringFunc(target, func(m string) string {
|
||||
return rMin.ReplaceAllString(m, "min")
|
||||
})
|
||||
rMonth := regexp.MustCompile(`'(\d+)M'`)
|
||||
rMon := regexp.MustCompile("M")
|
||||
target = rMonth.ReplaceAllStringFunc(target, func(M string) string {
|
||||
return rMon.ReplaceAllString(M, "mon")
|
||||
})
|
||||
return target
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user