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
690868c8
Commit
690868c8
authored
Nov 17, 2016
by
utkarshcmu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added firingEvalution to Rule test
parent
f46c4c88
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
2 deletions
+17
-2
pkg/api/alerting.go
+2
-1
pkg/api/dtos/alerting.go
+1
-0
pkg/services/alerting/eval_context.go
+1
-0
pkg/services/alerting/eval_handler.go
+13
-1
No files found.
pkg/api/alerting.go
View file @
690868c8
...
...
@@ -119,7 +119,8 @@ func AlertTest(c *middleware.Context, dto dtos.AlertTestCommand) Response {
res
:=
backendCmd
.
Result
dtoRes
:=
&
dtos
.
AlertTestResult
{
Firing
:
res
.
Firing
,
Firing
:
res
.
Firing
,
FiringEval
:
res
.
FiringEval
,
}
if
res
.
Error
!=
nil
{
...
...
pkg/api/dtos/alerting.go
View file @
690868c8
...
...
@@ -36,6 +36,7 @@ type AlertTestCommand struct {
type
AlertTestResult
struct
{
Firing
bool
`json:"firing"`
FiringEval
string
`json:"firingEvaluation"`
TimeMs
string
`json:"timeMs"`
Error
string
`json:"error,omitempty"`
EvalMatches
[]
*
EvalMatch
`json:"matches,omitempty"`
...
...
pkg/services/alerting/eval_context.go
View file @
690868c8
...
...
@@ -18,6 +18,7 @@ type EvalContext struct {
Logs
[]
*
ResultLogEntry
Error
error
Description
string
FiringEval
string
StartTime
time
.
Time
EndTime
time
.
Time
Rule
*
Rule
...
...
pkg/services/alerting/eval_handler.go
View file @
690868c8
package
alerting
import
(
"strconv"
"time"
"github.com/grafana/grafana/pkg/log"
...
...
@@ -21,7 +22,9 @@ func NewEvalHandler() *DefaultEvalHandler {
func
(
e
*
DefaultEvalHandler
)
Eval
(
context
*
EvalContext
)
{
firing
:=
true
for
_
,
condition
:=
range
context
.
Rule
.
Conditions
{
firingEval
:=
""
for
i
:=
0
;
i
<
len
(
context
.
Rule
.
Conditions
);
i
++
{
condition
:=
context
.
Rule
.
Conditions
[
i
]
cr
,
err
:=
condition
.
Eval
(
context
)
if
err
!=
nil
{
context
.
Error
=
err
...
...
@@ -33,15 +36,24 @@ func (e *DefaultEvalHandler) Eval(context *EvalContext) {
}
// calculating Firing based on operator
operator
:=
"AND"
if
cr
.
Operator
==
"or"
{
firing
=
firing
||
cr
.
Firing
operator
=
"OR"
}
else
{
firing
=
firing
&&
cr
.
Firing
}
if
i
>
0
{
firingEval
=
"["
+
firingEval
+
" "
+
operator
+
" "
+
strconv
.
FormatBool
(
cr
.
Firing
)
+
"]"
}
else
{
firingEval
=
strconv
.
FormatBool
(
firing
)
}
context
.
EvalMatches
=
append
(
context
.
EvalMatches
,
cr
.
EvalMatches
...
)
}
context
.
FiringEval
=
firingEval
+
" = "
+
strconv
.
FormatBool
(
firing
)
context
.
Firing
=
firing
context
.
EndTime
=
time
.
Now
()
elapsedTime
:=
context
.
EndTime
.
Sub
(
context
.
StartTime
)
/
time
.
Millisecond
...
...
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