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
62e8a039
Commit
62e8a039
authored
Nov 17, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(alerting): refactoring PR for OR conditions, #6579
parent
457ae743
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
32 additions
and
30 deletions
+32
-30
pkg/api/alerting.go
+2
-2
pkg/api/dtos/alerting.go
+6
-6
pkg/services/alerting/conditions/query.go
+1
-1
pkg/services/alerting/eval_context.go
+1
-2
pkg/services/alerting/eval_handler.go
+6
-6
pkg/services/alerting/eval_handler_test.go
+8
-8
public/app/features/alerting/partials/alert_tab.html
+5
-5
public/app/features/dashboard/row/row_model.ts
+3
-0
No files found.
pkg/api/alerting.go
View file @
62e8a039
...
...
@@ -119,8 +119,8 @@ func AlertTest(c *middleware.Context, dto dtos.AlertTestCommand) Response {
res
:=
backendCmd
.
Result
dtoRes
:=
&
dtos
.
AlertTestResult
{
Firing
:
res
.
Firing
,
FiringEval
:
res
.
FiringEval
,
Firing
:
res
.
Firing
,
ConditionEvals
:
res
.
ConditionEvals
,
}
if
res
.
Error
!=
nil
{
...
...
pkg/api/dtos/alerting.go
View file @
62e8a039
...
...
@@ -35,12 +35,12 @@ 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"`
Logs
[]
*
AlertTestResultLog
`json:"logs,omitempty"`
Firing
bool
`json:"firing"`
ConditionEvals
string
`json:"conditionEvals
"`
TimeMs
string
`json:"timeMs"`
Error
string
`json:"error,omitempty"`
EvalMatches
[]
*
EvalMatch
`json:"matches,omitempty"`
Logs
[]
*
AlertTestResultLog
`json:"logs,omitempty"`
}
type
AlertTestResultLog
struct
{
...
...
pkg/services/alerting/conditions/query.go
View file @
62e8a039
...
...
@@ -173,7 +173,7 @@ func NewQueryCondition(model *simplejson.Json, index int) (*QueryCondition, erro
condition
.
Evaluator
=
evaluator
operatorJson
:=
model
.
Get
(
"operator"
)
operator
:=
operatorJson
.
Get
(
"type"
)
.
MustString
()
operator
:=
operatorJson
.
Get
(
"type"
)
.
MustString
(
"and"
)
condition
.
Operator
=
operator
return
&
condition
,
nil
...
...
pkg/services/alerting/eval_context.go
View file @
62e8a039
...
...
@@ -17,8 +17,7 @@ type EvalContext struct {
EvalMatches
[]
*
EvalMatch
Logs
[]
*
ResultLogEntry
Error
error
Description
string
FiringEval
string
ConditionEvals
string
StartTime
time
.
Time
EndTime
time
.
Time
Rule
*
Rule
...
...
pkg/services/alerting/eval_handler.go
View file @
62e8a039
...
...
@@ -2,6 +2,7 @@ package alerting
import
(
"strconv"
"strings"
"time"
"github.com/grafana/grafana/pkg/log"
...
...
@@ -22,7 +23,8 @@ func NewEvalHandler() *DefaultEvalHandler {
func
(
e
*
DefaultEvalHandler
)
Eval
(
context
*
EvalContext
)
{
firing
:=
true
firingEval
:=
""
conditionEvals
:=
""
for
i
:=
0
;
i
<
len
(
context
.
Rule
.
Conditions
);
i
++
{
condition
:=
context
.
Rule
.
Conditions
[
i
]
cr
,
err
:=
condition
.
Eval
(
context
)
...
...
@@ -36,24 +38,22 @@ 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
)
+
"]"
conditionEvals
=
"["
+
conditionEvals
+
" "
+
strings
.
ToUpper
(
cr
.
Operator
)
+
" "
+
strconv
.
FormatBool
(
cr
.
Firing
)
+
"]"
}
else
{
firingEval
=
strconv
.
FormatBool
(
firing
)
conditionEvals
=
strconv
.
FormatBool
(
firing
)
}
context
.
EvalMatches
=
append
(
context
.
EvalMatches
,
cr
.
EvalMatches
...
)
}
context
.
FiringEval
=
firingEval
+
" = "
+
strconv
.
FormatBool
(
firing
)
context
.
ConditionEvals
=
conditionEvals
+
" = "
+
strconv
.
FormatBool
(
firing
)
context
.
Firing
=
firing
context
.
EndTime
=
time
.
Now
()
elapsedTime
:=
context
.
EndTime
.
Sub
(
context
.
StartTime
)
/
time
.
Millisecond
...
...
pkg/services/alerting/eval_handler_test.go
View file @
62e8a039
...
...
@@ -30,7 +30,7 @@ func TestAlertingExecutor(t *testing.T) {
handler
.
Eval
(
context
)
So
(
context
.
Firing
,
ShouldEqual
,
true
)
So
(
context
.
FiringEval
,
ShouldEqual
,
"true = true"
)
So
(
context
.
ConditionEvals
,
ShouldEqual
,
"true = true"
)
})
Convey
(
"Show return false with not passing asdf"
,
func
()
{
...
...
@@ -43,7 +43,7 @@ func TestAlertingExecutor(t *testing.T) {
handler
.
Eval
(
context
)
So
(
context
.
Firing
,
ShouldEqual
,
false
)
So
(
context
.
FiringEval
,
ShouldEqual
,
"[true AND false] = false"
)
So
(
context
.
ConditionEvals
,
ShouldEqual
,
"[true AND false] = false"
)
})
Convey
(
"Show return true if any of the condition is passing with OR operator"
,
func
()
{
...
...
@@ -56,7 +56,7 @@ func TestAlertingExecutor(t *testing.T) {
handler
.
Eval
(
context
)
So
(
context
.
Firing
,
ShouldEqual
,
true
)
So
(
context
.
FiringEval
,
ShouldEqual
,
"[true OR false] = true"
)
So
(
context
.
ConditionEvals
,
ShouldEqual
,
"[true OR false] = true"
)
})
Convey
(
"Show return false if any of the condition is failing with AND operator"
,
func
()
{
...
...
@@ -69,7 +69,7 @@ func TestAlertingExecutor(t *testing.T) {
handler
.
Eval
(
context
)
So
(
context
.
Firing
,
ShouldEqual
,
false
)
So
(
context
.
FiringEval
,
ShouldEqual
,
"[true AND false] = false"
)
So
(
context
.
ConditionEvals
,
ShouldEqual
,
"[true AND false] = false"
)
})
Convey
(
"Show return true if one condition is failing with nested OR operator"
,
func
()
{
...
...
@@ -83,7 +83,7 @@ func TestAlertingExecutor(t *testing.T) {
handler
.
Eval
(
context
)
So
(
context
.
Firing
,
ShouldEqual
,
true
)
So
(
context
.
FiringEval
,
ShouldEqual
,
"[[true AND true] OR false] = true"
)
So
(
context
.
ConditionEvals
,
ShouldEqual
,
"[[true AND true] OR false] = true"
)
})
Convey
(
"Show return false if one condition is passing with nested OR operator"
,
func
()
{
...
...
@@ -97,7 +97,7 @@ func TestAlertingExecutor(t *testing.T) {
handler
.
Eval
(
context
)
So
(
context
.
Firing
,
ShouldEqual
,
false
)
So
(
context
.
FiringEval
,
ShouldEqual
,
"[[true AND false] OR false] = false"
)
So
(
context
.
ConditionEvals
,
ShouldEqual
,
"[[true AND false] OR false] = false"
)
})
Convey
(
"Show return false if a condition is failing with nested AND operator"
,
func
()
{
...
...
@@ -111,7 +111,7 @@ func TestAlertingExecutor(t *testing.T) {
handler
.
Eval
(
context
)
So
(
context
.
Firing
,
ShouldEqual
,
false
)
So
(
context
.
FiringEval
,
ShouldEqual
,
"[[true AND false] AND true] = false"
)
So
(
context
.
ConditionEvals
,
ShouldEqual
,
"[[true AND false] AND true] = false"
)
})
Convey
(
"Show return true if a condition is passing with nested OR operator"
,
func
()
{
...
...
@@ -125,7 +125,7 @@ func TestAlertingExecutor(t *testing.T) {
handler
.
Eval
(
context
)
So
(
context
.
Firing
,
ShouldEqual
,
true
)
So
(
context
.
FiringEval
,
ShouldEqual
,
"[[true OR false] OR true] = true"
)
So
(
context
.
ConditionEvals
,
ShouldEqual
,
"[[true OR false] OR true] = true"
)
})
})
}
public/app/features/alerting/partials/alert_tab.html
View file @
62e8a039
...
...
@@ -38,23 +38,23 @@
<h5
class=
"section-heading"
>
Conditions
</h5>
<div
class=
"gf-form-inline"
ng-repeat=
"conditionModel in ctrl.conditionModels"
>
<div
class=
"gf-form"
>
<metric-segment-model
css-class=
"query-keyword"
ng-if=
"$index"
property=
"conditionModel.operator.type"
options=
"ctrl.evalOperators"
custom=
"false"
></metric-segment-model>
<metric-segment-model
css-class=
"query-keyword
width-5
"
ng-if=
"$index"
property=
"conditionModel.operator.type"
options=
"ctrl.evalOperators"
custom=
"false"
></metric-segment-model>
<span
class=
"gf-form-label query-keyword width-5"
ng-if=
"$index===0"
>
WHEN
</span>
</div>
<div
class=
"gf-form"
>
<query-part-editor
class=
"gf-form-label query-part"
part=
"conditionModel.reducerPart"
handle-event=
"ctrl.handleReducerPartEvent(conditionModel, $event)"
>
<query-part-editor
class=
"gf-form-label query-part
width-5
"
part=
"conditionModel.reducerPart"
handle-event=
"ctrl.handleReducerPartEvent(conditionModel, $event)"
>
</query-part-editor>
<span
class=
"gf-form-label query-keyword"
>
OF
</span>
</div>
<div
class=
"gf-form"
>
<query-part-editor
class=
"gf-form-label query-part"
part=
"conditionModel.queryPart"
handle-event=
"ctrl.handleQueryPartEvent(conditionModel, $event)"
>
<query-part-editor
class=
"gf-form-label query-part
width-10
"
part=
"conditionModel.queryPart"
handle-event=
"ctrl.handleQueryPartEvent(conditionModel, $event)"
>
</query-part-editor>
</div>
<div
class=
"gf-form"
>
<metric-segment-model
property=
"conditionModel.evaluator.type"
options=
"ctrl.evalFunctions"
custom=
"false"
css-class=
"query-keyword"
on-change=
"ctrl.evaluatorTypeChanged(conditionModel.evaluator)"
></metric-segment-model>
<input
class=
"gf-form-input max-width-
7
"
type=
"number"
step=
"any"
ng-hide=
"conditionModel.evaluator.params.length === 0"
ng-model=
"conditionModel.evaluator.params[0]"
ng-change=
"ctrl.evaluatorParamsChanged()"
></input>
<input
class=
"gf-form-input max-width-
9
"
type=
"number"
step=
"any"
ng-hide=
"conditionModel.evaluator.params.length === 0"
ng-model=
"conditionModel.evaluator.params[0]"
ng-change=
"ctrl.evaluatorParamsChanged()"
></input>
<label
class=
"gf-form-label query-keyword"
ng-show=
"conditionModel.evaluator.params.length === 2"
>
TO
</label>
<input
class=
"gf-form-input max-width-
7
"
type=
"number"
step=
"any"
ng-if=
"conditionModel.evaluator.params.length === 2"
ng-model=
"conditionModel.evaluator.params[1]"
ng-change=
"ctrl.evaluatorParamsChanged()"
></input>
<input
class=
"gf-form-input max-width-
9
"
type=
"number"
step=
"any"
ng-if=
"conditionModel.evaluator.params.length === 2"
ng-model=
"conditionModel.evaluator.params[1]"
ng-change=
"ctrl.evaluatorParamsChanged()"
></input>
</div>
<div
class=
"gf-form"
>
<label
class=
"gf-form-label"
>
...
...
public/app/features/dashboard/row/row_model.ts
View file @
62e8a039
...
...
@@ -34,6 +34,9 @@ export class DashboardRow {
getSaveModel
()
{
assignModelProperties
(
this
.
model
,
this
,
this
.
defaults
);
// remove properties that dont server persisted purpose
delete
this
.
model
.
isNew
;
return
this
.
model
;
}
...
...
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