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
44e485af
Commit
44e485af
authored
Jan 09, 2018
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
backend plugins: improves logging
parent
75a54e85
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
20 deletions
+30
-20
pkg/plugins/dashboard_importer_test.go
+1
-1
pkg/plugins/dashboards_test.go
+1
-1
pkg/plugins/datasource_plugin.go
+6
-4
pkg/plugins/plugins.go
+20
-12
pkg/plugins/plugins_test.go
+2
-2
No files found.
pkg/plugins/dashboard_importer_test.go
View file @
44e485af
...
@@ -92,7 +92,7 @@ func pluginScenario(desc string, t *testing.T, fn func()) {
...
@@ -92,7 +92,7 @@ func pluginScenario(desc string, t *testing.T, fn func()) {
setting
.
Cfg
=
ini
.
Empty
()
setting
.
Cfg
=
ini
.
Empty
()
sec
,
_
:=
setting
.
Cfg
.
NewSection
(
"plugin.test-app"
)
sec
,
_
:=
setting
.
Cfg
.
NewSection
(
"plugin.test-app"
)
sec
.
NewKey
(
"path"
,
"../../tests/test-app"
)
sec
.
NewKey
(
"path"
,
"../../tests/test-app"
)
err
:=
Init
(
context
.
TODO
())
err
:=
initPlugins
(
context
.
TODO
())
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
...
...
pkg/plugins/dashboards_test.go
View file @
44e485af
...
@@ -18,7 +18,7 @@ func TestPluginDashboards(t *testing.T) {
...
@@ -18,7 +18,7 @@ func TestPluginDashboards(t *testing.T) {
setting
.
Cfg
=
ini
.
Empty
()
setting
.
Cfg
=
ini
.
Empty
()
sec
,
_
:=
setting
.
Cfg
.
NewSection
(
"plugin.test-app"
)
sec
,
_
:=
setting
.
Cfg
.
NewSection
(
"plugin.test-app"
)
sec
.
NewKey
(
"path"
,
"../../tests/test-app"
)
sec
.
NewKey
(
"path"
,
"../../tests/test-app"
)
err
:=
Init
(
context
.
TODO
())
err
:=
initPlugins
(
context
.
TODO
())
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
...
...
pkg/plugins/datasource_plugin.go
View file @
44e485af
...
@@ -73,10 +73,12 @@ func buildExecutablePath(pluginDir, executable, os, arch string) string {
...
@@ -73,10 +73,12 @@ func buildExecutablePath(pluginDir, executable, os, arch string) string {
func
(
p
*
DataSourcePlugin
)
initBackendPlugin
(
ctx
context
.
Context
,
log
log
.
Logger
)
error
{
func
(
p
*
DataSourcePlugin
)
initBackendPlugin
(
ctx
context
.
Context
,
log
log
.
Logger
)
error
{
p
.
log
=
log
.
New
(
"plugin-id"
,
p
.
Id
)
p
.
log
=
log
.
New
(
"plugin-id"
,
p
.
Id
)
p
.
spawnSubProcess
()
err
:=
p
.
spawnSubProcess
()
go
p
.
reattachKilledProcess
(
ctx
)
if
err
==
nil
{
go
p
.
restartKilledProcess
(
ctx
)
}
return
nil
return
err
}
}
func
(
p
*
DataSourcePlugin
)
spawnSubProcess
()
error
{
func
(
p
*
DataSourcePlugin
)
spawnSubProcess
()
error
{
...
@@ -109,7 +111,7 @@ func (p *DataSourcePlugin) spawnSubProcess() error {
...
@@ -109,7 +111,7 @@ func (p *DataSourcePlugin) spawnSubProcess() error {
return
nil
return
nil
}
}
func
(
p
*
DataSourcePlugin
)
re
attach
KilledProcess
(
ctx
context
.
Context
)
error
{
func
(
p
*
DataSourcePlugin
)
re
start
KilledProcess
(
ctx
context
.
Context
)
error
{
ticker
:=
time
.
NewTicker
(
time
.
Second
*
1
)
ticker
:=
time
.
NewTicker
(
time
.
Second
*
1
)
for
{
for
{
...
...
pkg/plugins/plugins.go
View file @
44e485af
...
@@ -23,8 +23,7 @@ var (
...
@@ -23,8 +23,7 @@ var (
StaticRoutes
[]
*
PluginStaticRoute
StaticRoutes
[]
*
PluginStaticRoute
Apps
map
[
string
]
*
AppPlugin
Apps
map
[
string
]
*
AppPlugin
Plugins
map
[
string
]
*
PluginBase
Plugins
map
[
string
]
*
PluginBase
//BackendDatasources map[string]*BackendDatasource
PluginTypes
map
[
string
]
interface
{}
PluginTypes
map
[
string
]
interface
{}
GrafanaLatestVersion
string
GrafanaLatestVersion
string
GrafanaHasUpdate
bool
GrafanaHasUpdate
bool
...
@@ -43,7 +42,12 @@ type PluginManager struct {
...
@@ -43,7 +42,12 @@ type PluginManager struct {
}
}
func
NewPluginManager
(
ctx
context
.
Context
)
(
*
PluginManager
,
error
)
{
func
NewPluginManager
(
ctx
context
.
Context
)
(
*
PluginManager
,
error
)
{
Init
(
ctx
)
err
:=
initPlugins
(
ctx
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
PluginManager
{
return
&
PluginManager
{
log
:
log
.
New
(
"plugins"
),
log
:
log
.
New
(
"plugins"
),
},
nil
},
nil
...
@@ -60,14 +64,14 @@ func (p *PluginManager) Run(ctx context.Context) error {
...
@@ -60,14 +64,14 @@ func (p *PluginManager) Run(ctx context.Context) error {
return
ctx
.
Err
()
return
ctx
.
Err
()
}
}
func
Init
(
ctx
context
.
Context
)
error
{
func
initPlugins
(
ctx
context
.
Context
)
error
{
plog
=
log
.
New
(
"plugins"
)
plog
=
log
.
New
(
"plugins"
)
DataSources
=
ma
ke
(
map
[
string
]
*
DataSourcePlugin
)
DataSources
=
ma
p
[
string
]
*
DataSourcePlugin
{}
StaticRoutes
=
make
([]
*
PluginStaticRoute
,
0
)
StaticRoutes
=
[]
*
PluginStaticRoute
{}
Panels
=
ma
ke
(
map
[
string
]
*
PanelPlugin
)
Panels
=
ma
p
[
string
]
*
PanelPlugin
{}
Apps
=
ma
ke
(
map
[
string
]
*
AppPlugin
)
Apps
=
ma
p
[
string
]
*
AppPlugin
{}
Plugins
=
ma
ke
(
map
[
string
]
*
PluginBase
)
Plugins
=
ma
p
[
string
]
*
PluginBase
{}
PluginTypes
=
map
[
string
]
interface
{}{
PluginTypes
=
map
[
string
]
interface
{}{
"panel"
:
PanelPlugin
{},
"panel"
:
PanelPlugin
{},
"datasource"
:
DataSourcePlugin
{},
"datasource"
:
DataSourcePlugin
{},
...
@@ -79,9 +83,8 @@ func Init(ctx context.Context) error {
...
@@ -79,9 +83,8 @@ func Init(ctx context.Context) error {
// check if plugins dir exists
// check if plugins dir exists
if
_
,
err
:=
os
.
Stat
(
setting
.
PluginsPath
);
os
.
IsNotExist
(
err
)
{
if
_
,
err
:=
os
.
Stat
(
setting
.
PluginsPath
);
os
.
IsNotExist
(
err
)
{
plog
.
Warn
(
"Plugin dir does not exist"
,
"dir"
,
setting
.
PluginsPath
)
if
err
=
os
.
MkdirAll
(
setting
.
PluginsPath
,
os
.
ModePerm
);
err
!=
nil
{
if
err
=
os
.
MkdirAll
(
setting
.
PluginsPath
,
os
.
ModePerm
);
err
!=
nil
{
plog
.
Warn
(
"Failed to create plugin dir"
,
"dir"
,
setting
.
PluginsPath
,
"error"
,
err
)
plog
.
Error
(
"Failed to create plugin dir"
,
"dir"
,
setting
.
PluginsPath
,
"error"
,
err
)
}
else
{
}
else
{
plog
.
Info
(
"Plugin dir created"
,
"dir"
,
setting
.
PluginsPath
)
plog
.
Info
(
"Plugin dir created"
,
"dir"
,
setting
.
PluginsPath
)
scan
(
setting
.
PluginsPath
)
scan
(
setting
.
PluginsPath
)
...
@@ -96,13 +99,18 @@ func Init(ctx context.Context) error {
...
@@ -96,13 +99,18 @@ func Init(ctx context.Context) error {
for
_
,
panel
:=
range
Panels
{
for
_
,
panel
:=
range
Panels
{
panel
.
initFrontendPlugin
()
panel
.
initFrontendPlugin
()
}
}
for
_
,
ds
:=
range
DataSources
{
for
_
,
ds
:=
range
DataSources
{
if
ds
.
Backend
{
if
ds
.
Backend
{
ds
.
initBackendPlugin
(
ctx
,
plog
)
err
:=
ds
.
initBackendPlugin
(
ctx
,
plog
)
if
err
!=
nil
{
plog
.
Error
(
"Failed to init plugin."
,
"error"
,
err
,
"plugin"
,
ds
.
Id
)
}
}
}
ds
.
initFrontendPlugin
()
ds
.
initFrontendPlugin
()
}
}
for
_
,
app
:=
range
Apps
{
for
_
,
app
:=
range
Apps
{
app
.
initApp
()
app
.
initApp
()
}
}
...
...
pkg/plugins/plugins_test.go
View file @
44e485af
...
@@ -15,7 +15,7 @@ func TestPluginScans(t *testing.T) {
...
@@ -15,7 +15,7 @@ func TestPluginScans(t *testing.T) {
Convey
(
"When scaning for plugins"
,
t
,
func
()
{
Convey
(
"When scaning for plugins"
,
t
,
func
()
{
setting
.
StaticRootPath
,
_
=
filepath
.
Abs
(
"../../public/"
)
setting
.
StaticRootPath
,
_
=
filepath
.
Abs
(
"../../public/"
)
setting
.
Cfg
=
ini
.
Empty
()
setting
.
Cfg
=
ini
.
Empty
()
err
:=
Init
(
context
.
TODO
())
err
:=
initPlugins
(
context
.
TODO
())
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
So
(
len
(
DataSources
),
ShouldBeGreaterThan
,
1
)
So
(
len
(
DataSources
),
ShouldBeGreaterThan
,
1
)
...
@@ -30,7 +30,7 @@ func TestPluginScans(t *testing.T) {
...
@@ -30,7 +30,7 @@ func TestPluginScans(t *testing.T) {
setting
.
Cfg
=
ini
.
Empty
()
setting
.
Cfg
=
ini
.
Empty
()
sec
,
_
:=
setting
.
Cfg
.
NewSection
(
"plugin.nginx-app"
)
sec
,
_
:=
setting
.
Cfg
.
NewSection
(
"plugin.nginx-app"
)
sec
.
NewKey
(
"path"
,
"../../tests/test-app"
)
sec
.
NewKey
(
"path"
,
"../../tests/test-app"
)
err
:=
Init
(
context
.
TODO
())
err
:=
initPlugins
(
context
.
TODO
())
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
So
(
len
(
Apps
),
ShouldBeGreaterThan
,
0
)
So
(
len
(
Apps
),
ShouldBeGreaterThan
,
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