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
82cd2449
Commit
82cd2449
authored
Nov 28, 2017
by
Marcus Efraimsson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashfolders: revert automatic creation of folders for plugins
parent
852218e8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
167 deletions
+17
-167
pkg/plugins/dashboard_importer.go
+0
-61
pkg/plugins/dashboard_importer_test.go
+17
-96
pkg/plugins/dashboards.go
+0
-10
No files found.
pkg/plugins/dashboard_importer.go
View file @
82cd2449
...
...
@@ -49,10 +49,6 @@ func ImportDashboard(cmd *ImportDashboardCommand) error {
if
dashboard
,
err
=
loadPluginDashboard
(
cmd
.
PluginId
,
cmd
.
Path
);
err
!=
nil
{
return
err
}
if
err
=
createDashboardFolderForPlugin
(
cmd
,
dashboard
);
err
!=
nil
{
return
err
}
}
else
{
dashboard
=
m
.
NewDashboardFromJson
(
cmd
.
Dashboard
)
}
...
...
@@ -93,63 +89,6 @@ func ImportDashboard(cmd *ImportDashboardCommand) error {
return
nil
}
func
createDashboardFolderForPlugin
(
cmd
*
ImportDashboardCommand
,
dashboard
*
m
.
Dashboard
)
error
{
var
err
error
var
plugin
*
PluginBase
if
plugin
,
err
=
getPlugin
(
cmd
.
PluginId
);
err
!=
nil
{
return
err
}
var
pluginType
string
if
plugin
.
Type
==
"datasource"
{
pluginType
=
"Datasource"
}
else
if
plugin
.
Type
==
"app"
{
pluginType
=
"App"
}
folderTitle
:=
fmt
.
Sprint
(
pluginType
,
": "
,
plugin
.
Name
)
folderDash
:=
simplejson
.
NewFromAny
(
map
[
string
]
interface
{}{
"schemaVersion"
:
16
,
"title"
:
folderTitle
,
"editable"
:
true
,
"hideControls"
:
true
,
})
saveCmd
:=
m
.
SaveDashboardCommand
{
Dashboard
:
folderDash
,
OrgId
:
cmd
.
OrgId
,
UserId
:
cmd
.
UserId
,
PluginId
:
cmd
.
PluginId
,
IsFolder
:
true
,
}
dashModel
:=
saveCmd
.
GetDashboardModel
()
getDashboardQuery
:=
m
.
GetDashboardQuery
{
OrgId
:
cmd
.
OrgId
,
Slug
:
dashModel
.
Slug
,
}
if
err
:=
bus
.
Dispatch
(
&
getDashboardQuery
);
err
!=
nil
{
return
err
}
if
getDashboardQuery
.
Result
!=
nil
{
dashboard
.
FolderId
=
getDashboardQuery
.
Result
.
Id
return
nil
}
if
err
:=
bus
.
Dispatch
(
&
saveCmd
);
err
!=
nil
{
return
err
}
dashboard
.
FolderId
=
saveCmd
.
Result
.
Id
return
nil
}
type
DashTemplateEvaluator
struct
{
template
*
simplejson
.
Json
inputs
[]
ImportDashboardInput
...
...
pkg/plugins/dashboard_importer_test.go
View file @
82cd2449
...
...
@@ -13,98 +13,12 @@ import (
)
func
TestDashboardImport
(
t
*
testing
.
T
)
{
Convey
(
"When importing plugin dashboard"
,
t
,
func
()
{
setting
.
Cfg
=
ini
.
Empty
()
sec
,
_
:=
setting
.
Cfg
.
NewSection
(
"plugin.test-app"
)
sec
.
NewKey
(
"path"
,
"../../tests/test-app"
)
err
:=
Init
()
So
(
err
,
ShouldBeNil
)
folderId
:=
int64
(
1000
)
pluginScenario
(
"When importing a plugin dashboard"
,
t
,
func
()
{
var
importedDash
*
m
.
Dashboard
var
createdFolder
*
m
.
Dashboard
bus
.
AddHandler
(
"test"
,
func
(
cmd
*
m
.
SaveDashboardCommand
)
error
{
if
cmd
.
IsFolder
{
createdFolder
=
cmd
.
GetDashboardModel
()
createdFolder
.
Id
=
folderId
cmd
.
Result
=
createdFolder
}
else
{
importedDash
=
cmd
.
GetDashboardModel
()
cmd
.
Result
=
importedDash
}
return
nil
})
bus
.
AddHandler
(
"test"
,
func
(
cmd
*
m
.
GetDashboardQuery
)
error
{
return
nil
})
cmd
:=
ImportDashboardCommand
{
PluginId
:
"test-app"
,
Path
:
"dashboards/connections.json"
,
OrgId
:
1
,
UserId
:
1
,
Inputs
:
[]
ImportDashboardInput
{
{
Name
:
"*"
,
Type
:
"datasource"
,
Value
:
"graphite"
},
},
}
err
=
ImportDashboard
(
&
cmd
)
So
(
err
,
ShouldBeNil
)
Convey
(
"should install dashboard"
,
func
()
{
So
(
importedDash
,
ShouldNotBeNil
)
resultStr
,
_
:=
importedDash
.
Data
.
EncodePretty
()
expectedBytes
,
_
:=
ioutil
.
ReadFile
(
"../../tests/test-app/dashboards/connections_result.json"
)
expectedJson
,
_
:=
simplejson
.
NewJson
(
expectedBytes
)
expectedStr
,
_
:=
expectedJson
.
EncodePretty
()
So
(
string
(
resultStr
),
ShouldEqual
,
string
(
expectedStr
))
panel
:=
importedDash
.
Data
.
Get
(
"rows"
)
.
GetIndex
(
0
)
.
Get
(
"panels"
)
.
GetIndex
(
0
)
So
(
panel
.
Get
(
"datasource"
)
.
MustString
(),
ShouldEqual
,
"graphite"
)
So
(
importedDash
.
FolderId
,
ShouldEqual
,
folderId
)
})
Convey
(
"should create app folder"
,
func
()
{
So
(
createdFolder
.
Title
,
ShouldEqual
,
"App: Test App"
)
So
(
createdFolder
.
Id
,
ShouldEqual
,
folderId
)
})
})
Convey
(
"When re-importing plugin dashboard"
,
t
,
func
()
{
setting
.
Cfg
=
ini
.
Empty
()
sec
,
_
:=
setting
.
Cfg
.
NewSection
(
"plugin.test-app"
)
sec
.
NewKey
(
"path"
,
"../../tests/test-app"
)
err
:=
Init
()
So
(
err
,
ShouldBeNil
)
folderId
:=
int64
(
1000
)
var
importedDash
*
m
.
Dashboard
var
createdFolder
*
m
.
Dashboard
bus
.
AddHandler
(
"test"
,
func
(
cmd
*
m
.
SaveDashboardCommand
)
error
{
if
cmd
.
IsFolder
{
cmd
.
Result
=
cmd
.
GetDashboardModel
()
}
else
{
importedDash
=
cmd
.
GetDashboardModel
()
cmd
.
Result
=
importedDash
}
return
nil
})
bus
.
AddHandler
(
"test"
,
func
(
cmd
*
m
.
GetDashboardQuery
)
error
{
cmd
.
Result
=
&
m
.
Dashboard
{
Id
:
1000
,
Title
:
"Something"
,
}
importedDash
=
cmd
.
GetDashboardModel
()
cmd
.
Result
=
importedDash
return
nil
})
...
...
@@ -118,7 +32,7 @@ func TestDashboardImport(t *testing.T) {
},
}
err
=
ImportDashboard
(
&
cmd
)
err
:
=
ImportDashboard
(
&
cmd
)
So
(
err
,
ShouldBeNil
)
Convey
(
"should install dashboard"
,
func
()
{
...
...
@@ -133,12 +47,6 @@ func TestDashboardImport(t *testing.T) {
panel
:=
importedDash
.
Data
.
Get
(
"rows"
)
.
GetIndex
(
0
)
.
Get
(
"panels"
)
.
GetIndex
(
0
)
So
(
panel
.
Get
(
"datasource"
)
.
MustString
(),
ShouldEqual
,
"graphite"
)
So
(
importedDash
.
FolderId
,
ShouldEqual
,
folderId
)
})
Convey
(
"should not create app folder"
,
func
()
{
So
(
createdFolder
,
ShouldBeNil
)
})
})
...
...
@@ -177,3 +85,16 @@ func TestDashboardImport(t *testing.T) {
})
}
func
pluginScenario
(
desc
string
,
t
*
testing
.
T
,
fn
func
())
{
Convey
(
"Given a plugin"
,
t
,
func
()
{
setting
.
Cfg
=
ini
.
Empty
()
sec
,
_
:=
setting
.
Cfg
.
NewSection
(
"plugin.test-app"
)
sec
.
NewKey
(
"path"
,
"../../tests/test-app"
)
err
:=
Init
()
So
(
err
,
ShouldBeNil
)
Convey
(
desc
,
fn
)
})
}
pkg/plugins/dashboards.go
View file @
82cd2449
...
...
@@ -108,13 +108,3 @@ func loadPluginDashboard(pluginId, path string) (*m.Dashboard, error) {
return
m
.
NewDashboardFromJson
(
data
),
nil
}
func
getPlugin
(
pluginId
string
)
(
*
PluginBase
,
error
)
{
plugin
,
exists
:=
Plugins
[
pluginId
]
if
!
exists
{
return
nil
,
PluginNotFoundError
{
pluginId
}
}
return
plugin
,
nil
}
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