@@ -3,54 +3,22 @@ package process
3
3
import (
4
4
"context"
5
5
"errors"
6
- "sync"
7
6
"time"
8
7
9
8
"github.com/grafana/grafana/pkg/plugins"
10
- "github.com/grafana/grafana/pkg/plugins/backendplugin"
11
- "github.com/grafana/grafana/pkg/plugins/log"
12
- "github.com/grafana/grafana/pkg/plugins/manager/registry"
13
9
)
14
10
15
- var _ Service = ( * Manager )( nil )
11
+ type Service struct {}
16
12
17
- type Manager struct {
18
- pluginRegistry registry.Service
19
-
20
- mu sync.Mutex
21
- log log.Logger
22
- }
23
-
24
- func ProvideService (pluginRegistry registry.Service ) * Manager {
25
- return NewManager (pluginRegistry )
13
+ func ProvideService () * Service {
14
+ return & Service {}
26
15
}
27
16
28
- func NewManager (pluginRegistry registry.Service ) * Manager {
29
- return & Manager {
30
- pluginRegistry : pluginRegistry ,
31
- log : log .New ("plugin.process.manager" ),
32
- }
33
- }
34
-
35
- func (m * Manager ) Run (ctx context.Context ) error {
36
- <- ctx .Done ()
37
- m .shutdown (ctx )
38
- return ctx .Err ()
39
- }
40
-
41
- func (m * Manager ) Start (ctx context.Context , pluginID string ) error {
42
- p , exists := m .pluginRegistry .Plugin (ctx , pluginID )
43
- if ! exists {
44
- return backendplugin .ErrPluginNotRegistered
45
- }
46
-
17
+ func (* Service ) Start (ctx context.Context , p * plugins.Plugin ) error {
47
18
if ! p .IsManaged () || ! p .Backend || p .SignatureError != nil {
48
19
return nil
49
20
}
50
21
51
- m .mu .Lock ()
52
- defer m .mu .Unlock ()
53
-
54
22
if err := startPluginAndRestartKilledProcesses (ctx , p ); err != nil {
55
23
return err
56
24
}
@@ -59,15 +27,8 @@ func (m *Manager) Start(ctx context.Context, pluginID string) error {
59
27
return nil
60
28
}
61
29
62
- func (m * Manager ) Stop (ctx context.Context , pluginID string ) error {
63
- p , exists := m .pluginRegistry .Plugin (ctx , pluginID )
64
- if ! exists {
65
- return backendplugin .ErrPluginNotRegistered
66
- }
67
- m .log .Debug ("Stopping plugin process" , "pluginId" , p .ID )
68
- m .mu .Lock ()
69
- defer m .mu .Unlock ()
70
-
30
+ func (* Service ) Stop (ctx context.Context , p * plugins.Plugin ) error {
31
+ p .Logger ().Debug ("Stopping plugin process" )
71
32
if err := p .Decommission (); err != nil {
72
33
return err
73
34
}
@@ -79,23 +40,6 @@ func (m *Manager) Stop(ctx context.Context, pluginID string) error {
79
40
return nil
80
41
}
81
42
82
- // shutdown stops all backend plugin processes
83
- func (m * Manager ) shutdown (ctx context.Context ) {
84
- var wg sync.WaitGroup
85
- for _ , p := range m .pluginRegistry .Plugins (ctx ) {
86
- wg .Add (1 )
87
- go func (p backendplugin.Plugin , ctx context.Context ) {
88
- defer wg .Done ()
89
- p .Logger ().Debug ("Stopping plugin" )
90
- if err := p .Stop (ctx ); err != nil {
91
- p .Logger ().Error ("Failed to stop plugin" , "error" , err )
92
- }
93
- p .Logger ().Debug ("Plugin stopped" )
94
- }(p , ctx )
95
- }
96
- wg .Wait ()
97
- }
98
-
99
43
func startPluginAndRestartKilledProcesses (ctx context.Context , p * plugins.Plugin ) error {
100
44
if err := p .Start (ctx ); err != nil {
101
45
return err
@@ -123,7 +67,7 @@ func restartKilledProcess(ctx context.Context, p *plugins.Plugin) error {
123
67
if err := ctx .Err (); err != nil && ! errors .Is (err , context .Canceled ) {
124
68
return err
125
69
}
126
- return nil
70
+ return p . Stop ( ctx )
127
71
case <- ticker .C :
128
72
if p .IsDecommissioned () {
129
73
p .Logger ().Debug ("Plugin decommissioned" )
0 commit comments