Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
bb7f03c9
Commit
bb7f03c9
authored
Nov 03, 2016
by
Carl Bergquist
Committed by
GitHub
Nov 03, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6446 from utkarshcmu/graphite_alerting_fix
Fixed intervalFormat for Graphite Alerting
parents
d1d7c240
fc912311
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
2 deletions
+77
-2
pkg/tsdb/graphite/graphite.go
+17
-2
pkg/tsdb/graphite/graphite_test.go
+60
-0
No files found.
pkg/tsdb/graphite/graphite.go
View file @
bb7f03c9
...
...
@@ -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
{
f
ullTarget
}
formData
[
"target"
]
=
[]
string
{
f
ixIntervalFormat
(
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
}
pkg/tsdb/graphite/graphite_test.go
View file @
bb7f03c9
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"
)
})
})
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment