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 {
login
.
Init
()
social
.
NewOAuthService
()
pluginManager
,
err
:=
plugins
.
NewPluginManager
()
pluginManager
,
err
:=
plugins
.
NewPluginManager
(
g
.
context
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Failed to start plugins. error: %v"
,
err
)
}
...
...
pkg/plugins/dashboard_importer_test.go
View file @
75a54e85
package
plugins
import
(
"context"
"io/ioutil"
"testing"
...
...
@@ -91,7 +92,7 @@ func pluginScenario(desc string, t *testing.T, fn func()) {
setting
.
Cfg
=
ini
.
Empty
()
sec
,
_
:=
setting
.
Cfg
.
NewSection
(
"plugin.test-app"
)
sec
.
NewKey
(
"path"
,
"../../tests/test-app"
)
err
:=
Init
()
err
:=
Init
(
context
.
TODO
()
)
So
(
err
,
ShouldBeNil
)
...
...
pkg/plugins/dashboards_test.go
View file @
75a54e85
package
plugins
import
(
"context"
"testing"
"github.com/grafana/grafana/pkg/bus"
...
...
@@ -17,7 +18,7 @@ func TestPluginDashboards(t *testing.T) {
setting
.
Cfg
=
ini
.
Empty
()
sec
,
_
:=
setting
.
Cfg
.
NewSection
(
"plugin.test-app"
)
sec
.
NewKey
(
"path"
,
"../../tests/test-app"
)
err
:=
Init
()
err
:=
Init
(
context
.
TODO
()
)
So
(
err
,
ShouldBeNil
)
...
...
pkg/plugins/datasource_plugin.go
View file @
75a54e85
package
plugins
import
(
"context"
"encoding/json"
"fmt"
"os"
...
...
@@ -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
)))
}
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
.
spawnSubProcess
()
go
p
.
reattachKilledProcess
()
go
p
.
reattachKilledProcess
(
ctx
)
return
nil
}
...
...
@@ -108,14 +109,17 @@ func (p *DataSourcePlugin) spawnSubProcess() error {
return
nil
}
func
(
p
*
DataSourcePlugin
)
reattachKilledProcess
(
)
{
func
(
p
*
DataSourcePlugin
)
reattachKilledProcess
(
ctx
context
.
Context
)
error
{
ticker
:=
time
.
NewTicker
(
time
.
Second
*
1
)
for
{
select
{
case
<-
ctx
.
Done
()
:
return
ctx
.
Err
()
case
<-
ticker
.
C
:
if
p
.
client
.
Exited
()
{
err
:=
p
.
spawnSubProcess
()
p
.
log
.
Debug
(
"Spawning new sub process"
,
"name"
,
p
.
Name
,
"id"
,
p
.
Id
)
if
err
!=
nil
{
p
.
log
.
Error
(
"Failed to spawn subprocess"
)
}
...
...
@@ -126,6 +130,7 @@ func (p *DataSourcePlugin) reattachKilledProcess() {
func
(
p
*
DataSourcePlugin
)
Kill
()
{
if
p
.
client
!=
nil
{
p
.
log
.
Debug
(
"Killing subprocess "
,
"name"
,
p
.
Name
)
p
.
client
.
Kill
()
}
}
pkg/plugins/models.go
View file @
75a54e85
...
...
@@ -41,8 +41,6 @@ type PluginBase struct {
HideFromList
bool
`json:"hideFromList,omitempty"`
State
string
`json:"state,omitempty"`
IncludedInAppId
string
`json:"-"`
PluginDir
string
`json:"-"`
DefaultNavUrl
string
`json:"-"`
...
...
pkg/plugins/plugins.go
View file @
75a54e85
...
...
@@ -42,8 +42,8 @@ type PluginManager struct {
log
log
.
Logger
}
func
NewPluginManager
()
(
*
PluginManager
,
error
)
{
Init
()
func
NewPluginManager
(
ctx
context
.
Context
)
(
*
PluginManager
,
error
)
{
Init
(
ctx
)
return
&
PluginManager
{
log
:
log
.
New
(
"plugins"
),
},
nil
...
...
@@ -60,7 +60,7 @@ func (p *PluginManager) Run(ctx context.Context) error {
return
ctx
.
Err
()
}
func
Init
()
error
{
func
Init
(
ctx
context
.
Context
)
error
{
plog
=
log
.
New
(
"plugins"
)
DataSources
=
make
(
map
[
string
]
*
DataSourcePlugin
)
...
...
@@ -98,7 +98,7 @@ func Init() error {
}
for
_
,
ds
:=
range
DataSources
{
if
ds
.
Backend
{
ds
.
initBackendPlugin
(
plog
)
ds
.
initBackendPlugin
(
ctx
,
plog
)
}
ds
.
initFrontendPlugin
()
...
...
pkg/plugins/plugins_test.go
View file @
75a54e85
package
plugins
import
(
"context"
"path/filepath"
"testing"
...
...
@@ -14,7 +15,7 @@ func TestPluginScans(t *testing.T) {
Convey
(
"When scaning for plugins"
,
t
,
func
()
{
setting
.
StaticRootPath
,
_
=
filepath
.
Abs
(
"../../public/"
)
setting
.
Cfg
=
ini
.
Empty
()
err
:=
Init
()
err
:=
Init
(
context
.
TODO
()
)
So
(
err
,
ShouldBeNil
)
So
(
len
(
DataSources
),
ShouldBeGreaterThan
,
1
)
...
...
@@ -29,7 +30,7 @@ func TestPluginScans(t *testing.T) {
setting
.
Cfg
=
ini
.
Empty
()
sec
,
_
:=
setting
.
Cfg
.
NewSection
(
"plugin.nginx-app"
)
sec
.
NewKey
(
"path"
,
"../../tests/test-app"
)
err
:=
Init
()
err
:=
Init
(
context
.
TODO
()
)
So
(
err
,
ShouldBeNil
)
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