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
f0fc336e
Commit
f0fc336e
authored
Jul 21, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(alerting): worked on alert condition eval tests
parent
3ad38eef
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
31 deletions
+58
-31
pkg/services/alerting/conditions_test.go
+48
-20
pkg/services/alerting/handler.go
+0
-1
pkg/services/alerting/handler_test.go
+8
-8
public/sass/components/_jsontree.scss
+2
-2
No files found.
pkg/services/alerting/conditions_test.go
View file @
f0fc336e
...
@@ -14,13 +14,40 @@ func TestQueryCondition(t *testing.T) {
...
@@ -14,13 +14,40 @@ func TestQueryCondition(t *testing.T) {
Convey
(
"when evaluating query condition"
,
t
,
func
()
{
Convey
(
"when evaluating query condition"
,
t
,
func
()
{
bus
.
AddHandler
(
"test"
,
func
(
query
*
m
.
GetDataSourceByIdQuery
)
error
{
queryConditionScenario
(
"Given avg() and > 100"
,
func
(
ctx
*
queryConditionTestContext
)
{
query
.
Result
=
&
m
.
DataSource
{
Id
:
1
,
Type
:
"graphite"
}
return
nil
ctx
.
reducer
=
`{"type": "avg"}`
ctx
.
evaluator
=
`{"type": ">", "params": [100]}`
Convey
(
"should trigger when avg is above 100"
,
func
()
{
ctx
.
series
=
tsdb
.
TimeSeriesSlice
{
tsdb
.
NewTimeSeries
(
"test1"
,
[][
2
]
float64
{{
120
,
0
}})}
ctx
.
exec
()
So
(
ctx
.
result
.
Error
,
ShouldBeNil
)
So
(
ctx
.
result
.
Triggered
,
ShouldBeTrue
)
})
Convey
(
"Should not trigger when avg is below 100"
,
func
()
{
ctx
.
series
=
tsdb
.
TimeSeriesSlice
{
tsdb
.
NewTimeSeries
(
"test1"
,
[][
2
]
float64
{{
90
,
0
}})}
ctx
.
exec
()
So
(
ctx
.
result
.
Error
,
ShouldBeNil
)
So
(
ctx
.
result
.
Triggered
,
ShouldBeFalse
)
})
})
})
})
}
type
queryConditionTestContext
struct
{
reducer
string
evaluator
string
series
tsdb
.
TimeSeriesSlice
result
*
AlertResultContext
}
Convey
(
"Given avg() and > 100"
,
func
()
{
type
queryConditionScenarioFunc
func
(
c
*
queryConditionTestContext
)
func
(
ctx
*
queryConditionTestContext
)
exec
()
{
jsonModel
,
err
:=
simplejson
.
NewJson
([]
byte
(
`{
jsonModel
,
err
:=
simplejson
.
NewJson
([]
byte
(
`{
"type": "query",
"type": "query",
"query": {
"query": {
...
@@ -28,37 +55,38 @@ func TestQueryCondition(t *testing.T) {
...
@@ -28,37 +55,38 @@ func TestQueryCondition(t *testing.T) {
"datasourceId": 1,
"datasourceId": 1,
"model": {"target": "aliasByNode(statsd.fakesite.counters.session_start.mobile.count, 4)"}
"model": {"target": "aliasByNode(statsd.fakesite.counters.session_start.mobile.count, 4)"}
},
},
"reducer":
{"type": "avg", "params": []}
,
"reducer":
`
+
ctx
.
reducer
+
`
,
"evaluator":
{"type": ">", "params": [100]}
"evaluator":
`
+
ctx
.
evaluator
+
`
}`
))
}`
))
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
condition
,
err
:=
NewQueryCondition
(
jsonModel
)
condition
,
err
:=
NewQueryCondition
(
jsonModel
)
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
Convey
(
"Should set result to triggered when avg is above 100"
,
func
()
{
context
:=
&
AlertResultContext
{
Rule
:
&
AlertRule
{},
}
condition
.
HandleRequest
=
func
(
req
*
tsdb
.
Request
)
(
*
tsdb
.
Response
,
error
)
{
condition
.
HandleRequest
=
func
(
req
*
tsdb
.
Request
)
(
*
tsdb
.
Response
,
error
)
{
return
&
tsdb
.
Response
{
return
&
tsdb
.
Response
{
Results
:
map
[
string
]
*
tsdb
.
QueryResult
{
Results
:
map
[
string
]
*
tsdb
.
QueryResult
{
"A"
:
&
tsdb
.
QueryResult
{
"A"
:
{
Series
:
ctx
.
series
},
Series
:
tsdb
.
TimeSeriesSlice
{
tsdb
.
NewTimeSeries
(
"test1"
,
[][
2
]
float64
{{
120
,
0
}}),
},
},
},
},
},
nil
},
nil
}
}
condition
.
Eval
(
context
)
condition
.
Eval
(
ctx
.
result
)
}
So
(
context
.
Error
,
ShouldBeNil
)
func
queryConditionScenario
(
desc
string
,
fn
queryConditionScenarioFunc
)
{
So
(
context
.
Triggered
,
ShouldBeTrue
)
Convey
(
desc
,
func
()
{
})
bus
.
AddHandler
(
"test"
,
func
(
query
*
m
.
GetDataSourceByIdQuery
)
error
{
query
.
Result
=
&
m
.
DataSource
{
Id
:
1
,
Type
:
"graphite"
}
return
nil
})
})
ctx
:=
&
queryConditionTestContext
{}
ctx
.
result
=
&
AlertResultContext
{
Rule
:
&
AlertRule
{},
}
fn
(
ctx
)
})
})
}
}
pkg/services/alerting/handler.go
View file @
f0fc336e
...
@@ -55,7 +55,6 @@ func (e *HandlerImpl) eval(context *AlertResultContext) {
...
@@ -55,7 +55,6 @@ func (e *HandlerImpl) eval(context *AlertResultContext) {
}
}
context
.
EndTime
=
time
.
Now
()
context
.
EndTime
=
time
.
Now
()
context
.
DoneChan
<-
true
}
}
// func (e *HandlerImpl) executeQuery(job *AlertJob) (tsdb.TimeSeriesSlice, error) {
// func (e *HandlerImpl) executeQuery(job *AlertJob) (tsdb.TimeSeriesSlice, error) {
...
...
pkg/services/alerting/handler_test.go
View file @
f0fc336e
...
@@ -19,26 +19,26 @@ func TestAlertingExecutor(t *testing.T) {
...
@@ -19,26 +19,26 @@ func TestAlertingExecutor(t *testing.T) {
handler
:=
NewHandler
()
handler
:=
NewHandler
()
Convey
(
"Show return triggered with single passing condition"
,
func
()
{
Convey
(
"Show return triggered with single passing condition"
,
func
()
{
rule
:=
&
AlertRule
{
context
:=
NewAlertResultContext
(
&
AlertRule
{
Conditions
:
[]
AlertCondition
{
&
conditionStub
{
Conditions
:
[]
AlertCondition
{
&
conditionStub
{
triggered
:
true
,
triggered
:
true
,
}},
}},
}
}
)
result
:=
handler
.
eval
(
rule
)
handler
.
eval
(
context
)
So
(
resul
t
.
Triggered
,
ShouldEqual
,
true
)
So
(
contex
t
.
Triggered
,
ShouldEqual
,
true
)
})
})
Convey
(
"Show return false with not passing condition"
,
func
()
{
Convey
(
"Show return false with not passing condition"
,
func
()
{
rule
:=
&
AlertRule
{
context
:=
NewAlertResultContext
(
&
AlertRule
{
Conditions
:
[]
AlertCondition
{
Conditions
:
[]
AlertCondition
{
&
conditionStub
{
triggered
:
true
},
&
conditionStub
{
triggered
:
true
},
&
conditionStub
{
triggered
:
false
},
&
conditionStub
{
triggered
:
false
},
},
},
}
}
)
result
:=
handler
.
eval
(
rule
)
handler
.
eval
(
context
)
So
(
resul
t
.
Triggered
,
ShouldEqual
,
false
)
So
(
contex
t
.
Triggered
,
ShouldEqual
,
false
)
})
})
// Convey("Show return critical since below 2", func() {
// Convey("Show return critical since below 2", func() {
...
...
public/sass/components/_jsontree.scss
View file @
f0fc336e
...
@@ -8,7 +8,7 @@ json-tree {
...
@@ -8,7 +8,7 @@ json-tree {
&
:
:
before
{
&
:
:
before
{
pointer-events
:
none
;
pointer-events
:
none
;
}
}
&
:
:
before
,
&
>
.
key
{
&
:
:
before
,
&
>
.
json-tree-
key
{
cursor
:
pointer
;
cursor
:
pointer
;
}
}
}
}
...
@@ -41,7 +41,7 @@ json-tree {
...
@@ -41,7 +41,7 @@ json-tree {
content
:
'\25b6'
;
content
:
'\25b6'
;
position
:
absolute
;
position
:
absolute
;
left
:
0px
;
left
:
0px
;
font-size
:
10
px
;
font-size
:
8
px
;
transition
:
transform
.1s
ease
;
transition
:
transform
.1s
ease
;
}
}
&.
expanded
:
:
before
{
&.
expanded
:
:
before
{
...
...
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