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
ae2d5367
Commit
ae2d5367
authored
Nov 05, 2018
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adds tests for extracting for property
parent
ccd89eee
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
18 additions
and
12 deletions
+18
-12
pkg/services/alerting/extractor.go
+4
-5
pkg/services/alerting/extractor_test.go
+13
-7
pkg/services/alerting/testdata/collapsed-panels.json
+0
-0
pkg/services/alerting/testdata/dash-without-id.json
+0
-0
pkg/services/alerting/testdata/graphite-alert.json
+1
-0
pkg/services/alerting/testdata/influxdb-alert.json
+0
-0
pkg/services/alerting/testdata/panel-with-id-0.json
+0
-0
pkg/services/alerting/testdata/panels-missing-id.json
+0
-0
pkg/services/alerting/testdata/v5-dashboard.json
+0
-0
No files found.
pkg/services/alerting/extractor.go
View file @
ae2d5367
...
...
@@ -2,9 +2,8 @@ package alerting
import
(
"errors"
"time"
"fmt"
"time"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/components/simplejson"
...
...
@@ -114,10 +113,10 @@ func (e *DashAlertExtractor) getAlertFromPanels(jsonWithPanels *simplejson.Json,
return
nil
,
ValidationError
{
Reason
:
"Could not parse frequency"
}
}
rawFo
w
:=
jsonAlert
.
Get
(
"for"
)
.
MustString
()
rawFo
r
:=
jsonAlert
.
Get
(
"for"
)
.
MustString
()
var
forValue
time
.
Duration
if
rawFo
w
!=
""
{
forValue
,
err
=
time
.
ParseDuration
(
rawFo
w
)
if
rawFo
r
!=
""
{
forValue
,
err
=
time
.
ParseDuration
(
rawFo
r
)
if
err
!=
nil
{
return
nil
,
ValidationError
{
Reason
:
"Could not parse for"
}
}
...
...
pkg/services/alerting/extractor_test.go
View file @
ae2d5367
...
...
@@ -3,6 +3,7 @@ package alerting
import
(
"io/ioutil"
"testing"
"time"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/components/simplejson"
...
...
@@ -46,7 +47,7 @@ func TestAlertRuleExtraction(t *testing.T) {
return
nil
})
json
,
err
:=
ioutil
.
ReadFile
(
"./test
-
data/graphite-alert.json"
)
json
,
err
:=
ioutil
.
ReadFile
(
"./testdata/graphite-alert.json"
)
So
(
err
,
ShouldBeNil
)
Convey
(
"Extractor should not modify the original json"
,
func
()
{
...
...
@@ -118,6 +119,11 @@ func TestAlertRuleExtraction(t *testing.T) {
So
(
alerts
[
1
]
.
PanelId
,
ShouldEqual
,
4
)
})
Convey
(
"should extract for param"
,
func
()
{
So
(
alerts
[
0
]
.
For
,
ShouldEqual
,
time
.
Minute
*
2
)
So
(
alerts
[
1
]
.
For
,
ShouldEqual
,
time
.
Duration
(
0
))
})
Convey
(
"should extract name and desc"
,
func
()
{
So
(
alerts
[
0
]
.
Name
,
ShouldEqual
,
"name1"
)
So
(
alerts
[
0
]
.
Message
,
ShouldEqual
,
"desc1"
)
...
...
@@ -140,7 +146,7 @@ func TestAlertRuleExtraction(t *testing.T) {
})
Convey
(
"Panels missing id should return error"
,
func
()
{
panelWithoutId
,
err
:=
ioutil
.
ReadFile
(
"./test
-
data/panels-missing-id.json"
)
panelWithoutId
,
err
:=
ioutil
.
ReadFile
(
"./testdata/panels-missing-id.json"
)
So
(
err
,
ShouldBeNil
)
dashJson
,
err
:=
simplejson
.
NewJson
(
panelWithoutId
)
...
...
@@ -156,7 +162,7 @@ func TestAlertRuleExtraction(t *testing.T) {
})
Convey
(
"Panel with id set to zero should return error"
,
func
()
{
panelWithIdZero
,
err
:=
ioutil
.
ReadFile
(
"./test
-
data/panel-with-id-0.json"
)
panelWithIdZero
,
err
:=
ioutil
.
ReadFile
(
"./testdata/panel-with-id-0.json"
)
So
(
err
,
ShouldBeNil
)
dashJson
,
err
:=
simplejson
.
NewJson
(
panelWithIdZero
)
...
...
@@ -172,7 +178,7 @@ func TestAlertRuleExtraction(t *testing.T) {
})
Convey
(
"Parse alerts from dashboard without rows"
,
func
()
{
json
,
err
:=
ioutil
.
ReadFile
(
"./test
-
data/v5-dashboard.json"
)
json
,
err
:=
ioutil
.
ReadFile
(
"./testdata/v5-dashboard.json"
)
So
(
err
,
ShouldBeNil
)
dashJson
,
err
:=
simplejson
.
NewJson
(
json
)
...
...
@@ -192,7 +198,7 @@ func TestAlertRuleExtraction(t *testing.T) {
})
Convey
(
"Parse and validate dashboard containing influxdb alert"
,
func
()
{
json
,
err
:=
ioutil
.
ReadFile
(
"./test
-
data/influxdb-alert.json"
)
json
,
err
:=
ioutil
.
ReadFile
(
"./testdata/influxdb-alert.json"
)
So
(
err
,
ShouldBeNil
)
dashJson
,
err
:=
simplejson
.
NewJson
(
json
)
...
...
@@ -221,7 +227,7 @@ func TestAlertRuleExtraction(t *testing.T) {
})
Convey
(
"Should be able to extract collapsed panels"
,
func
()
{
json
,
err
:=
ioutil
.
ReadFile
(
"./test
-
data/collapsed-panels.json"
)
json
,
err
:=
ioutil
.
ReadFile
(
"./testdata/collapsed-panels.json"
)
So
(
err
,
ShouldBeNil
)
dashJson
,
err
:=
simplejson
.
NewJson
(
json
)
...
...
@@ -242,7 +248,7 @@ func TestAlertRuleExtraction(t *testing.T) {
})
Convey
(
"Parse and validate dashboard without id and containing an alert"
,
func
()
{
json
,
err
:=
ioutil
.
ReadFile
(
"./test
-
data/dash-without-id.json"
)
json
,
err
:=
ioutil
.
ReadFile
(
"./testdata/dash-without-id.json"
)
So
(
err
,
ShouldBeNil
)
dashJSON
,
err
:=
simplejson
.
NewJson
(
json
)
...
...
pkg/services/alerting/test
-
data/collapsed-panels.json
→
pkg/services/alerting/testdata/collapsed-panels.json
View file @
ae2d5367
File moved
pkg/services/alerting/test
-
data/dash-without-id.json
→
pkg/services/alerting/testdata/dash-without-id.json
View file @
ae2d5367
File moved
pkg/services/alerting/test
-
data/graphite-alert.json
→
pkg/services/alerting/testdata/graphite-alert.json
View file @
ae2d5367
...
...
@@ -23,6 +23,7 @@
"message"
:
"desc1"
,
"handler"
:
1
,
"frequency"
:
"60s"
,
"for"
:
"2m"
,
"conditions"
:
[
{
"type"
:
"query"
,
...
...
pkg/services/alerting/test
-
data/influxdb-alert.json
→
pkg/services/alerting/testdata/influxdb-alert.json
View file @
ae2d5367
File moved
pkg/services/alerting/test
-
data/panel-with-id-0.json
→
pkg/services/alerting/testdata/panel-with-id-0.json
View file @
ae2d5367
File moved
pkg/services/alerting/test
-
data/panels-missing-id.json
→
pkg/services/alerting/testdata/panels-missing-id.json
View file @
ae2d5367
File moved
pkg/services/alerting/test
-
data/v5-dashboard.json
→
pkg/services/alerting/testdata/v5-dashboard.json
View file @
ae2d5367
File moved
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