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
75a54e85
Commit
75a54e85
authored
Dec 25, 2017
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dont spawn new subprocess while shutting down
parent
05362a96
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
20 additions
and
14 deletions
+20
-14
pkg/cmd/grafana-server/server.go
+1
-1
pkg/plugins/dashboard_importer_test.go
+2
-1
pkg/plugins/dashboards_test.go
+2
-1
pkg/plugins/datasource_plugin.go
+8
-3
pkg/plugins/models.go
+0
-2
pkg/plugins/plugins.go
+4
-4
pkg/plugins/plugins_test.go
+3
-2
No files found.
pkg/cmd/grafana-server/server.go
View file @
75a54e85
...
@@ -63,7 +63,7 @@ func (g *GrafanaServerImpl) Start() error {
...
@@ -63,7 +63,7 @@ func (g *GrafanaServerImpl) Start() error {
login
.
Init
()
login
.
Init
()
social
.
NewOAuthService
()
social
.
NewOAuthService
()
pluginManager
,
err
:=
plugins
.
NewPluginManager
()
pluginManager
,
err
:=
plugins
.
NewPluginManager
(
g
.
context
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Failed to start plugins. error: %v"
,
err
)
return
fmt
.
Errorf
(
"Failed to start plugins. error: %v"
,
err
)
}
}
...
...
pkg/plugins/dashboard_importer_test.go
View file @
75a54e85
package
plugins
package
plugins
import
(
import
(
"context"
"io/ioutil"
"io/ioutil"
"testing"
"testing"
...
@@ -91,7 +92,7 @@ func pluginScenario(desc string, t *testing.T, fn func()) {
...
@@ -91,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
()
err
:=
Init
(
context
.
TODO
()
)
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
...
...
pkg/plugins/dashboards_test.go
View file @
75a54e85
package
plugins
package
plugins
import
(
import
(
"context"
"testing"
"testing"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/bus"
...
@@ -17,7 +18,7 @@ func TestPluginDashboards(t *testing.T) {
...
@@ -17,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
()
err
:=
Init
(
context
.
TODO
()
)
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
...
...
pkg/plugins/datasource_plugin.go
View file @
75a54e85
package
plugins
package
plugins
import
(
import
(
"context"
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"os"
"os"
...
@@ -69,11 +70,11 @@ func buildExecutablePath(pluginDir, executable, os, arch string) string {
...
@@ -69,11 +70,11 @@ func buildExecutablePath(pluginDir, executable, os, arch string) string {
return
path
.
Join
(
pluginDir
,
fmt
.
Sprintf
(
"%s_%s_%s"
,
executable
,
strings
.
ToLower
(
os
),
strings
.
ToLower
(
arch
)))
return
path
.
Join
(
pluginDir
,
fmt
.
Sprintf
(
"%s_%s_%s"
,
executable
,
strings
.
ToLower
(
os
),
strings
.
ToLower
(
arch
)))
}
}
func
(
p
*
DataSourcePlugin
)
initBackendPlugin
(
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
()
p
.
spawnSubProcess
()
go
p
.
reattachKilledProcess
()
go
p
.
reattachKilledProcess
(
ctx
)
return
nil
return
nil
}
}
...
@@ -108,14 +109,17 @@ func (p *DataSourcePlugin) spawnSubProcess() error {
...
@@ -108,14 +109,17 @@ func (p *DataSourcePlugin) spawnSubProcess() error {
return
nil
return
nil
}
}
func
(
p
*
DataSourcePlugin
)
reattachKilledProcess
(
)
{
func
(
p
*
DataSourcePlugin
)
reattachKilledProcess
(
ctx
context
.
Context
)
error
{
ticker
:=
time
.
NewTicker
(
time
.
Second
*
1
)
ticker
:=
time
.
NewTicker
(
time
.
Second
*
1
)
for
{
for
{
select
{
select
{
case
<-
ctx
.
Done
()
:
return
ctx
.
Err
()
case
<-
ticker
.
C
:
case
<-
ticker
.
C
:
if
p
.
client
.
Exited
()
{
if
p
.
client
.
Exited
()
{
err
:=
p
.
spawnSubProcess
()
err
:=
p
.
spawnSubProcess
()
p
.
log
.
Debug
(
"Spawning new sub process"
,
"name"
,
p
.
Name
,
"id"
,
p
.
Id
)
if
err
!=
nil
{
if
err
!=
nil
{
p
.
log
.
Error
(
"Failed to spawn subprocess"
)
p
.
log
.
Error
(
"Failed to spawn subprocess"
)
}
}
...
@@ -126,6 +130,7 @@ func (p *DataSourcePlugin) reattachKilledProcess() {
...
@@ -126,6 +130,7 @@ func (p *DataSourcePlugin) reattachKilledProcess() {
func
(
p
*
DataSourcePlugin
)
Kill
()
{
func
(
p
*
DataSourcePlugin
)
Kill
()
{
if
p
.
client
!=
nil
{
if
p
.
client
!=
nil
{
p
.
log
.
Debug
(
"Killing subprocess "
,
"name"
,
p
.
Name
)
p
.
client
.
Kill
()
p
.
client
.
Kill
()
}
}
}
}
pkg/plugins/models.go
View file @
75a54e85
...
@@ -41,8 +41,6 @@ type PluginBase struct {
...
@@ -41,8 +41,6 @@ type PluginBase struct {
HideFromList
bool
`json:"hideFromList,omitempty"`
HideFromList
bool
`json:"hideFromList,omitempty"`
State
string
`json:"state,omitempty"`
State
string
`json:"state,omitempty"`
IncludedInAppId
string
`json:"-"`
IncludedInAppId
string
`json:"-"`
PluginDir
string
`json:"-"`
PluginDir
string
`json:"-"`
DefaultNavUrl
string
`json:"-"`
DefaultNavUrl
string
`json:"-"`
...
...
pkg/plugins/plugins.go
View file @
75a54e85
...
@@ -42,8 +42,8 @@ type PluginManager struct {
...
@@ -42,8 +42,8 @@ type PluginManager struct {
log
log
.
Logger
log
log
.
Logger
}
}
func
NewPluginManager
()
(
*
PluginManager
,
error
)
{
func
NewPluginManager
(
ctx
context
.
Context
)
(
*
PluginManager
,
error
)
{
Init
()
Init
(
ctx
)
return
&
PluginManager
{
return
&
PluginManager
{
log
:
log
.
New
(
"plugins"
),
log
:
log
.
New
(
"plugins"
),
},
nil
},
nil
...
@@ -60,7 +60,7 @@ func (p *PluginManager) Run(ctx context.Context) error {
...
@@ -60,7 +60,7 @@ func (p *PluginManager) Run(ctx context.Context) error {
return
ctx
.
Err
()
return
ctx
.
Err
()
}
}
func
Init
()
error
{
func
Init
(
ctx
context
.
Context
)
error
{
plog
=
log
.
New
(
"plugins"
)
plog
=
log
.
New
(
"plugins"
)
DataSources
=
make
(
map
[
string
]
*
DataSourcePlugin
)
DataSources
=
make
(
map
[
string
]
*
DataSourcePlugin
)
...
@@ -98,7 +98,7 @@ func Init() error {
...
@@ -98,7 +98,7 @@ func Init() error {
}
}
for
_
,
ds
:=
range
DataSources
{
for
_
,
ds
:=
range
DataSources
{
if
ds
.
Backend
{
if
ds
.
Backend
{
ds
.
initBackendPlugin
(
plog
)
ds
.
initBackendPlugin
(
ctx
,
plog
)
}
}
ds
.
initFrontendPlugin
()
ds
.
initFrontendPlugin
()
...
...
pkg/plugins/plugins_test.go
View file @
75a54e85
package
plugins
package
plugins
import
(
import
(
"context"
"path/filepath"
"path/filepath"
"testing"
"testing"
...
@@ -14,7 +15,7 @@ func TestPluginScans(t *testing.T) {
...
@@ -14,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
()
err
:=
Init
(
context
.
TODO
()
)
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
So
(
len
(
DataSources
),
ShouldBeGreaterThan
,
1
)
So
(
len
(
DataSources
),
ShouldBeGreaterThan
,
1
)
...
@@ -29,7 +30,7 @@ func TestPluginScans(t *testing.T) {
...
@@ -29,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
()
err
:=
Init
(
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