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
d25284a3
Commit
d25284a3
authored
Nov 05, 2018
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
introduce state `unknown` for rules that have not been evaluated yet
parent
6f748d8a
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
46 additions
and
7 deletions
+46
-7
pkg/api/alerting.go
+1
-1
pkg/models/alert.go
+7
-1
pkg/services/alerting/eval_context.go
+5
-0
pkg/services/alerting/notifiers/base.go
+5
-0
pkg/services/alerting/notifiers/base_test.go
+16
-0
pkg/services/sqlstore/alert.go
+3
-3
pkg/services/sqlstore/alert_test.go
+2
-2
public/app/features/alerting/state/alertDef.ts
+7
-0
No files found.
pkg/api/alerting.go
View file @
d25284a3
...
...
@@ -291,7 +291,7 @@ func PauseAlert(c *m.ReqContext, dto dtos.PauseAlertCommand) Response {
return
Error
(
500
,
""
,
err
)
}
var
response
m
.
AlertStateType
=
m
.
AlertState
Pending
var
response
m
.
AlertStateType
=
m
.
AlertState
Unknown
pausedState
:=
"un-paused"
if
cmd
.
Paused
{
response
=
m
.
AlertStatePaused
...
...
pkg/models/alert.go
View file @
d25284a3
...
...
@@ -19,6 +19,7 @@ const (
AlertStateAlerting
AlertStateType
=
"alerting"
AlertStateOK
AlertStateType
=
"ok"
AlertStatePending
AlertStateType
=
"pending"
AlertStateUnknown
AlertStateType
=
"unknown"
)
const
(
...
...
@@ -39,7 +40,12 @@ var (
)
func
(
s
AlertStateType
)
IsValid
()
bool
{
return
s
==
AlertStateOK
||
s
==
AlertStateNoData
||
s
==
AlertStatePaused
||
s
==
AlertStatePending
return
s
==
AlertStateOK
||
s
==
AlertStateNoData
||
s
==
AlertStatePaused
||
s
==
AlertStatePending
||
s
==
AlertStateAlerting
||
s
==
AlertStateUnknown
}
func
(
s
NoDataOption
)
IsValid
()
bool
{
...
...
pkg/services/alerting/eval_context.go
View file @
d25284a3
...
...
@@ -68,6 +68,11 @@ func (c *EvalContext) GetStateModel() *StateDescription {
Color
:
"#D63232"
,
Text
:
"Alerting"
,
}
case
m
.
AlertStateUnknown
:
return
&
StateDescription
{
Color
:
"888888"
,
Text
:
"Unknown"
,
}
default
:
panic
(
"Unknown rule state for alert notifications "
+
c
.
Rule
.
State
)
}
...
...
pkg/services/alerting/notifiers/base.go
View file @
d25284a3
...
...
@@ -67,6 +67,11 @@ func (n *NotifierBase) ShouldNotify(ctx context.Context, context *alerting.EvalC
}
// Do not notify when we become OK for the first time.
if
context
.
PrevAlertState
==
models
.
AlertStateUnknown
&&
context
.
Rule
.
State
==
models
.
AlertStateOK
{
return
false
}
// Do not notify when we become OK from pending
if
context
.
PrevAlertState
==
models
.
AlertStatePending
&&
context
.
Rule
.
State
==
models
.
AlertStateOK
{
return
false
}
...
...
pkg/services/alerting/notifiers/base_test.go
View file @
d25284a3
...
...
@@ -134,6 +134,22 @@ func TestShouldSendAlertNotification(t *testing.T) {
expect
:
true
,
},
{
name
:
"unknown -> ok"
,
prevState
:
m
.
AlertStateUnknown
,
newState
:
m
.
AlertStateOK
,
state
:
&
m
.
AlertNotificationState
{},
expect
:
false
,
},
{
name
:
"unknown -> alerting"
,
prevState
:
m
.
AlertStateUnknown
,
newState
:
m
.
AlertStateAlerting
,
state
:
&
m
.
AlertNotificationState
{},
expect
:
true
,
},
}
for
_
,
tc
:=
range
tcs
{
...
...
pkg/services/sqlstore/alert.go
View file @
d25284a3
...
...
@@ -205,7 +205,7 @@ func updateAlerts(existingAlerts []*m.Alert, cmd *m.SaveAlertsCommand, sess *DBS
}
else
{
alert
.
Updated
=
timeNow
()
alert
.
Created
=
timeNow
()
alert
.
State
=
m
.
AlertState
Pending
alert
.
State
=
m
.
AlertState
Unknown
alert
.
NewStateDate
=
timeNow
()
_
,
err
:=
sess
.
Insert
(
alert
)
...
...
@@ -300,7 +300,7 @@ func PauseAlert(cmd *m.PauseAlertCommand) error {
params
=
append
(
params
,
string
(
m
.
AlertStatePaused
))
params
=
append
(
params
,
timeNow
())
}
else
{
params
=
append
(
params
,
string
(
m
.
AlertState
Pending
))
params
=
append
(
params
,
string
(
m
.
AlertState
Unknown
))
params
=
append
(
params
,
timeNow
())
}
...
...
@@ -324,7 +324,7 @@ func PauseAllAlerts(cmd *m.PauseAllAlertCommand) error {
if
cmd
.
Paused
{
newState
=
string
(
m
.
AlertStatePaused
)
}
else
{
newState
=
string
(
m
.
AlertState
Pending
)
newState
=
string
(
m
.
AlertState
Unknown
)
}
res
,
err
:=
sess
.
Exec
(
`UPDATE alert SET state = ?, new_state_date = ?`
,
newState
,
timeNow
())
...
...
pkg/services/sqlstore/alert_test.go
View file @
d25284a3
...
...
@@ -109,7 +109,7 @@ func TestAlertingDataAccess(t *testing.T) {
So
(
alert
.
DashboardId
,
ShouldEqual
,
testDash
.
Id
)
So
(
alert
.
PanelId
,
ShouldEqual
,
1
)
So
(
alert
.
Name
,
ShouldEqual
,
"Alerting title"
)
So
(
alert
.
State
,
ShouldEqual
,
"pending"
)
So
(
alert
.
State
,
ShouldEqual
,
m
.
AlertStateUnknown
)
So
(
alert
.
NewStateDate
,
ShouldNotBeNil
)
So
(
alert
.
EvalData
,
ShouldNotBeNil
)
So
(
alert
.
EvalData
.
Get
(
"test"
)
.
MustString
(),
ShouldEqual
,
"test"
)
...
...
@@ -154,7 +154,7 @@ func TestAlertingDataAccess(t *testing.T) {
So
(
query
.
Result
[
0
]
.
Name
,
ShouldEqual
,
"Name"
)
Convey
(
"Alert state should not be updated"
,
func
()
{
So
(
query
.
Result
[
0
]
.
State
,
ShouldEqual
,
"pending"
)
So
(
query
.
Result
[
0
]
.
State
,
ShouldEqual
,
m
.
AlertStateUnknown
)
})
})
...
...
public/app/features/alerting/state/alertDef.ts
View file @
d25284a3
...
...
@@ -99,6 +99,13 @@ function getStateDisplayModel(state) {
stateClass
:
'alert-state-warning'
,
};
}
case
'unknown'
:
{
return
{
text
:
'UNKNOWN'
,
iconClass
:
'fa fa-question'
,
stateClass
:
'alert-state-paused'
,
};
}
}
throw
{
message
:
'Unknown alert state'
};
...
...
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