mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 00:25:46 -06:00
Merge pull request #6446 from utkarshcmu/graphite_alerting_fix
Fixed intervalFormat for Graphite Alerting
This commit is contained in:
commit
bb7f03c91e
@ -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
|
||||
}
|
||||
|
@ -1 +1,61 @@
|
||||
package graphite
|
||||
|
||||
import (
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGraphiteFunctions(t *testing.T) {
|
||||
Convey("Testing Graphite Functions", t, func() {
|
||||
|
||||
Convey("formatting time range for now", func() {
|
||||
|
||||
timeRange := formatTimeRange("now")
|
||||
So(timeRange, ShouldEqual, "now")
|
||||
|
||||
})
|
||||
|
||||
Convey("formatting time range for now-1m", func() {
|
||||
|
||||
timeRange := formatTimeRange("now-1m")
|
||||
So(timeRange, ShouldEqual, "now-1min")
|
||||
|
||||
})
|
||||
|
||||
Convey("formatting time range for now-1M", func() {
|
||||
|
||||
timeRange := formatTimeRange("now-1M")
|
||||
So(timeRange, ShouldEqual, "now-1mon")
|
||||
|
||||
})
|
||||
|
||||
Convey("fix interval format in query for 1m", func() {
|
||||
|
||||
timeRange := fixIntervalFormat("aliasByNode(hitcount(averageSeries(app.grafana.*.dashboards.views.count), '1m'), 4)")
|
||||
So(timeRange, ShouldEqual, "aliasByNode(hitcount(averageSeries(app.grafana.*.dashboards.views.count), '1min'), 4)")
|
||||
|
||||
})
|
||||
|
||||
Convey("fix interval format in query for 1M", func() {
|
||||
|
||||
timeRange := fixIntervalFormat("aliasByNode(hitcount(averageSeries(app.grafana.*.dashboards.views.count), '1M'), 4)")
|
||||
So(timeRange, ShouldEqual, "aliasByNode(hitcount(averageSeries(app.grafana.*.dashboards.views.count), '1mon'), 4)")
|
||||
|
||||
})
|
||||
|
||||
Convey("should not override query for 1M", func() {
|
||||
|
||||
timeRange := fixIntervalFormat("app.grafana.*.dashboards.views.1M.count")
|
||||
So(timeRange, ShouldEqual, "app.grafana.*.dashboards.views.1M.count")
|
||||
|
||||
})
|
||||
|
||||
Convey("should not override query for 1m", func() {
|
||||
|
||||
timeRange := fixIntervalFormat("app.grafana.*.dashboards.views.1m.count")
|
||||
So(timeRange, ShouldEqual, "app.grafana.*.dashboards.views.1m.count")
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user