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
50d98b16
Commit
50d98b16
authored
Jun 03, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(alerting): adds support for retries
parent
68f01d57
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
10 deletions
+32
-10
pkg/models/alerts.go
+1
-0
pkg/models/alerts_state.go
+1
-0
pkg/services/alerting/alerting.go
+29
-9
pkg/services/alerting/executor.go
+1
-1
No files found.
pkg/models/alerts.go
View file @
50d98b16
...
...
@@ -113,6 +113,7 @@ type AlertJob struct {
Offset
int64
Delay
bool
Running
bool
Retry
int
Rule
AlertRule
}
...
...
pkg/models/alerts_state.go
View file @
50d98b16
...
...
@@ -27,6 +27,7 @@ var (
AlertStateCritical
=
"CRITICAL"
AlertStateAcknowledged
=
"ACKNOWLEDGED"
AlertStateMaintenance
=
"MAINTENANCE"
AlertStatePending
=
"PENDING"
)
func
(
this
*
UpdateAlertStateCommand
)
IsValidState
()
bool
{
...
...
pkg/services/alerting/alerting.go
View file @
50d98b16
package
alerting
import
(
"fmt"
"time"
"github.com/grafana/grafana/pkg/bus"
...
...
@@ -9,6 +10,10 @@ import (
"github.com/grafana/grafana/pkg/setting"
)
var
(
MaxRetries
=
3
)
func
Init
()
{
if
!
setting
.
AlertingEnabled
{
return
...
...
@@ -70,6 +75,7 @@ func (scheduler *Scheduler) updateJobs(alertRuleFn func() []m.AlertRule) {
}
else
{
job
=
&
m
.
AlertJob
{
Running
:
false
,
Retry
:
0
,
}
}
...
...
@@ -104,18 +110,32 @@ func (scheduler *Scheduler) executor(executor Executor) {
func
(
scheduler
*
Scheduler
)
handleResponses
()
{
for
response
:=
range
scheduler
.
responseQueue
{
log
.
Info
(
"Response: alert(%d) status(%s) actual(%v) r
unning(%v)"
,
response
.
Id
,
response
.
State
,
response
.
ActualValue
,
response
.
AlertJob
.
Running
)
log
.
Info
(
"Response: alert(%d) status(%s) actual(%v) r
etry(%d) running(%v)"
,
response
.
Id
,
response
.
State
,
response
.
ActualValue
,
response
.
AlertJob
.
Retry
,
response
.
AlertJob
.
Running
)
response
.
AlertJob
.
Running
=
false
cmd
:=
&
m
.
UpdateAlertStateCommand
{
AlertId
:
response
.
Id
,
NewState
:
response
.
State
,
Info
:
response
.
Description
,
if
response
.
State
==
m
.
AlertStatePending
{
response
.
AlertJob
.
Retry
++
if
response
.
AlertJob
.
Retry
>
MaxRetries
{
response
.
State
=
m
.
AlertStateCritical
response
.
Description
=
fmt
.
Sprintf
(
"Failed to run check after %d retires"
,
MaxRetries
)
scheduler
.
saveState
(
response
)
}
}
else
{
response
.
AlertJob
.
Retry
=
0
scheduler
.
saveState
(
response
)
}
}
}
if
err
:=
bus
.
Dispatch
(
cmd
);
err
!=
nil
{
log
.
Error
(
2
,
"failed to save state %v"
,
err
)
}
func
(
scheduler
*
Scheduler
)
saveState
(
response
*
m
.
AlertResult
)
{
cmd
:=
&
m
.
UpdateAlertStateCommand
{
AlertId
:
response
.
Id
,
NewState
:
response
.
State
,
Info
:
response
.
Description
,
}
if
err
:=
bus
.
Dispatch
(
cmd
);
err
!=
nil
{
log
.
Error
(
2
,
"failed to save state %v"
,
err
)
}
}
...
...
@@ -129,7 +149,7 @@ func (scheduler *Scheduler) measureAndExecute(exec Executor, job *m.AlertJob) {
case
<-
time
.
After
(
time
.
Second
*
5
)
:
scheduler
.
responseQueue
<-
&
m
.
AlertResult
{
Id
:
job
.
Rule
.
Id
,
State
:
"timed out"
,
State
:
m
.
AlertStatePending
,
Duration
:
float64
(
time
.
Since
(
now
)
.
Nanoseconds
())
/
float64
(
1000000
),
AlertJob
:
job
,
}
...
...
pkg/services/alerting/executor.go
View file @
50d98b16
...
...
@@ -81,7 +81,7 @@ func (this *ExecutorImpl) Execute(job *m.AlertJob, responseQueue chan *m.AlertRe
response
,
err
:=
b
.
GetSeries
(
job
)
if
err
!=
nil
{
responseQueue
<-
&
m
.
AlertResult
{
State
:
"PENDING"
,
Id
:
job
.
Rule
.
Id
,
AlertJob
:
job
}
responseQueue
<-
&
m
.
AlertResult
{
State
:
m
.
AlertStatePending
,
Id
:
job
.
Rule
.
Id
,
AlertJob
:
job
}
}
result
:=
this
.
validateRule
(
job
.
Rule
,
response
)
...
...
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