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
8b05af2f
Commit
8b05af2f
authored
Jun 23, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(alerting): add exeuction time to alertResult
parent
f95be63c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
20 additions
and
11 deletions
+20
-11
pkg/services/alerting/engine.go
+5
-4
pkg/services/alerting/handler.go
+6
-4
pkg/services/alerting/models.go
+3
-0
pkg/services/alerting/result_handler.go
+5
-3
pkg/services/alerting/result_handler_test.go
+1
-0
No files found.
pkg/services/alerting/engine.go
View file @
8b05af2f
...
...
@@ -95,10 +95,11 @@ func (e *Engine) executeJob(job *AlertJob) {
select
{
case
<-
time
.
After
(
time
.
Second
*
5
)
:
e
.
resultQueue
<-
&
AlertResult
{
State
:
alertstates
.
Pending
,
Duration
:
float64
(
time
.
Since
(
now
)
.
Nanoseconds
())
/
float64
(
1000000
),
Error
:
fmt
.
Errorf
(
"Timeout"
),
AlertJob
:
job
,
State
:
alertstates
.
Pending
,
Duration
:
float64
(
time
.
Since
(
now
)
.
Nanoseconds
())
/
float64
(
1000000
),
Error
:
fmt
.
Errorf
(
"Timeout"
),
AlertJob
:
job
,
ExeuctionTime
:
time
.
Now
(),
}
e
.
log
.
Debug
(
"Job Execution timeout"
,
"alertRuleId"
,
job
.
Rule
.
Id
)
case
result
:=
<-
resultChan
:
...
...
pkg/services/alerting/handler.go
View file @
8b05af2f
...
...
@@ -2,6 +2,7 @@ package alerting
import
(
"fmt"
"time"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/log"
...
...
@@ -28,9 +29,10 @@ func (e *HandlerImpl) Execute(job *AlertJob, resultQueue chan *AlertResult) {
timeSeries
,
err
:=
e
.
executeQuery
(
job
)
if
err
!=
nil
{
resultQueue
<-
&
AlertResult
{
Error
:
err
,
State
:
alertstates
.
Pending
,
AlertJob
:
job
,
Error
:
err
,
State
:
alertstates
.
Pending
,
AlertJob
:
job
,
ExeuctionTime
:
time
.
Now
(),
}
}
...
...
@@ -136,5 +138,5 @@ func (e *HandlerImpl) evaluateRule(rule *AlertRule, series tsdb.TimeSeriesSlice)
}
}
return
&
AlertResult
{
State
:
executionState
,
Description
:
"Returned "
+
executionState
,
TriggeredAlerts
:
triggeredAlert
}
return
&
AlertResult
{
State
:
executionState
,
Description
:
"Returned "
+
executionState
,
TriggeredAlerts
:
triggeredAlert
,
ExeuctionTime
:
time
.
Now
()
}
}
pkg/services/alerting/models.go
View file @
8b05af2f
package
alerting
import
"time"
type
AlertJob
struct
{
Offset
int64
Delay
bool
...
...
@@ -28,6 +30,7 @@ type AlertResult struct {
Description
string
Error
error
AlertJob
*
AlertJob
ExeuctionTime
time
.
Time
}
type
TriggeredAlert
struct
{
...
...
pkg/services/alerting/result_handler.go
View file @
8b05af2f
...
...
@@ -55,13 +55,15 @@ func (handler *ResultHandlerImpl) shouldUpdateState(result *AlertResult) bool {
return
false
}
now
:=
time
.
Now
()
if
query
.
Result
==
nil
{
return
true
}
olderThen15Min
:=
query
.
Result
.
Created
.
Before
(
now
.
Add
(
time
.
Minute
*
-
15
))
//now := time.Now()
//olderThen15Min := query.Result.Created.Before(now.Add(time.Minute * -15))
lastExecution
:=
query
.
Result
.
Created
asdf
:=
result
.
ExeuctionTime
.
Add
(
time
.
Minute
*
-
15
)
olderThen15Min
:=
lastExecution
.
Before
(
asdf
)
changedState
:=
query
.
Result
.
NewState
!=
result
.
State
return
changedState
||
olderThen15Min
...
...
pkg/services/alerting/result_handler_test.go
View file @
8b05af2f
...
...
@@ -51,6 +51,7 @@ func TestAlertResultHandler(t *testing.T) {
Created
:
now
.
Add
(
time
.
Minute
*
-
30
),
}
mockResult
.
State
=
alertstates
.
Critical
mockResult
.
ExeuctionTime
=
time
.
Now
()
So
(
resultHandler
.
shouldUpdateState
(
mockResult
),
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