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
2cf72715
Commit
2cf72715
authored
Jun 13, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test(alerting): fixes broken unit tests
parent
d52fc8d0
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
22 additions
and
21 deletions
+22
-21
pkg/services/alerting/alert_rule.go
+2
-2
pkg/services/alerting/executor_test.go
+9
-8
pkg/services/alerting/transformers/aggregation.go
+1
-1
pkg/services/alerting/transformers/transformer.go
+1
-1
pkg/services/sqlstore/alert_rule_changes.go
+9
-9
No files found.
pkg/services/alerting/alert_rule.go
View file @
2cf72715
...
...
@@ -23,7 +23,7 @@ type AlertRule struct {
Query
AlertQuery
Transform
string
TransformParams
simplejson
.
Json
Transformer
transformer
.
Transformer
Transformer
transformer
s
.
Transformer
}
func
getTimeDurationStringToSeconds
(
str
string
)
int64
{
...
...
@@ -56,7 +56,7 @@ func NewAlertRuleFromDBModel(ruleDef *m.Alert) (*AlertRule, error) {
if
model
.
Transform
==
"aggregation"
{
method
:=
ruleDef
.
Expression
.
Get
(
"transform"
)
.
Get
(
"method"
)
.
MustString
()
model
.
Transformer
=
transformer
.
NewAggregationTransformer
(
method
)
model
.
Transformer
=
transformer
s
.
NewAggregationTransformer
(
method
)
}
query
:=
ruleDef
.
Expression
.
Get
(
"query"
)
...
...
pkg/services/alerting/executor_test.go
View file @
2cf72715
...
...
@@ -4,6 +4,7 @@ import (
"testing"
"github.com/grafana/grafana/pkg/services/alerting/alertstates"
"github.com/grafana/grafana/pkg/services/alerting/transformers"
"github.com/grafana/grafana/pkg/tsdb"
.
"github.com/smartystreets/goconvey/convey"
)
...
...
@@ -16,7 +17,7 @@ func TestAlertingExecutor(t *testing.T) {
Convey
(
"Show return ok since avg is above 2"
,
func
()
{
rule
:=
&
AlertRule
{
Critical
:
Level
{
Level
:
10
,
Operator
:
">"
},
Transformer
:
&
AggregationTransformer
{
Method
:
"avg"
}
,
Transformer
:
transformers
.
NewAggregationTransformer
(
"avg"
)
,
}
timeSeries
:=
[]
*
tsdb
.
TimeSeries
{
...
...
@@ -30,7 +31,7 @@ func TestAlertingExecutor(t *testing.T) {
Convey
(
"Show return critical since below 2"
,
func
()
{
rule
:=
&
AlertRule
{
Critical
:
Level
{
Level
:
10
,
Operator
:
"<"
},
Transformer
:
&
AggregationTransformer
{
Method
:
"avg"
}
,
Transformer
:
transformers
.
NewAggregationTransformer
(
"avg"
)
,
}
timeSeries
:=
[]
*
tsdb
.
TimeSeries
{
...
...
@@ -44,7 +45,7 @@ func TestAlertingExecutor(t *testing.T) {
Convey
(
"Show return critical since sum is above 10"
,
func
()
{
rule
:=
&
AlertRule
{
Critical
:
Level
{
Level
:
10
,
Operator
:
">"
},
Transformer
:
&
AggregationTransformer
{
Method
:
"sum"
}
,
Transformer
:
transformers
.
NewAggregationTransformer
(
"sum"
)
,
}
timeSeries
:=
[]
*
tsdb
.
TimeSeries
{
...
...
@@ -58,7 +59,7 @@ func TestAlertingExecutor(t *testing.T) {
Convey
(
"Show return ok since avg is below 10"
,
func
()
{
rule
:=
&
AlertRule
{
Critical
:
Level
{
Level
:
10
,
Operator
:
">"
},
Transformer
:
&
AggregationTransformer
{
Method
:
"avg"
}
,
Transformer
:
transformers
.
NewAggregationTransformer
(
"avg"
)
,
}
timeSeries
:=
[]
*
tsdb
.
TimeSeries
{
...
...
@@ -72,7 +73,7 @@ func TestAlertingExecutor(t *testing.T) {
Convey
(
"Show return ok since min is below 10"
,
func
()
{
rule
:=
&
AlertRule
{
Critical
:
Level
{
Level
:
10
,
Operator
:
">"
},
Transformer
:
&
AggregationTransformer
{
Method
:
"avg"
}
,
Transformer
:
transformers
.
NewAggregationTransformer
(
"avg"
)
,
}
timeSeries
:=
[]
*
tsdb
.
TimeSeries
{
...
...
@@ -86,7 +87,7 @@ func TestAlertingExecutor(t *testing.T) {
Convey
(
"Show return ok since max is above 10"
,
func
()
{
rule
:=
&
AlertRule
{
Critical
:
Level
{
Level
:
10
,
Operator
:
">"
},
Transformer
:
&
AggregationTransformer
{
Method
:
"max"
}
,
Transformer
:
transformers
.
NewAggregationTransformer
(
"max"
)
,
}
timeSeries
:=
[]
*
tsdb
.
TimeSeries
{
...
...
@@ -103,7 +104,7 @@ func TestAlertingExecutor(t *testing.T) {
Convey
(
"both are ok"
,
func
()
{
rule
:=
&
AlertRule
{
Critical
:
Level
{
Level
:
10
,
Operator
:
">"
},
Transformer
:
&
AggregationTransformer
{
Method
:
"avg"
}
,
Transformer
:
transformers
.
NewAggregationTransformer
(
"avg"
)
,
}
timeSeries
:=
[]
*
tsdb
.
TimeSeries
{
...
...
@@ -118,7 +119,7 @@ func TestAlertingExecutor(t *testing.T) {
Convey
(
"first serie is good, second is critical"
,
func
()
{
rule
:=
&
AlertRule
{
Critical
:
Level
{
Level
:
10
,
Operator
:
">"
},
Transformer
:
&
AggregationTransformer
{
Method
:
"avg"
}
,
Transformer
:
transformers
.
NewAggregationTransformer
(
"avg"
)
,
}
timeSeries
:=
[]
*
tsdb
.
TimeSeries
{
...
...
pkg/services/alerting/transformers/aggregation.go
View file @
2cf72715
package
transformer
package
transformer
s
import
(
"fmt"
...
...
pkg/services/alerting/transformers/transformer.go
View file @
2cf72715
package
transformer
package
transformer
s
import
"github.com/grafana/grafana/pkg/tsdb"
...
...
pkg/services/sqlstore/alert_rule_changes.go
View file @
2cf72715
...
...
@@ -18,24 +18,24 @@ func GetAlertRuleChanges(query *m.GetAlertChangesQuery) error {
params
:=
make
([]
interface
{},
0
)
sql
.
WriteString
(
`SELECT
alert_
rule_
change.id,
alert_
rule_
change.org_id,
alert_
rule_
change.alert_id,
alert_
rule_
change.type,
alert_
rule_
change.created
FROM alert_
rule_
change
alert_change.id,
alert_change.org_id,
alert_change.alert_id,
alert_change.type,
alert_change.created
FROM alert_change
`
)
sql
.
WriteString
(
`WHERE alert_
rule_
change.org_id = ?`
)
sql
.
WriteString
(
`WHERE alert_change.org_id = ?`
)
params
=
append
(
params
,
query
.
OrgId
)
if
query
.
SinceId
!=
0
{
sql
.
WriteString
(
`AND alert_
rule_
change.id >= ?`
)
sql
.
WriteString
(
`AND alert_change.id >= ?`
)
params
=
append
(
params
,
query
.
SinceId
)
}
if
query
.
Limit
!=
0
{
sql
.
WriteString
(
` ORDER BY alert_
rule_
change.id DESC LIMIT ?`
)
sql
.
WriteString
(
` ORDER BY alert_change.id DESC LIMIT ?`
)
params
=
append
(
params
,
query
.
Limit
)
}
...
...
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