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 {
log
.
Info
(
"Alertrule: %v"
,
alert
.
Name
)
valueQuery
:=
alerting
.
Get
(
"
valueQ
uery"
)
valueQueryRef
:=
valueQuery
.
Get
(
"
queryR
efId"
)
.
MustString
()
valueQuery
:=
alerting
.
Get
(
"
q
uery"
)
valueQueryRef
:=
valueQuery
.
Get
(
"
r
efId"
)
.
MustString
()
for
_
,
targetsObj
:=
range
panel
.
Get
(
"targets"
)
.
MustArray
()
{
target
:=
simplejson
.
NewFromAny
(
targetsObj
)
...
...
@@ -48,7 +48,7 @@ func ParseAlertsFromDashboard(cmd *m.SaveDashboardCommand) []*m.AlertRuleDAO {
if
err
:=
bus
.
Dispatch
(
query
);
err
==
nil
{
for
_
,
ds
:=
range
query
.
Result
{
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 {
OrgId
:
cmd
.
OrgId
,
}
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
()
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)
}
model
.
Frequency
=
ruleDef
.
Expression
.
Get
(
"frequency"
)
.
MustInt64
()
valueQuery
:=
ruleDef
.
Expression
.
Get
(
"valueQuery"
)
model
.
ValueQuery
=
AlertQuery
{
Query
:
valueQuery
.
Get
(
"query"
)
.
MustString
(),
DatasourceId
:
valueQuery
.
Get
(
"datasourceId"
)
.
MustInt64
(),
From
:
valueQuery
.
Get
(
"from"
)
.
MustString
(),
To
:
valueQuery
.
Get
(
"to"
)
.
MustString
(),
Aggregator
:
valueQuery
.
Get
(
"agg"
)
.
MustString
(),
model
.
Transform
=
ruleDef
.
Expression
.
Get
(
"transform"
)
.
Get
(
"type"
)
.
MustString
()
model
.
TransformParams
=
*
ruleDef
.
Expression
.
Get
(
"transform"
)
query
:=
ruleDef
.
Expression
.
Get
(
"query"
)
model
.
Query
=
AlertQuery
{
Query
:
query
.
Get
(
"query"
)
.
MustString
(),
DatasourceId
:
query
.
Get
(
"datasourceId"
)
.
MustInt64
(),
From
:
query
.
Get
(
"from"
)
.
MustString
(),
To
:
query
.
Get
(
"to"
)
.
MustString
(),
Aggregator
:
query
.
Get
(
"agg"
)
.
MustString
(),
}
if
model
.
Value
Query
.
Query
==
""
{
return
nil
,
fmt
.
Errorf
(
"missing
valueQuery
query"
)
if
model
.
Query
.
Query
==
""
{
return
nil
,
fmt
.
Errorf
(
"missing
query.
query"
)
}
if
model
.
Value
Query
.
DatasourceId
==
0
{
return
nil
,
fmt
.
Errorf
(
"missing
valueQuery
datasourceId"
)
if
model
.
Query
.
DatasourceId
==
0
{
return
nil
,
fmt
.
Errorf
(
"missing
query.
datasourceId"
)
}
return
model
,
nil
...
...
pkg/services/alerting/executor.go
View file @
8cd1d179
...
...
@@ -100,7 +100,7 @@ func (e *ExecutorImpl) Execute(job *AlertJob, resultQueue chan *AlertResult) {
func
(
e
*
ExecutorImpl
)
executeQuery
(
job
*
AlertJob
)
(
tsdb
.
TimeSeriesSlice
,
error
)
{
getDsInfo
:=
&
m
.
GetDataSourceByIdQuery
{
Id
:
job
.
Rule
.
Value
Query
.
DatasourceId
,
Id
:
job
.
Rule
.
Query
.
DatasourceId
,
OrgId
:
job
.
Rule
.
OrgId
,
}
...
...
@@ -128,16 +128,16 @@ func (e *ExecutorImpl) executeQuery(job *AlertJob) (tsdb.TimeSeriesSlice, error)
}
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
{
TimeRange
:
tsdb
.
TimeRange
{
From
:
"-"
+
rule
.
Value
Query
.
From
,
To
:
rule
.
Value
Query
.
To
,
From
:
"-"
+
rule
.
Query
.
From
,
To
:
rule
.
Query
.
To
,
},
Queries
:
[]
*
tsdb
.
Query
{
{
RefId
:
"A"
,
Query
:
rule
.
Value
Query
.
Query
,
Query
:
rule
.
Query
.
Query
,
DataSource
:
&
tsdb
.
DataSourceInfo
{
Id
:
datasource
.
Id
,
Name
:
datasource
.
Name
,
...
...
pkg/services/alerting/models.go
View file @
8cd1d179
package
alerting
import
(
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/tsdb"
)
type
AlertJob
struct
{
Offset
int64
Delay
bool
...
...
@@ -18,26 +23,23 @@ type AlertResult struct {
}
type
AlertRule
struct
{
Id
int64
OrgId
int64
DashboardId
int64
PanelId
int64
//WarnLevel float64
//CritLevel float64
//WarnOperator string
//CritOperator string
Frequency
int64
Name
string
Description
string
State
string
Warning
Level
Critical
Level
Id
int64
OrgId
int64
DashboardId
int64
PanelId
int64
Frequency
int64
Name
string
Description
string
State
string
Warning
Level
Critical
Level
Query
AlertQuery
Transform
string
TransformParams
simplejson
.
Json
}
ValueQuery
AlertQuery
EvalFunc
string
EvalQuery
AlertQuery
EvalParam
string
type
Transformer
interface
{
Transform
(
tsdb
tsdb
.
TimeSeriesSlice
)
float64
}
type
Level
struct
{
...
...
pkg/services/sqlstore/alert_rule_parser_test.go
View file @
8cd1d179
...
...
@@ -15,58 +15,37 @@ func TestAlertRuleModelParsing(t *testing.T) {
alertRuleDAO
:=
&
m
.
AlertRuleDAO
{}
json
,
_
:=
simplejson
.
NewJson
([]
byte
(
`
{
"frequency": 10,
"warning": {
"op": ">",
"level": 10
},
"critical": {
"
level": 20
,
"
op": ">"
"
op": ">"
,
"
level": 20
},
"description": "Alerting Panel Title alert",
"evalQuery": {
"agg": "avg",
"from": "5m",
"params": [
"#A",
"5m",
"now",
"avg"
],
"query": {
"queryRefId": "A",
"to": "now"
},
"evalStringParam1": "",
"frequency": 10,
"function": "static",
"name": "Alerting Panel Title alert",
"queryRef": "- select query -",
"valueQuery": {
"agg": "avg",
"datasourceId": 1,
"from": "5m",
"params": [
"#A",
"5m",
"now",
"avg"
],
"query": "aliasByNode(statsd.fakesite.counters.session_start.*.count, 4)",
"queryRefId": "A",
"to": "now"
"to": "now",
"datasourceId": 1,
"query": "aliasByNode(statsd.fakesite.counters.session_start.*.count, 4)"
},
"warning": {
"level": 10,
"op": ">"
}
}`
))
"transform": {
"name": "aggregation",
"method": "avg"
}`
))
alertRuleDAO
.
Name
=
"Test"
alertRuleDAO
.
Expression
=
json
rule
,
_
:=
alerting
.
ParseAlertRulesFromAlertModel
(
alertRuleDAO
)
Convey
(
"Confirm that all properties are set"
,
func
()
{
So
(
rule
.
Value
Query
.
Query
,
ShouldEqual
,
"aliasByNode(statsd.fakesite.counters.session_start.*.count, 4)"
)
So
(
rule
.
Value
Query
.
From
,
ShouldEqual
,
"5m"
)
So
(
rule
.
Value
Query
.
To
,
ShouldEqual
,
"now"
)
So
(
rule
.
Value
Query
.
DatasourceId
,
ShouldEqual
,
1
)
So
(
rule
.
ValueQuery
.
Aggregator
,
ShouldEqual
,
"avg"
)
So
(
rule
.
Query
.
Query
,
ShouldEqual
,
"aliasByNode(statsd.fakesite.counters.session_start.*.count, 4)"
)
So
(
rule
.
Query
.
From
,
ShouldEqual
,
"5m"
)
So
(
rule
.
Query
.
To
,
ShouldEqual
,
"now"
)
So
(
rule
.
Query
.
DatasourceId
,
ShouldEqual
,
1
)
//
So(rule.ValueQuery.Aggregator, ShouldEqual, "avg")
So
(
rule
.
Warning
.
Level
,
ShouldEqual
,
10
)
So
(
rule
.
Warning
.
Operator
,
ShouldEqual
,
">"
)
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 {
frequency
:
10
,
warning
:
{
op
:
'>'
,
level
:
10
},
critical
:
{
op
:
'>'
,
level
:
20
},
function
:
'static'
,
valueQuery
:
{
queryRefId
:
'A'
,
from
:
'600s'
,
query
:
{
refId
:
'A'
,
from
:
'5m'
,
to
:
'now'
,
agg
:
'avg'
,
},
evalQuery
:
{
queryRefId
:
'A'
,
from
:
'600s'
,
to
:
'now'
,
agg
:
'avg'
,
},
evalStringParam1
:
''
,
transform
:
{
type
:
'aggregation'
,
method
:
'avg'
}
};
/** @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