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
50811c80
Commit
50811c80
authored
Nov 22, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(alerting): fixes bug that prevents noData from triggering
closes #6631
parent
d73620f3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
1 deletions
+42
-1
pkg/services/alerting/eval_handler.go
+4
-0
pkg/services/alerting/eval_handler_test.go
+38
-1
No files found.
pkg/services/alerting/eval_handler.go
View file @
50811c80
...
@@ -23,6 +23,7 @@ func NewEvalHandler() *DefaultEvalHandler {
...
@@ -23,6 +23,7 @@ func NewEvalHandler() *DefaultEvalHandler {
func
(
e
*
DefaultEvalHandler
)
Eval
(
context
*
EvalContext
)
{
func
(
e
*
DefaultEvalHandler
)
Eval
(
context
*
EvalContext
)
{
firing
:=
true
firing
:=
true
noDataFound
:=
true
conditionEvals
:=
""
conditionEvals
:=
""
for
i
:=
0
;
i
<
len
(
context
.
Rule
.
Conditions
);
i
++
{
for
i
:=
0
;
i
<
len
(
context
.
Rule
.
Conditions
);
i
++
{
...
@@ -40,8 +41,10 @@ func (e *DefaultEvalHandler) Eval(context *EvalContext) {
...
@@ -40,8 +41,10 @@ func (e *DefaultEvalHandler) Eval(context *EvalContext) {
// calculating Firing based on operator
// calculating Firing based on operator
if
cr
.
Operator
==
"or"
{
if
cr
.
Operator
==
"or"
{
firing
=
firing
||
cr
.
Firing
firing
=
firing
||
cr
.
Firing
noDataFound
=
noDataFound
||
cr
.
NoDataFound
}
else
{
}
else
{
firing
=
firing
&&
cr
.
Firing
firing
=
firing
&&
cr
.
Firing
noDataFound
=
noDataFound
&&
cr
.
NoDataFound
}
}
if
i
>
0
{
if
i
>
0
{
...
@@ -55,6 +58,7 @@ func (e *DefaultEvalHandler) Eval(context *EvalContext) {
...
@@ -55,6 +58,7 @@ func (e *DefaultEvalHandler) Eval(context *EvalContext) {
context
.
ConditionEvals
=
conditionEvals
+
" = "
+
strconv
.
FormatBool
(
firing
)
context
.
ConditionEvals
=
conditionEvals
+
" = "
+
strconv
.
FormatBool
(
firing
)
context
.
Firing
=
firing
context
.
Firing
=
firing
context
.
NoDataFound
=
noDataFound
context
.
EndTime
=
time
.
Now
()
context
.
EndTime
=
time
.
Now
()
elapsedTime
:=
context
.
EndTime
.
Sub
(
context
.
StartTime
)
/
time
.
Millisecond
elapsedTime
:=
context
.
EndTime
.
Sub
(
context
.
StartTime
)
/
time
.
Millisecond
metrics
.
M_Alerting_Exeuction_Time
.
Update
(
elapsedTime
)
metrics
.
M_Alerting_Exeuction_Time
.
Update
(
elapsedTime
)
...
...
pkg/services/alerting/eval_handler_test.go
View file @
50811c80
...
@@ -11,10 +11,11 @@ type conditionStub struct {
...
@@ -11,10 +11,11 @@ type conditionStub struct {
firing
bool
firing
bool
operator
string
operator
string
matches
[]
*
EvalMatch
matches
[]
*
EvalMatch
noData
bool
}
}
func
(
c
*
conditionStub
)
Eval
(
context
*
EvalContext
)
(
*
ConditionResult
,
error
)
{
func
(
c
*
conditionStub
)
Eval
(
context
*
EvalContext
)
(
*
ConditionResult
,
error
)
{
return
&
ConditionResult
{
Firing
:
c
.
firing
,
EvalMatches
:
c
.
matches
,
Operator
:
c
.
operator
},
nil
return
&
ConditionResult
{
Firing
:
c
.
firing
,
EvalMatches
:
c
.
matches
,
Operator
:
c
.
operator
,
NoDataFound
:
c
.
noData
},
nil
}
}
func
TestAlertingExecutor
(
t
*
testing
.
T
)
{
func
TestAlertingExecutor
(
t
*
testing
.
T
)
{
...
@@ -127,5 +128,41 @@ func TestAlertingExecutor(t *testing.T) {
...
@@ -127,5 +128,41 @@ func TestAlertingExecutor(t *testing.T) {
So
(
context
.
Firing
,
ShouldEqual
,
true
)
So
(
context
.
Firing
,
ShouldEqual
,
true
)
So
(
context
.
ConditionEvals
,
ShouldEqual
,
"[[true OR false] OR true] = true"
)
So
(
context
.
ConditionEvals
,
ShouldEqual
,
"[[true OR false] OR true] = true"
)
})
})
Convey
(
"Should return no data if one condition has nodata"
,
func
()
{
context
:=
NewEvalContext
(
context
.
TODO
(),
&
Rule
{
Conditions
:
[]
Condition
{
&
conditionStub
{
operator
:
"and"
,
noData
:
true
},
},
})
handler
.
Eval
(
context
)
So
(
context
.
Firing
,
ShouldEqual
,
false
)
So
(
context
.
NoDataFound
,
ShouldBeTrue
)
})
Convey
(
"Should return no data if both conditions have no data and using AND"
,
func
()
{
context
:=
NewEvalContext
(
context
.
TODO
(),
&
Rule
{
Conditions
:
[]
Condition
{
&
conditionStub
{
operator
:
"and"
,
noData
:
true
},
&
conditionStub
{
operator
:
"and"
,
noData
:
false
},
},
})
handler
.
Eval
(
context
)
So
(
context
.
NoDataFound
,
ShouldBeFalse
)
})
Convey
(
"Should not return no data if both conditions have no data and using OR"
,
func
()
{
context
:=
NewEvalContext
(
context
.
TODO
(),
&
Rule
{
Conditions
:
[]
Condition
{
&
conditionStub
{
operator
:
"or"
,
noData
:
true
},
&
conditionStub
{
operator
:
"or"
,
noData
:
false
},
},
})
handler
.
Eval
(
context
)
So
(
context
.
NoDataFound
,
ShouldBeTrue
)
})
})
})
}
}
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