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
8cd1d179
Commit
8cd1d179
authored
Jun 10, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(alerting): new alerting model\
parent
0c69c5af
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
72 additions
and
95 deletions
+72
-95
pkg/services/alerting/dashboard_parser.go
+19
-18
pkg/services/alerting/executor.go
+5
-5
pkg/services/alerting/models.go
+21
-19
pkg/services/sqlstore/alert_rule_parser_test.go
+20
-41
public/app/plugins/panel/graph/alert_tab_ctrl.ts
+7
-12
No files found.
pkg/services/alerting/dashboard_parser.go
View file @
8cd1d179
...
@@ -30,8 +30,8 @@ func ParseAlertsFromDashboard(cmd *m.SaveDashboardCommand) []*m.AlertRuleDAO {
...
@@ -30,8 +30,8 @@ func ParseAlertsFromDashboard(cmd *m.SaveDashboardCommand) []*m.AlertRuleDAO {
log
.
Info
(
"Alertrule: %v"
,
alert
.
Name
)
log
.
Info
(
"Alertrule: %v"
,
alert
.
Name
)
valueQuery
:=
alerting
.
Get
(
"
valueQ
uery"
)
valueQuery
:=
alerting
.
Get
(
"
q
uery"
)
valueQueryRef
:=
valueQuery
.
Get
(
"
queryR
efId"
)
.
MustString
()
valueQueryRef
:=
valueQuery
.
Get
(
"
r
efId"
)
.
MustString
()
for
_
,
targetsObj
:=
range
panel
.
Get
(
"targets"
)
.
MustArray
()
{
for
_
,
targetsObj
:=
range
panel
.
Get
(
"targets"
)
.
MustArray
()
{
target
:=
simplejson
.
NewFromAny
(
targetsObj
)
target
:=
simplejson
.
NewFromAny
(
targetsObj
)
...
@@ -48,7 +48,7 @@ func ParseAlertsFromDashboard(cmd *m.SaveDashboardCommand) []*m.AlertRuleDAO {
...
@@ -48,7 +48,7 @@ func ParseAlertsFromDashboard(cmd *m.SaveDashboardCommand) []*m.AlertRuleDAO {
if
err
:=
bus
.
Dispatch
(
query
);
err
==
nil
{
if
err
:=
bus
.
Dispatch
(
query
);
err
==
nil
{
for
_
,
ds
:=
range
query
.
Result
{
for
_
,
ds
:=
range
query
.
Result
{
if
ds
.
IsDefault
{
if
ds
.
IsDefault
{
alerting
.
SetPath
([]
string
{
"
valueQ
uery"
,
"datasourceId"
},
ds
.
Id
)
alerting
.
SetPath
([]
string
{
"
q
uery"
,
"datasourceId"
},
ds
.
Id
)
}
}
}
}
}
}
...
@@ -58,12 +58,12 @@ func ParseAlertsFromDashboard(cmd *m.SaveDashboardCommand) []*m.AlertRuleDAO {
...
@@ -58,12 +58,12 @@ func ParseAlertsFromDashboard(cmd *m.SaveDashboardCommand) []*m.AlertRuleDAO {
OrgId
:
cmd
.
OrgId
,
OrgId
:
cmd
.
OrgId
,
}
}
bus
.
Dispatch
(
query
)
bus
.
Dispatch
(
query
)
alerting
.
SetPath
([]
string
{
"
valueQ
uery"
,
"datasourceId"
},
query
.
Result
.
Id
)
alerting
.
SetPath
([]
string
{
"
q
uery"
,
"datasourceId"
},
query
.
Result
.
Id
)
}
}
targetQuery
:=
target
.
Get
(
"target"
)
.
MustString
()
targetQuery
:=
target
.
Get
(
"target"
)
.
MustString
()
if
targetQuery
!=
""
{
if
targetQuery
!=
""
{
alerting
.
SetPath
([]
string
{
"
valueQ
uery"
,
"query"
},
targetQuery
)
alerting
.
SetPath
([]
string
{
"
q
uery"
,
"query"
},
targetQuery
)
}
}
}
}
}
}
...
@@ -105,23 +105,24 @@ func ParseAlertRulesFromAlertModel(ruleDef *m.AlertRuleDAO) (*AlertRule, error)
...
@@ -105,23 +105,24 @@ func ParseAlertRulesFromAlertModel(ruleDef *m.AlertRuleDAO) (*AlertRule, error)
}
}
model
.
Frequency
=
ruleDef
.
Expression
.
Get
(
"frequency"
)
.
MustInt64
()
model
.
Frequency
=
ruleDef
.
Expression
.
Get
(
"frequency"
)
.
MustInt64
()
model
.
Transform
=
ruleDef
.
Expression
.
Get
(
"transform"
)
.
Get
(
"type"
)
.
MustString
()
valueQuery
:=
ruleDef
.
Expression
.
Get
(
"valueQuery"
)
model
.
TransformParams
=
*
ruleDef
.
Expression
.
Get
(
"transform"
)
model
.
ValueQuery
=
AlertQuery
{
query
:=
ruleDef
.
Expression
.
Get
(
"query"
)
Query
:
valueQuery
.
Get
(
"query"
)
.
MustString
(),
model
.
Query
=
AlertQuery
{
DatasourceId
:
valueQuery
.
Get
(
"datasourceId"
)
.
MustInt64
(),
Query
:
query
.
Get
(
"query"
)
.
MustString
(),
From
:
valueQuery
.
Get
(
"from"
)
.
MustString
(),
DatasourceId
:
query
.
Get
(
"datasourceId"
)
.
MustInt64
(),
To
:
valueQuery
.
Get
(
"to"
)
.
MustString
(),
From
:
query
.
Get
(
"from"
)
.
MustString
(),
Aggregator
:
valueQuery
.
Get
(
"agg"
)
.
MustString
(),
To
:
query
.
Get
(
"to"
)
.
MustString
(),
Aggregator
:
query
.
Get
(
"agg"
)
.
MustString
(),
}
}
if
model
.
Value
Query
.
Query
==
""
{
if
model
.
Query
.
Query
==
""
{
return
nil
,
fmt
.
Errorf
(
"missing
valueQuery
query"
)
return
nil
,
fmt
.
Errorf
(
"missing
query.
query"
)
}
}
if
model
.
Value
Query
.
DatasourceId
==
0
{
if
model
.
Query
.
DatasourceId
==
0
{
return
nil
,
fmt
.
Errorf
(
"missing
valueQuery
datasourceId"
)
return
nil
,
fmt
.
Errorf
(
"missing
query.
datasourceId"
)
}
}
return
model
,
nil
return
model
,
nil
...
...
pkg/services/alerting/executor.go
View file @
8cd1d179
...
@@ -100,7 +100,7 @@ func (e *ExecutorImpl) Execute(job *AlertJob, resultQueue chan *AlertResult) {
...
@@ -100,7 +100,7 @@ func (e *ExecutorImpl) Execute(job *AlertJob, resultQueue chan *AlertResult) {
func
(
e
*
ExecutorImpl
)
executeQuery
(
job
*
AlertJob
)
(
tsdb
.
TimeSeriesSlice
,
error
)
{
func
(
e
*
ExecutorImpl
)
executeQuery
(
job
*
AlertJob
)
(
tsdb
.
TimeSeriesSlice
,
error
)
{
getDsInfo
:=
&
m
.
GetDataSourceByIdQuery
{
getDsInfo
:=
&
m
.
GetDataSourceByIdQuery
{
Id
:
job
.
Rule
.
Value
Query
.
DatasourceId
,
Id
:
job
.
Rule
.
Query
.
DatasourceId
,
OrgId
:
job
.
Rule
.
OrgId
,
OrgId
:
job
.
Rule
.
OrgId
,
}
}
...
@@ -128,16 +128,16 @@ func (e *ExecutorImpl) executeQuery(job *AlertJob) (tsdb.TimeSeriesSlice, error)
...
@@ -128,16 +128,16 @@ func (e *ExecutorImpl) executeQuery(job *AlertJob) (tsdb.TimeSeriesSlice, error)
}
}
func
(
e
*
ExecutorImpl
)
GetRequestForAlertRule
(
rule
*
AlertRule
,
datasource
*
m
.
DataSource
)
*
tsdb
.
Request
{
func
(
e
*
ExecutorImpl
)
GetRequestForAlertRule
(
rule
*
AlertRule
,
datasource
*
m
.
DataSource
)
*
tsdb
.
Request
{
log
.
Debug2
(
"GetRequest"
,
"query"
,
rule
.
ValueQuery
.
Query
,
"from"
,
rule
.
Value
Query
.
From
,
"datasourceId"
,
datasource
.
Id
)
log
.
Debug2
(
"GetRequest"
,
"query"
,
rule
.
Query
.
Query
,
"from"
,
rule
.
Query
.
From
,
"datasourceId"
,
datasource
.
Id
)
req
:=
&
tsdb
.
Request
{
req
:=
&
tsdb
.
Request
{
TimeRange
:
tsdb
.
TimeRange
{
TimeRange
:
tsdb
.
TimeRange
{
From
:
"-"
+
rule
.
Value
Query
.
From
,
From
:
"-"
+
rule
.
Query
.
From
,
To
:
rule
.
Value
Query
.
To
,
To
:
rule
.
Query
.
To
,
},
},
Queries
:
[]
*
tsdb
.
Query
{
Queries
:
[]
*
tsdb
.
Query
{
{
{
RefId
:
"A"
,
RefId
:
"A"
,
Query
:
rule
.
Value
Query
.
Query
,
Query
:
rule
.
Query
.
Query
,
DataSource
:
&
tsdb
.
DataSourceInfo
{
DataSource
:
&
tsdb
.
DataSourceInfo
{
Id
:
datasource
.
Id
,
Id
:
datasource
.
Id
,
Name
:
datasource
.
Name
,
Name
:
datasource
.
Name
,
...
...
pkg/services/alerting/models.go
View file @
8cd1d179
package
alerting
package
alerting
import
(
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/tsdb"
)
type
AlertJob
struct
{
type
AlertJob
struct
{
Offset
int64
Offset
int64
Delay
bool
Delay
bool
...
@@ -18,26 +23,23 @@ type AlertResult struct {
...
@@ -18,26 +23,23 @@ type AlertResult struct {
}
}
type
AlertRule
struct
{
type
AlertRule
struct
{
Id
int64
Id
int64
OrgId
int64
OrgId
int64
DashboardId
int64
DashboardId
int64
PanelId
int64
PanelId
int64
//WarnLevel float64
Frequency
int64
//CritLevel float64
Name
string
//WarnOperator string
Description
string
//CritOperator string
State
string
Frequency
int64
Warning
Level
Name
string
Critical
Level
Description
string
Query
AlertQuery
State
string
Transform
string
TransformParams
simplejson
.
Json
Warning
Level
}
Critical
Level
ValueQuery
AlertQuery
type
Transformer
interface
{
EvalFunc
string
Transform
(
tsdb
tsdb
.
TimeSeriesSlice
)
float64
EvalQuery
AlertQuery
EvalParam
string
}
}
type
Level
struct
{
type
Level
struct
{
...
...
pkg/services/sqlstore/alert_rule_parser_test.go
View file @
8cd1d179
...
@@ -15,58 +15,37 @@ func TestAlertRuleModelParsing(t *testing.T) {
...
@@ -15,58 +15,37 @@ func TestAlertRuleModelParsing(t *testing.T) {
alertRuleDAO
:=
&
m
.
AlertRuleDAO
{}
alertRuleDAO
:=
&
m
.
AlertRuleDAO
{}
json
,
_
:=
simplejson
.
NewJson
([]
byte
(
`
json
,
_
:=
simplejson
.
NewJson
([]
byte
(
`
{
{
"frequency": 10,
"warning": {
"op": ">",
"level": 10
},
"critical": {
"critical": {
"
level": 20
,
"
op": ">"
,
"
op": ">"
"
level": 20
},
},
"description": "Alerting Panel Title alert",
"query": {
"evalQuery": {
"agg": "avg",
"from": "5m",
"params": [
"#A",
"5m",
"now",
"avg"
],
"queryRefId": "A",
"queryRefId": "A",
"to": "now"
},
"evalStringParam1": "",
"frequency": 10,
"function": "static",
"name": "Alerting Panel Title alert",
"queryRef": "- select query -",
"valueQuery": {
"agg": "avg",
"datasourceId": 1,
"from": "5m",
"from": "5m",
"params": [
"to": "now",
"#A",
"datasourceId": 1,
"5m",
"query": "aliasByNode(statsd.fakesite.counters.session_start.*.count, 4)"
"now",
"avg"
],
"query": "aliasByNode(statsd.fakesite.counters.session_start.*.count, 4)",
"queryRefId": "A",
"to": "now"
},
},
"warning": {
"transform": {
"level": 10,
"name": "aggregation",
"op": ">"
"method": "avg"
}
}`
))
}`
))
alertRuleDAO
.
Name
=
"Test"
alertRuleDAO
.
Name
=
"Test"
alertRuleDAO
.
Expression
=
json
alertRuleDAO
.
Expression
=
json
rule
,
_
:=
alerting
.
ParseAlertRulesFromAlertModel
(
alertRuleDAO
)
rule
,
_
:=
alerting
.
ParseAlertRulesFromAlertModel
(
alertRuleDAO
)
Convey
(
"Confirm that all properties are set"
,
func
()
{
Convey
(
"Confirm that all properties are set"
,
func
()
{
So
(
rule
.
Value
Query
.
Query
,
ShouldEqual
,
"aliasByNode(statsd.fakesite.counters.session_start.*.count, 4)"
)
So
(
rule
.
Query
.
Query
,
ShouldEqual
,
"aliasByNode(statsd.fakesite.counters.session_start.*.count, 4)"
)
So
(
rule
.
Value
Query
.
From
,
ShouldEqual
,
"5m"
)
So
(
rule
.
Query
.
From
,
ShouldEqual
,
"5m"
)
So
(
rule
.
Value
Query
.
To
,
ShouldEqual
,
"now"
)
So
(
rule
.
Query
.
To
,
ShouldEqual
,
"now"
)
So
(
rule
.
Value
Query
.
DatasourceId
,
ShouldEqual
,
1
)
So
(
rule
.
Query
.
DatasourceId
,
ShouldEqual
,
1
)
So
(
rule
.
ValueQuery
.
Aggregator
,
ShouldEqual
,
"avg"
)
//
So(rule.ValueQuery.Aggregator, ShouldEqual, "avg")
So
(
rule
.
Warning
.
Level
,
ShouldEqual
,
10
)
So
(
rule
.
Warning
.
Level
,
ShouldEqual
,
10
)
So
(
rule
.
Warning
.
Operator
,
ShouldEqual
,
">"
)
So
(
rule
.
Warning
.
Operator
,
ShouldEqual
,
">"
)
So
(
rule
.
Critical
.
Level
,
ShouldEqual
,
20
)
So
(
rule
.
Critical
.
Level
,
ShouldEqual
,
20
)
...
...
public/app/plugins/panel/graph/alert_tab_ctrl.ts
View file @
8cd1d179
...
@@ -51,20 +51,15 @@ export class AlertTabCtrl {
...
@@ -51,20 +51,15 @@ export class AlertTabCtrl {
frequency
:
10
,
frequency
:
10
,
warning
:
{
op
:
'>'
,
level
:
10
},
warning
:
{
op
:
'>'
,
level
:
10
},
critical
:
{
op
:
'>'
,
level
:
20
},
critical
:
{
op
:
'>'
,
level
:
20
},
function
:
'static'
,
query
:
{
valueQuery
:
{
refId
:
'A'
,
queryRefId
:
'A'
,
from
:
'5m'
,
from
:
'600s'
,
to
:
'now'
,
to
:
'now'
,
agg
:
'avg'
,
},
},
evalQuery
:
{
transform
:
{
queryRefId
:
'A'
,
type
:
'aggregation'
,
from
:
'600s'
,
method
:
'avg'
to
:
'now'
,
}
agg
:
'avg'
,
},
evalStringParam1
:
''
,
};
};
/** @ngInject */
/** @ngInject */
...
...
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