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
777ca4cd
Commit
777ca4cd
authored
Jun 15, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
style(alerting): rename level.level to level.value
parent
a8931521
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
92 additions
and
20 deletions
+92
-20
pkg/services/alerting/alert_rule.go
+2
-2
pkg/services/alerting/alert_rule_test.go
+53
-0
pkg/services/alerting/evaluator.go
+1
-1
pkg/services/alerting/executor.go
+2
-2
pkg/services/alerting/executor_test.go
+10
-10
pkg/services/alerting/extractor.go
+6
-0
pkg/services/alerting/extractor_test.go
+17
-4
pkg/services/alerting/models.go
+1
-1
No files found.
pkg/services/alerting/alert_rule.go
View file @
777ca4cd
...
...
@@ -63,13 +63,13 @@ func NewAlertRuleFromDBModel(ruleDef *m.Alert) (*AlertRule, error) {
critical
:=
ruleDef
.
Settings
.
Get
(
"critical"
)
model
.
Critical
=
Level
{
Operator
:
critical
.
Get
(
"op"
)
.
MustString
(),
Level
:
critical
.
Get
(
"level
"
)
.
MustFloat64
(),
Value
:
critical
.
Get
(
"value
"
)
.
MustFloat64
(),
}
warning
:=
ruleDef
.
Settings
.
Get
(
"warn"
)
model
.
Warning
=
Level
{
Operator
:
warning
.
Get
(
"op"
)
.
MustString
(),
Level
:
warning
.
Get
(
"level
"
)
.
MustFloat64
(),
Value
:
warning
.
Get
(
"value
"
)
.
MustFloat64
(),
}
model
.
Frequency
=
getTimeDurationStringToSeconds
(
ruleDef
.
Settings
.
Get
(
"frequency"
)
.
MustString
())
...
...
pkg/services/alerting/alert_rule_test.go
View file @
777ca4cd
...
...
@@ -3,6 +3,8 @@ package alerting
import
(
"testing"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models"
.
"github.com/smartystreets/goconvey/convey"
)
...
...
@@ -28,5 +30,56 @@ func TestAlertRuleModel(t *testing.T) {
seconds
:=
getTimeDurationStringToSeconds
(
"1o"
)
So
(
seconds
,
ShouldEqual
,
1
)
})
Convey
(
""
,
func
()
{
json
:=
`
{
"name": "name2",
"description": "desc2",
"handler": 0,
"enabled": true,
"critical": {
"value": 20,
"op": ">"
},
"warn": {
"value": 10,
"op": ">"
},
"frequency": "60s",
"query": {
"from": "5m",
"refId": "A",
"to": "now",
"query": "aliasByNode(statsd.fakesite.counters.session_start.mobile.count, 4)",
"datasourceId": 1
},
"transform": {
"method": "avg",
"name": "aggregation"
}
}
`
alertJSON
,
jsonErr
:=
simplejson
.
NewJson
([]
byte
(
json
))
So
(
jsonErr
,
ShouldBeNil
)
alert
:=
&
models
.
Alert
{
Id
:
1
,
OrgId
:
1
,
DashboardId
:
1
,
PanelId
:
1
,
Settings
:
alertJSON
,
}
alertRule
,
err
:=
NewAlertRuleFromDBModel
(
alert
)
So
(
err
,
ShouldBeNil
)
So
(
alertRule
.
Critical
.
Operator
,
ShouldEqual
,
">"
)
So
(
alertRule
.
Critical
.
Value
,
ShouldEqual
,
20
)
So
(
alertRule
.
Warning
.
Operator
,
ShouldEqual
,
">"
)
So
(
alertRule
.
Warning
.
Value
,
ShouldEqual
,
10
)
})
})
}
pkg/services/alerting/evaluator.go
View file @
777ca4cd
...
...
@@ -3,7 +3,7 @@ package alerting
type
compareFn
func
(
float64
,
float64
)
bool
func
evalCondition
(
level
Level
,
result
float64
)
bool
{
return
operators
[
level
.
Operator
](
result
,
level
.
Level
)
return
operators
[
level
.
Operator
](
result
,
level
.
Value
)
}
var
operators
=
map
[
string
]
compareFn
{
...
...
pkg/services/alerting/executor.go
View file @
777ca4cd
...
...
@@ -102,7 +102,7 @@ func (e *ExecutorImpl) evaluateRule(rule *AlertRule, series tsdb.TimeSeriesSlice
transformedValue
,
_
:=
rule
.
Transformer
.
Transform
(
serie
)
critResult
:=
evalCondition
(
rule
.
Critical
,
transformedValue
)
e
.
log
.
Debug
(
"Alert execution Crit"
,
"name"
,
serie
.
Name
,
"transformedValue"
,
transformedValue
,
"operator"
,
rule
.
Critical
.
Operator
,
"level"
,
rule
.
Critical
.
Level
,
"result"
,
critResult
)
e
.
log
.
Debug
(
"Alert execution Crit"
,
"name"
,
serie
.
Name
,
"transformedValue"
,
transformedValue
,
"operator"
,
rule
.
Critical
.
Operator
,
"level"
,
rule
.
Critical
.
Value
,
"result"
,
critResult
)
if
critResult
{
triggeredAlert
=
append
(
triggeredAlert
,
&
TriggeredAlert
{
State
:
alertstates
.
Critical
,
...
...
@@ -112,7 +112,7 @@ func (e *ExecutorImpl) evaluateRule(rule *AlertRule, series tsdb.TimeSeriesSlice
}
warnResult
:=
evalCondition
(
rule
.
Warning
,
transformedValue
)
e
.
log
.
Debug
(
"Alert execution Warn"
,
"name"
,
serie
.
Name
,
"transformedValue"
,
transformedValue
,
"operator"
,
rule
.
Warning
.
Operator
,
"level"
,
rule
.
Warning
.
Level
,
"result"
,
warnResult
)
e
.
log
.
Debug
(
"Alert execution Warn"
,
"name"
,
serie
.
Name
,
"transformedValue"
,
transformedValue
,
"operator"
,
rule
.
Warning
.
Operator
,
"level"
,
rule
.
Warning
.
Value
,
"result"
,
warnResult
)
if
warnResult
{
triggeredAlert
=
append
(
triggeredAlert
,
&
TriggeredAlert
{
State
:
alertstates
.
Warn
,
...
...
pkg/services/alerting/executor_test.go
View file @
777ca4cd
...
...
@@ -16,7 +16,7 @@ func TestAlertingExecutor(t *testing.T) {
Convey
(
"single time serie"
,
func
()
{
Convey
(
"Show return ok since avg is above 2"
,
func
()
{
rule
:=
&
AlertRule
{
Critical
:
Level
{
Level
:
10
,
Operator
:
">"
},
Critical
:
Level
{
Value
:
10
,
Operator
:
">"
},
Transformer
:
transformers
.
NewAggregationTransformer
(
"avg"
),
}
...
...
@@ -30,7 +30,7 @@ func TestAlertingExecutor(t *testing.T) {
Convey
(
"Show return critical since below 2"
,
func
()
{
rule
:=
&
AlertRule
{
Critical
:
Level
{
Level
:
10
,
Operator
:
"<"
},
Critical
:
Level
{
Value
:
10
,
Operator
:
"<"
},
Transformer
:
transformers
.
NewAggregationTransformer
(
"avg"
),
}
...
...
@@ -44,7 +44,7 @@ func TestAlertingExecutor(t *testing.T) {
Convey
(
"Show return critical since sum is above 10"
,
func
()
{
rule
:=
&
AlertRule
{
Critical
:
Level
{
Level
:
10
,
Operator
:
">"
},
Critical
:
Level
{
Value
:
10
,
Operator
:
">"
},
Transformer
:
transformers
.
NewAggregationTransformer
(
"sum"
),
}
...
...
@@ -58,7 +58,7 @@ func TestAlertingExecutor(t *testing.T) {
Convey
(
"Show return ok since avg is below 10"
,
func
()
{
rule
:=
&
AlertRule
{
Critical
:
Level
{
Level
:
10
,
Operator
:
">"
},
Critical
:
Level
{
Value
:
10
,
Operator
:
">"
},
Transformer
:
transformers
.
NewAggregationTransformer
(
"avg"
),
}
...
...
@@ -72,7 +72,7 @@ func TestAlertingExecutor(t *testing.T) {
Convey
(
"Show return ok since min is below 10"
,
func
()
{
rule
:=
&
AlertRule
{
Critical
:
Level
{
Level
:
10
,
Operator
:
">"
},
Critical
:
Level
{
Value
:
10
,
Operator
:
">"
},
Transformer
:
transformers
.
NewAggregationTransformer
(
"avg"
),
}
...
...
@@ -86,7 +86,7 @@ func TestAlertingExecutor(t *testing.T) {
Convey
(
"Show return ok since max is above 10"
,
func
()
{
rule
:=
&
AlertRule
{
Critical
:
Level
{
Level
:
10
,
Operator
:
">"
},
Critical
:
Level
{
Value
:
10
,
Operator
:
">"
},
Transformer
:
transformers
.
NewAggregationTransformer
(
"max"
),
}
...
...
@@ -103,7 +103,7 @@ func TestAlertingExecutor(t *testing.T) {
Convey
(
"muliple time series"
,
func
()
{
Convey
(
"both are ok"
,
func
()
{
rule
:=
&
AlertRule
{
Critical
:
Level
{
Level
:
10
,
Operator
:
">"
},
Critical
:
Level
{
Value
:
10
,
Operator
:
">"
},
Transformer
:
transformers
.
NewAggregationTransformer
(
"avg"
),
}
...
...
@@ -118,7 +118,7 @@ func TestAlertingExecutor(t *testing.T) {
Convey
(
"first serie is good, second is critical"
,
func
()
{
rule
:=
&
AlertRule
{
Critical
:
Level
{
Level
:
10
,
Operator
:
">"
},
Critical
:
Level
{
Value
:
10
,
Operator
:
">"
},
Transformer
:
transformers
.
NewAggregationTransformer
(
"avg"
),
}
...
...
@@ -133,8 +133,8 @@ func TestAlertingExecutor(t *testing.T) {
Convey
(
"first serie is warn, second is critical"
,
func
()
{
rule
:=
&
AlertRule
{
Critical
:
Level
{
Level
:
10
,
Operator
:
">"
},
Warning
:
Level
{
Level
:
5
,
Operator
:
">"
},
Critical
:
Level
{
Value
:
10
,
Operator
:
">"
},
Warning
:
Level
{
Value
:
5
,
Operator
:
">"
},
Transformer
:
transformers
.
NewAggregationTransformer
(
"avg"
),
}
...
...
pkg/services/alerting/extractor.go
View file @
777ca4cd
...
...
@@ -63,6 +63,12 @@ func (e *DashAlertExtractor) GetAlerts() ([]*m.Alert, error) {
continue
}
enabled
,
hasEnabled
:=
jsonAlert
.
CheckGet
(
"enabled"
)
if
!
hasEnabled
||
!
enabled
.
MustBool
()
{
continue
}
alert
:=
&
m
.
Alert
{
DashboardId
:
e
.
Dash
.
Id
,
OrgId
:
e
.
OrgId
,
...
...
pkg/services/alerting/extractor_test.go
View file @
777ca4cd
...
...
@@ -42,7 +42,7 @@ func TestAlertRuleExtraction(t *testing.T) {
"handler": 1,
"enabled": true,
"critical": {
"
level
": 20,
"
value
": 20,
"op": ">"
},
"frequency": "60s",
...
...
@@ -56,7 +56,7 @@ func TestAlertRuleExtraction(t *testing.T) {
"type": "aggregation"
},
"warn": {
"
level
": 10,
"
value
": 10,
"op": ">"
}
}
...
...
@@ -77,7 +77,7 @@ func TestAlertRuleExtraction(t *testing.T) {
"handler": 0,
"enabled": true,
"critical": {
"
level
": 20,
"
value
": 20,
"op": ">"
},
"frequency": "60s",
...
...
@@ -91,7 +91,7 @@ func TestAlertRuleExtraction(t *testing.T) {
"name": "aggregation"
},
"warn": {
"
level
": 10,
"
value
": 10,
"op": ">"
}
}
...
...
@@ -107,6 +107,19 @@ func TestAlertRuleExtraction(t *testing.T) {
{
"datasource": "InfluxDB",
"id": 2,
"alert": {
"name": "name2",
"description": "desc2",
"enabled": false,
"critical": {
"level": 20,
"op": ">"
},
"warn": {
"level": 10,
"op": ">"
}
},
"targets": [
{
"dsType": "influxdb",
...
...
pkg/services/alerting/models.go
View file @
777ca4cd
...
...
@@ -38,7 +38,7 @@ type TriggeredAlert struct {
type
Level
struct
{
Operator
string
Level
float64
Value
float64
}
type
AlertQuery
struct
{
...
...
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