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
0398face
Commit
0398face
authored
Mar 12, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(plugins): dashboard import for data sources is working! #4298
parent
3fb0b718
Show whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
271 additions
and
73 deletions
+271
-73
pkg/api/dashboard_snapshot.go
+0
-2
pkg/api/dtos/models.go
+1
-1
pkg/components/simplejson/simplejson_go11.go
+0
-2
pkg/models/dashboard_snapshot.go
+7
-3
pkg/plugins/dashboard_importer.go
+30
-17
pkg/plugins/dashboard_importer_test.go
+10
-5
pkg/services/sqlstore/dashboard.go
+2
-2
pkg/services/sqlstore/dashboard_snapshot_test.go
+4
-3
pkg/services/sqlstore/dashboard_test.go
+9
-8
public/app/features/dashboard/dashnav/dashnav.ts
+2
-2
public/app/features/plugins/import_list/import_list.html
+3
-3
public/app/features/plugins/import_list/import_list.ts
+1
-1
public/app/features/plugins/partials/ds_edit.html
+1
-1
public/app/plugins/datasource/graphite/dashboards/carbon_metrics.json
+176
-0
public/app/plugins/datasource/graphite/dashboards/carbon_stats.json
+0
-22
public/app/plugins/datasource/graphite/plugin.json
+1
-1
tests/test-app/dashboards/connections.json
+4
-0
tests/test-app/dashboards/connections_result.json
+20
-0
No files found.
pkg/api/dashboard_snapshot.go
View file @
0398face
...
...
@@ -53,7 +53,6 @@ func CreateDashboardSnapshot(c *middleware.Context, cmd m.CreateDashboardSnapsho
}
func
GetDashboardSnapshot
(
c
*
middleware
.
Context
)
{
key
:=
c
.
Params
(
":key"
)
query
:=
&
m
.
GetDashboardSnapshotQuery
{
Key
:
key
}
...
...
@@ -136,5 +135,4 @@ func SearchDashboardSnapshots(c *middleware.Context) Response {
}
return
Json
(
200
,
dtos
)
//return Json(200, searchQuery.Result)
}
pkg/api/dtos/models.go
View file @
0398face
...
...
@@ -54,7 +54,7 @@ type DashboardMeta struct {
type
DashboardFullWithMeta
struct
{
Meta
DashboardMeta
`json:"meta"`
Dashboard
map
[
string
]
interface
{}
`json:"dashboard"`
Dashboard
*
simplejson
.
Json
`json:"dashboard"`
}
type
DataSource
struct
{
...
...
pkg/components/simplejson/simplejson_go11.go
View file @
0398face
...
...
@@ -6,7 +6,6 @@ import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"reflect"
"strconv"
...
...
@@ -14,7 +13,6 @@ import (
// Implements the json.Unmarshaler interface.
func
(
j
*
Json
)
UnmarshalJSON
(
p
[]
byte
)
error
{
fmt
.
Printf
(
"UnmarshalJSON"
)
dec
:=
json
.
NewDecoder
(
bytes
.
NewBuffer
(
p
))
dec
.
UseNumber
()
return
dec
.
Decode
(
&
j
.
data
)
...
...
pkg/models/dashboard_snapshot.go
View file @
0398face
package
models
import
"time"
import
(
"time"
"github.com/grafana/grafana/pkg/components/simplejson"
)
// DashboardSnapshot model
type
DashboardSnapshot
struct
{
...
...
@@ -17,7 +21,7 @@ type DashboardSnapshot struct {
Created
time
.
Time
Updated
time
.
Time
Dashboard
map
[
string
]
interface
{}
Dashboard
*
simplejson
.
Json
}
// DashboardSnapshotDTO without dashboard map
...
...
@@ -40,7 +44,7 @@ type DashboardSnapshotDTO struct {
// COMMANDS
type
CreateDashboardSnapshotCommand
struct
{
Dashboard
map
[
string
]
interface
{}
`json:"dashboard" binding:"Required"`
Dashboard
*
simplejson
.
Json
`json:"dashboard" binding:"Required"`
Name
string
`json:"name" binding:"Required"`
Expires
int64
`json:"expires"`
...
...
pkg/plugins/dashboard_importer.go
View file @
0398face
package
plugins
import
(
"encoding/json"
"fmt"
"reflect"
"regexp"
"github.com/grafana/grafana/pkg/bus"
...
...
@@ -127,32 +127,45 @@ func (this *DashTemplateEvaluator) Eval() (*simplejson.Json, error) {
log
.
Info
(
"Import: dashboard has no __import section"
)
}
this
.
EvalObject
(
this
.
template
,
this
.
result
)
return
this
.
result
,
nil
return
simplejson
.
NewFromAny
(
this
.
evalObject
(
this
.
template
)),
nil
}
func
(
this
*
DashTemplateEvaluator
)
EvalObject
(
source
*
simplejson
.
Json
,
writer
*
simplejson
.
Json
)
{
func
(
this
*
DashTemplateEvaluator
)
evalValue
(
source
*
simplejson
.
Json
)
interface
{}
{
for
key
,
value
:=
range
source
.
MustMap
()
{
if
key
==
"__inputs"
{
continue
}
sourceValue
:=
source
.
Interface
()
switch
v
:=
v
alue
.
(
type
)
{
switch
v
:=
sourceV
alue
.
(
type
)
{
case
string
:
interpolated
:=
this
.
varRegex
.
ReplaceAllStringFunc
(
v
,
func
(
match
string
)
string
{
return
this
.
variables
[
match
]
})
writer
.
Set
(
key
,
interpolated
)
return
interpolated
case
bool
:
return
v
case
json
.
Number
:
return
v
case
map
[
string
]
interface
{}
:
childSource
:=
simplejson
.
NewFromAny
(
value
)
childWriter
:=
simplejson
.
New
()
writer
.
Set
(
key
,
childWriter
.
Interface
())
this
.
EvalObject
(
childSource
,
childWriter
)
return
this
.
evalObject
(
source
)
case
[]
interface
{}
:
default
:
log
.
Info
(
"type: %v"
,
reflect
.
TypeOf
(
value
))
log
.
Error
(
3
,
"Unknown json type key: %v , type: %v"
,
key
,
value
)
array
:=
make
([]
interface
{},
0
)
for
_
,
item
:=
range
v
{
array
=
append
(
array
,
this
.
evalValue
(
simplejson
.
NewFromAny
(
item
))
)
}
return
array
}
return
nil
}
func
(
this
*
DashTemplateEvaluator
)
evalObject
(
source
*
simplejson
.
Json
)
interface
{}
{
result
:=
make
(
map
[
string
]
interface
{})
for
key
,
value
:=
range
source
.
MustMap
()
{
if
key
==
"__inputs"
{
continue
}
result
[
key
]
=
this
.
evalValue
(
simplejson
.
NewFromAny
(
value
))
}
return
result
}
pkg/plugins/dashboard_importer_test.go
View file @
0398face
package
plugins
import
(
"io/ioutil"
"testing"
"github.com/grafana/grafana/pkg/bus"
...
...
@@ -34,7 +35,7 @@ func TestDashboardImport(t *testing.T) {
OrgId
:
1
,
UserId
:
1
,
Inputs
:
[]
ImportDashboardInput
{
{
Name
:
"*"
,
Type
:
"datasource"
},
{
Name
:
"*"
,
Type
:
"datasource"
,
Value
:
"graphite"
},
},
}
...
...
@@ -44,11 +45,15 @@ func TestDashboardImport(t *testing.T) {
Convey
(
"should install dashboard"
,
func
()
{
So
(
importedDash
,
ShouldNotBeNil
)
dashStr
,
_
:=
importedDash
.
Data
.
EncodePretty
()
So
(
string
(
dashStr
),
ShouldEqual
,
""
)
resultStr
,
_
:=
importedDash
.
Data
.
EncodePretty
()
expectedBytes
,
_
:=
ioutil
.
ReadFile
(
"../../tests/test-app/dashboards/connections_result.json"
)
expectedJson
,
_
:=
simplejson
.
NewJson
(
expectedBytes
)
expectedStr
,
_
:=
expectedJson
.
EncodePretty
()
// So(panel["datasource"], ShouldEqual, "graphite")
// So(importedDash.Data["__inputs"], ShouldBeNil)
So
(
string
(
resultStr
),
ShouldEqual
,
string
(
expectedStr
))
panel
:=
importedDash
.
Data
.
Get
(
"rows"
)
.
GetIndex
(
0
)
.
Get
(
"panels"
)
.
GetIndex
(
0
)
So
(
panel
.
Get
(
"datasource"
)
.
MustString
(),
ShouldEqual
,
"graphite"
)
})
})
...
...
pkg/services/sqlstore/dashboard.go
View file @
0398face
...
...
@@ -69,7 +69,7 @@ func SaveDashboard(cmd *m.SaveDashboardCommand) error {
affectedRows
,
err
=
sess
.
Insert
(
dash
)
}
else
{
dash
.
Version
+=
1
dash
.
Data
[
"version"
]
=
dash
.
Version
dash
.
Data
.
Set
(
"version"
,
dash
.
Version
)
affectedRows
,
err
=
sess
.
Id
(
dash
.
Id
)
.
Update
(
dash
)
}
...
...
@@ -108,7 +108,7 @@ func GetDashboard(query *m.GetDashboardQuery) error {
return
m
.
ErrDashboardNotFound
}
dashboard
.
Data
[
"id"
]
=
dashboard
.
Id
dashboard
.
Data
.
Set
(
"id"
,
dashboard
.
Id
)
query
.
Result
=
&
dashboard
return
nil
...
...
pkg/services/sqlstore/dashboard_snapshot_test.go
View file @
0398face
...
...
@@ -5,6 +5,7 @@ import (
.
"github.com/smartystreets/goconvey/convey"
"github.com/grafana/grafana/pkg/components/simplejson"
m
"github.com/grafana/grafana/pkg/models"
)
...
...
@@ -16,9 +17,9 @@ func TestDashboardSnapshotDBAccess(t *testing.T) {
Convey
(
"Given saved snaphot"
,
func
()
{
cmd
:=
m
.
CreateDashboardSnapshotCommand
{
Key
:
"hej"
,
Dashboard
:
map
[
string
]
interface
{}{
Dashboard
:
simplejson
.
NewFromAny
(
map
[
string
]
interface
{}{
"hello"
:
"mupp"
,
},
}
)
,
}
err
:=
CreateDashboardSnapshot
(
&
cmd
)
So
(
err
,
ShouldBeNil
)
...
...
@@ -29,7 +30,7 @@ func TestDashboardSnapshotDBAccess(t *testing.T) {
So
(
err
,
ShouldBeNil
)
So
(
query
.
Result
,
ShouldNotBeNil
)
So
(
query
.
Result
.
Dashboard
[
"hello"
]
,
ShouldEqual
,
"mupp"
)
So
(
query
.
Result
.
Dashboard
.
Get
(
"hello"
)
.
MustString
()
,
ShouldEqual
,
"mupp"
)
})
})
...
...
pkg/services/sqlstore/dashboard_test.go
View file @
0398face
...
...
@@ -5,6 +5,7 @@ import (
.
"github.com/smartystreets/goconvey/convey"
"github.com/grafana/grafana/pkg/components/simplejson"
m
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/search"
)
...
...
@@ -12,11 +13,11 @@ import (
func
insertTestDashboard
(
title
string
,
orgId
int64
,
tags
...
interface
{})
*
m
.
Dashboard
{
cmd
:=
m
.
SaveDashboardCommand
{
OrgId
:
orgId
,
Dashboard
:
map
[
string
]
interface
{}{
Dashboard
:
simplejson
.
NewFromAny
(
map
[
string
]
interface
{}{
"id"
:
nil
,
"title"
:
title
,
"tags"
:
tags
,
},
}
)
,
}
err
:=
SaveDashboard
(
&
cmd
)
...
...
@@ -58,11 +59,11 @@ func TestDashboardDataAccess(t *testing.T) {
cmd
:=
m
.
SaveDashboardCommand
{
OrgId
:
1
,
Overwrite
:
true
,
Dashboard
:
map
[
string
]
interface
{}{
Dashboard
:
simplejson
.
NewFromAny
(
map
[
string
]
interface
{}{
"id"
:
float64
(
123412321
),
"title"
:
"Expect error"
,
"tags"
:
[]
interface
{}{},
},
}
)
,
}
err
:=
SaveDashboard
(
&
cmd
)
...
...
@@ -76,11 +77,11 @@ func TestDashboardDataAccess(t *testing.T) {
cmd
:=
m
.
SaveDashboardCommand
{
OrgId
:
2
,
Overwrite
:
true
,
Dashboard
:
map
[
string
]
interface
{}{
Dashboard
:
simplejson
.
NewFromAny
(
map
[
string
]
interface
{}{
"id"
:
float64
(
query
.
Result
.
Id
),
"title"
:
"Expect error"
,
"tags"
:
[]
interface
{}{},
},
}
)
,
}
err
:=
SaveDashboard
(
&
cmd
)
...
...
@@ -135,11 +136,11 @@ func TestDashboardDataAccess(t *testing.T) {
Convey
(
"Should not be able to save dashboard with same name"
,
func
()
{
cmd
:=
m
.
SaveDashboardCommand
{
OrgId
:
1
,
Dashboard
:
map
[
string
]
interface
{}{
Dashboard
:
simplejson
.
NewFromAny
(
map
[
string
]
interface
{}{
"id"
:
nil
,
"title"
:
"test dash 23"
,
"tags"
:
[]
interface
{}{},
},
}
)
,
}
err
:=
SaveDashboard
(
&
cmd
)
...
...
public/app/features/dashboard/dashnav/dashnav.ts
View file @
0398face
...
...
@@ -137,8 +137,8 @@ export class DashNavCtrl {
$scope
.
deleteDashboard
=
function
()
{
$scope
.
appEvent
(
'confirm-modal'
,
{
title
:
'Delete
dashboard
'
,
text
:
'Do you want to delete dashboard?'
,
title
:
'Delete'
,
text
:
'Do you want to delete
this
dashboard?'
,
text2
:
$scope
.
dashboard
.
title
,
icon
:
'fa-trash'
,
yesText
:
'Delete'
,
...
...
public/app/features/plugins/import_list/import_list.html
View file @
0398face
...
...
@@ -21,13 +21,13 @@
</td>
<td
style=
"text-align: right"
>
<button
class=
"btn btn-secondary"
ng-click=
"ctrl.import(dash, false)"
ng-show=
"!dash.installed"
>
I
nstall
I
mport
</button>
<button
class=
"btn btn-secondary"
ng-click=
"ctrl.import(dash, true)"
ng-show=
"dash.installed"
>
Re-I
nstall
Re-I
mport
</button>
<button
class=
"btn btn-danger"
ng-click=
"ctrl.remove(dash)"
ng-show=
"dash.installed"
>
Un-install
Delete
</button>
</td>
</tr>
...
...
public/app/features/plugins/import_list/import_list.ts
View file @
0398face
...
...
@@ -34,7 +34,7 @@ export class DashImportListCtrl {
});
}
this
.
backendSrv
.
post
(
`/api/plugins/dashboards/i
nstall
`
,
installCmd
).
then
(
res
=>
{
this
.
backendSrv
.
post
(
`/api/plugins/dashboards/i
mport
`
,
installCmd
).
then
(
res
=>
{
this
.
$rootScope
.
appEvent
(
'alert-success'
,
[
'Dashboard Installed'
,
dash
.
title
]);
_
.
extend
(
dash
,
res
);
});
...
...
public/app/features/plugins/partials/ds_edit.html
View file @
0398face
...
...
@@ -74,7 +74,7 @@
</div>
<div
ng-if=
"ctrl.tabIndex === 1"
class=
"tab-content"
>
<dashboard-import-list
plugin=
"ctrl.datasourceMeta"
datasource=
"ctrl.current"
></dashboard-import-list>
<dashboard-import-list
plugin=
"ctrl.datasourceMeta"
datasource=
"ctrl.current"
></dashboard-import-list>
</div>
</div>
...
...
public/app/plugins/datasource/graphite/dashboards/carbon_metrics.json
0 → 100644
View file @
0398face
{
"__inputs"
:
{
"graphite"
:
{
"type"
:
"datasource"
,
"pluginId"
:
"graphite"
,
"description"
:
"Graphite datasource"
}
},
"revision"
:
"1.0"
,
"title"
:
"Graphite Carbon Metrics"
,
"tags"
:
[
"graphite"
,
"carbon"
],
"style"
:
"dark"
,
"timezone"
:
"browser"
,
"editable"
:
true
,
"hideControls"
:
false
,
"sharedCrosshair"
:
false
,
"rows"
:
[
{
"collapsable"
:
true
,
"collapse"
:
false
,
"editable"
:
true
,
"height"
:
"350px"
,
"notice"
:
false
,
"panels"
:
[
{
"aliasColors"
:
{},
"annotate"
:
{
"enable"
:
false
},
"bars"
:
false
,
"datasource"
:
"$__graphite"
,
"editable"
:
true
,
"fill"
:
0
,
"grid"
:
{
"leftLogBase"
:
1
,
"leftMax"
:
null
,
"leftMin"
:
null
,
"max"
:
null
,
"min"
:
0
,
"rightLogBase"
:
1
,
"rightMax"
:
null
,
"rightMin"
:
null
,
"threshold1"
:
null
,
"threshold1Color"
:
"rgba(216, 200, 27, 0.27)"
,
"threshold2"
:
null
,
"threshold2Color"
:
"rgba(234, 112, 112, 0.22)"
},
"id"
:
1
,
"legend"
:
{
"avg"
:
false
,
"current"
:
false
,
"max"
:
false
,
"min"
:
false
,
"show"
:
true
,
"total"
:
false
,
"values"
:
false
},
"lines"
:
true
,
"linewidth"
:
1
,
"loadingEditor"
:
false
,
"nullPointMode"
:
"null as zero"
,
"percentage"
:
false
,
"pointradius"
:
5
,
"points"
:
false
,
"renderer"
:
"flot"
,
"resolution"
:
100
,
"scale"
:
1
,
"seriesOverrides"
:
[
{
"alias"
:
"Points Per Update"
,
"yaxis"
:
2
},
{
"alias"
:
"CPU"
,
"yaxis"
:
2
}
],
"span"
:
12
,
"stack"
:
false
,
"steppedLine"
:
false
,
"targets"
:
[
{
"refId"
:
"A"
,
"target"
:
"alias(sumSeries(carbon.agents.*.updateOperations),
\"
Updates
\"
) "
},
{
"refId"
:
"B"
,
"target"
:
"alias(sumSeries(carbon.agents.*.metricsReceived),'Metrics Received')"
},
{
"refId"
:
"C"
,
"target"
:
"alias(sumSeries(carbon.agents.*.committedPoints),'Committed Points')"
},
{
"refId"
:
"D"
,
"target"
:
"alias(sumSeries(carbon.agents.*.pointsPerUpdate),'Points Per Update')"
},
{
"refId"
:
"E"
,
"target"
:
"alias(averageSeries(carbon.agents.*.cpuUsage),'CPU')"
},
{
"refId"
:
"F"
,
"target"
:
"alias(sumSeries(carbon.agents.*.creates),'Creates')"
}
],
"timeFrom"
:
null
,
"timeShift"
:
null
,
"title"
:
"Graphite Carbon Metrics"
,
"tooltip"
:
{
"query_as_alias"
:
true
,
"shared"
:
false
,
"value_type"
:
"cumulative"
},
"type"
:
"graph"
,
"x-axis"
:
true
,
"y-axis"
:
true
,
"y_formats"
:
[
"short"
,
"short"
],
"zerofill"
:
true
}
],
"title"
:
"Row1"
}
],
"time"
:
{
"from"
:
"now-3h"
,
"to"
:
"now"
},
"timepicker"
:
{
"collapse"
:
false
,
"enable"
:
true
,
"notice"
:
false
,
"now"
:
true
,
"refresh_intervals"
:
[
"5s"
,
"10s"
,
"30s"
,
"1m"
,
"5m"
,
"15m"
,
"30m"
,
"1h"
,
"2h"
,
"1d"
],
"status"
:
"Stable"
,
"time_options"
:
[
"5m"
,
"15m"
,
"1h"
,
"6h"
,
"12h"
,
"24h"
,
"2d"
,
"7d"
,
"30d"
],
"type"
:
"timepicker"
},
"templating"
:
{
"enable"
:
false
,
"list"
:
[]
},
"annotations"
:
{
"enable"
:
false
,
"list"
:
[]
},
"refresh"
:
false
,
"schemaVersion"
:
8
,
"version"
:
2
,
"links"
:
[]
}
public/app/plugins/datasource/graphite/dashboards/carbon_stats.json
deleted
100644 → 0
View file @
3fb0b718
{
"__inputs"
:
{
"graphite"
:
{
"type"
:
"datasource"
,
"pluginId"
:
"graphite"
,
"description"
:
"Graphite datasource"
}
},
"title"
:
"Carbon Cache Stats"
,
"version"
:
1
,
"rows"
:
[
{
"panels"
:
[
{
"type"
:
"graph"
,
"datasource"
:
"$__graphite"
}
]
}
]
}
public/app/plugins/datasource/graphite/plugin.json
View file @
0398face
...
...
@@ -4,7 +4,7 @@
"id"
:
"graphite"
,
"includes"
:
[
{
"type"
:
"dashboard"
,
"name"
:
"
Carbon Cache Stats"
,
"path"
:
"dashboards/carbon_stat
s.json"
}
{
"type"
:
"dashboard"
,
"name"
:
"
Graphite Carbon Metrics"
,
"path"
:
"dashboards/carbon_metric
s.json"
}
],
"metrics"
:
true
,
...
...
tests/test-app/dashboards/connections.json
View file @
0398face
...
...
@@ -10,6 +10,10 @@
"title"
:
"Nginx Connections"
,
"revision"
:
"1.5"
,
"schemaVersion"
:
11
,
"tags"
:
[
"tag1"
,
"tag2"
],
"number_array"
:
[
1
,
2
,
3
,
10.33
],
"boolean_true"
:
true
,
"boolean_false"
:
false
,
"rows"
:
[
{
...
...
tests/test-app/dashboards/connections_result.json
0 → 100644
View file @
0398face
{
"revision"
:
"1.5"
,
"tags"
:
[
"tag1"
,
"tag2"
],
"boolean_false"
:
false
,
"boolean_true"
:
true
,
"number_array"
:
[
1
,
2
,
3
,
10.33
],
"rows"
:
[
{
"panels"
:
[
{
"datasource"
:
"graphite"
,
"type"
:
"graph"
}
]
}
],
"schemaVersion"
:
11
,
"title"
:
"Nginx Connections"
,
"version"
:
0
}
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