summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-08-17 23:27:37 +0300
committerValery Piashchynski <[email protected]>2021-08-17 23:27:37 +0300
commit65a70f5d15fb0a1b1f787ff7f06b3a299dab0f96 (patch)
treec6c3e8f4b5952c4e389804da38fea0e03b2cd111
parent064d375e3671135226cb3bc70be057339b23f26f (diff)
Update Resetter plugin, remove old and unused code
Signed-off-by: Valery Piashchynski <[email protected]>
-rwxr-xr-x.gitignore2
-rwxr-xr-xMakefile44
-rw-r--r--go.mod6
-rw-r--r--go.sum8
-rw-r--r--plugins/gzip/plugin.go1
-rw-r--r--plugins/reload/plugin.go16
-rw-r--r--plugins/resetter/interface.go16
-rw-r--r--plugins/resetter/plugin.go43
-rw-r--r--plugins/resetter/rpc.go17
-rw-r--r--tests/plugins/resetter/resetter_test.go5
10 files changed, 39 insertions, 119 deletions
diff --git a/.gitignore b/.gitignore
index beb3f885..86a94bda 100755
--- a/.gitignore
+++ b/.gitignore
@@ -12,7 +12,7 @@
unit_tests
unit_tests_copied
dir1
-coverage
+coverage-ci
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
diff --git a/Makefile b/Makefile
index 10f09f33..5cba50c5 100755
--- a/Makefile
+++ b/Makefile
@@ -15,9 +15,13 @@ test_coverage:
go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/bst.txt -covermode=atomic ./pkg/bst
go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/pq.txt -covermode=atomic ./pkg/priority_queue
go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/worker_stack.txt -covermode=atomic ./pkg/worker_watcher
+ go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/broadcast_plugin.txt -covermode=atomic ./tests/plugins/broadcast
+ go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/websockets.txt -covermode=atomic ./tests/plugins/websockets
+ go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/ws_origin.txt -covermode=atomic ./plugins/websockets
+ go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/jobs_core.txt -covermode=atomic ./tests/plugins/jobs
+ go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/struct_jobs.txt -covermode=atomic ./plugins/jobs/job
go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/http_config.txt -covermode=atomic ./plugins/http/config
go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/server_cmd.txt -covermode=atomic ./plugins/server
- go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/struct_jobs.txt -covermode=atomic ./plugins/jobs/job
go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/pipeline_jobs.txt -covermode=atomic ./plugins/jobs/pipeline
go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/http.txt -covermode=atomic ./tests/plugins/http
go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/informer.txt -covermode=atomic ./tests/plugins/informer
@@ -34,10 +38,6 @@ test_coverage:
go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/resetter.txt -covermode=atomic ./tests/plugins/resetter
go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/rpc.txt -covermode=atomic ./tests/plugins/rpc
go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/kv_plugin.txt -covermode=atomic ./tests/plugins/kv
- go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/broadcast_plugin.txt -covermode=atomic ./tests/plugins/broadcast
- go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/websockets.txt -covermode=atomic ./tests/plugins/websockets
- go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/ws_origin.txt -covermode=atomic ./plugins/websockets
- go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/jobs_core.txt -covermode=atomic ./tests/plugins/jobs
cat ./coverage-ci/*.txt > ./coverage-ci/summary.txt
docker-compose -f tests/env/docker-compose.yaml down
@@ -74,37 +74,3 @@ test: ## Run application tests
go test -v -race -tags=debug ./plugins/websockets
go test -v -race -tags=debug ./tests/plugins/jobs
docker-compose -f tests/env/docker-compose.yaml down
-
-testGo1.17rc1: ## Run application tests
- docker-compose -f tests/env/docker-compose.yaml up -d
- go1.17rc1 test -v -race -tags=debug ./pkg/transport/pipe
- go1.17rc1 test -v -race -tags=debug ./pkg/transport/socket
- go1.17rc1 test -v -race -tags=debug ./pkg/pool
- go1.17rc1 test -v -race -tags=debug ./pkg/worker
- go1.17rc1 test -v -race -tags=debug ./pkg/worker_watcher
- go1.17rc1 test -v -race -tags=debug ./pkg/bst
- go1.17rc1 test -v -race -tags=debug ./pkg/priority_queue
- go1.17rc1 test -v -race -tags=debug ./plugins/jobs/job
- go1.17rc1 test -v -race -tags=debug ./plugins/jobs/pipeline
- go1.17rc1 test -v -race -tags=debug ./plugins/http/config
- go1.17rc1 test -v -race -tags=debug ./plugins/server
- go1.17rc1 test -v -race -tags=debug ./plugins/websockets
- go1.17rc1 test -v -race -tags=debug ./tests/plugins/http
- go1.17rc1 test -v -race -tags=debug ./tests/plugins/informer
- go1.17rc1 test -v -race -tags=debug ./tests/plugins/reload
- go1.17rc1 test -v -race -tags=debug ./tests/plugins/server
- go1.17rc1 test -v -race -tags=debug ./tests/plugins/service
- go1.17rc1 test -v -race -tags=debug ./tests/plugins/status
- go1.17rc1 test -v -race -tags=debug ./tests/plugins/config
- go1.17rc1 test -v -race -tags=debug ./tests/plugins/gzip
- go1.17rc1 test -v -race -tags=debug ./tests/plugins/headers
- go1.17rc1 test -v -race -tags=debug ./tests/plugins/logger
- go1.17rc1 test -v -race -tags=debug ./tests/plugins/metrics
- go1.17rc1 test -v -race -tags=debug ./tests/plugins/redis
- go1.17rc1 test -v -race -tags=debug ./tests/plugins/resetter
- go1.17rc1 test -v -race -tags=debug ./tests/plugins/rpc
- go1.17rc1 test -v -race -tags=debug ./tests/plugins/kv
- go1.17rc1 test -v -race -tags=debug ./tests/plugins/websockets
- go1.17rc1 test -v -race -tags=debug ./tests/plugins/broadcast
- go1.17rc1 test -v -race -tags=debug ./tests/plugins/jobs
- docker-compose -f tests/env/docker-compose.yaml down
diff --git a/go.mod b/go.mod
index 79cd6bc8..0daf6abe 100644
--- a/go.mod
+++ b/go.mod
@@ -4,7 +4,6 @@ go 1.17
require (
github.com/Shopify/toxiproxy v2.1.4+incompatible
- github.com/StackExchange/wmi v1.2.1 // indirect
github.com/alicebob/miniredis/v2 v2.15.1
// ========= AWS SDK v2
github.com/aws/aws-sdk-go-v2 v1.8.0
@@ -34,7 +33,6 @@ require (
github.com/spiral/goridge/v3 v3.2.0
// ===========
github.com/stretchr/testify v1.7.0
- github.com/tklauser/go-sysconf v0.3.7 // indirect
github.com/valyala/tcplisten v1.0.0
github.com/yookoala/gofast v0.6.0
go.etcd.io/bbolt v1.3.6
@@ -42,12 +40,13 @@ require (
go.uber.org/zap v1.19.0
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
- golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e
+ golang.org/x/sys v0.0.0-20210816074244-15123e1e1f71
google.golang.org/protobuf v1.27.1
gopkg.in/natefinch/lumberjack.v2 v2.0.0
)
require (
+ github.com/StackExchange/wmi v1.2.1 // indirect
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a // indirect
github.com/andybalholm/brotli v1.0.2 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.4.0 // indirect
@@ -81,6 +80,7 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
+ github.com/tklauser/go-sysconf v0.3.8 // indirect
github.com/tklauser/numcpus v0.2.3 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.26.0 // indirect
diff --git a/go.sum b/go.sum
index 560bd9c7..bcd4166f 100644
--- a/go.sum
+++ b/go.sum
@@ -388,8 +388,8 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
-github.com/tklauser/go-sysconf v0.3.7 h1:HT7h4+536gjqeq1ZIJPgOl1rg1XFatQGVZWp7Py53eg=
-github.com/tklauser/go-sysconf v0.3.7/go.mod h1:JZIdXh4RmBvZDBZ41ld2bGxRV3n4daiiqA3skYhAoQ4=
+github.com/tklauser/go-sysconf v0.3.8 h1:41Nq9J+pxKud4IQ830J5LlS5nl67dVQC7AuisUooaOU=
+github.com/tklauser/go-sysconf v0.3.8/go.mod h1:z4zYWRS+X53WUKtBcmDg1comV3fPhdQnzasnIHUoLDU=
github.com/tklauser/numcpus v0.2.3 h1:nQ0QYpiritP6ViFhrKYsiv6VVxOpum2Gks5GhnJbS/8=
github.com/tklauser/numcpus v0.2.3/go.mod h1:vpEPS/JC+oZGGQ/My/vJnNsvMDQL6PwOqt8dsCw5j+E=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
@@ -607,8 +607,8 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e h1:WUoyKPm6nCo1BnNUvPGnFG3T5DUVem42yDJZZ4CNxMA=
-golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20210816074244-15123e1e1f71 h1:ikCpsnYR+Ew0vu99XlDp55lGgDJdIMx3f4a18jfse/s=
+golang.org/x/sys v0.0.0-20210816074244-15123e1e1f71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
diff --git a/plugins/gzip/plugin.go b/plugins/gzip/plugin.go
index a957878c..05f1eb63 100644
--- a/plugins/gzip/plugin.go
+++ b/plugins/gzip/plugin.go
@@ -10,7 +10,6 @@ const PluginName = "gzip"
type Plugin struct{}
-// Init needed for the Endure
func (g *Plugin) Init() error {
return nil
}
diff --git a/plugins/reload/plugin.go b/plugins/reload/plugin.go
index d3271d6c..a9a5a63c 100644
--- a/plugins/reload/plugin.go
+++ b/plugins/reload/plugin.go
@@ -20,12 +20,12 @@ type Plugin struct {
log logger.Logger
watcher *Watcher
services map[string]interface{}
- res resetter.Resetter
+ res *resetter.Plugin
stopc chan struct{}
}
// Init controller service
-func (s *Plugin) Init(cfg config.Configurer, log logger.Logger, res resetter.Resetter) error {
+func (s *Plugin) Init(cfg config.Configurer, log logger.Logger, res *resetter.Plugin) error {
const op = errors.Op("reload_plugin_init")
if !cfg.Has(PluginName) {
return errors.E(op, errors.Disabled)
@@ -86,9 +86,9 @@ func (s *Plugin) Serve() chan error {
}
// make a map with unique services
- // so, if we would have a 100 events from http service
- // in map we would see only 1 key and it's config
- treshholdc := make(chan struct {
+ // so, if we would have 100 events from http service
+ // in map we would see only 1 key, and it's config
+ thCh := make(chan struct {
serviceConfig ServiceConfig
service string
}, thresholdChanBuffer)
@@ -98,7 +98,7 @@ func (s *Plugin) Serve() chan error {
go func() {
for e := range s.watcher.Event {
- treshholdc <- struct {
+ thCh <- struct {
serviceConfig ServiceConfig
service string
}{serviceConfig: s.cfg.Services[e.service], service: e.service}
@@ -111,7 +111,7 @@ func (s *Plugin) Serve() chan error {
go func() {
for {
select {
- case cfg := <-treshholdc:
+ case cfg := <-thCh:
// logic is following:
// restart
timer.Stop()
@@ -124,7 +124,7 @@ func (s *Plugin) Serve() chan error {
case <-timer.C:
if len(updated) > 0 {
for name := range updated {
- err := s.res.ResetByName(name)
+ err := s.res.Reset(name)
if err != nil {
timer.Stop()
errCh <- errors.E(op, err)
diff --git a/plugins/resetter/interface.go b/plugins/resetter/interface.go
index 47d8d791..0defcaba 100644
--- a/plugins/resetter/interface.go
+++ b/plugins/resetter/interface.go
@@ -1,17 +1,7 @@
package resetter
-// If plugin implements Resettable interface, than it state can be resetted without reload in runtime via RPC/HTTP
-type Resettable interface {
- // Reset reload all plugins
- Reset() error
-}
-
-// Resetter interface is the Resetter plugin main interface
+// Resetter interface
type Resetter interface {
- // Reset all registered plugins
- ResetAll() error
- // Reset by plugin name
- ResetByName(string) error
- // GetAll registered plugins
- GetAll() []string
+ // Reset reload plugin
+ Reset() error
}
diff --git a/plugins/resetter/plugin.go b/plugins/resetter/plugin.go
index 4feb692a..b2fe59af 100644
--- a/plugins/resetter/plugin.go
+++ b/plugins/resetter/plugin.go
@@ -3,61 +3,32 @@ package resetter
import (
endure "github.com/spiral/endure/pkg/container"
"github.com/spiral/errors"
- "github.com/spiral/roadrunner/v2/plugins/logger"
)
const PluginName = "resetter"
type Plugin struct {
- registry map[string]Resettable
- log logger.Logger
+ registry map[string]Resetter
}
-func (p *Plugin) ResetAll() error {
- const op = errors.Op("resetter_plugin_reset_all")
- for name := range p.registry {
- err := p.registry[name].Reset()
- if err != nil {
- return errors.E(op, err)
- }
- }
- return nil
-}
-
-func (p *Plugin) ResetByName(plugin string) error {
- const op = errors.Op("resetter_plugin_reset_by_name")
- if plugin, ok := p.registry[plugin]; ok {
- return plugin.Reset()
- }
- return errors.E(op, errors.Errorf("can't find plugin: %s", plugin))
-}
-
-func (p *Plugin) GetAll() []string {
- all := make([]string, 0, len(p.registry))
- for name := range p.registry {
- all = append(all, name)
- }
- return all
-}
-
-func (p *Plugin) Init(log logger.Logger) error {
- p.registry = make(map[string]Resettable)
- p.log = log
+func (p *Plugin) Init() error {
+ p.registry = make(map[string]Resetter)
return nil
}
// Reset named service.
func (p *Plugin) Reset(name string) error {
+ const op = errors.Op("resetter_plugin_reset_by_name")
svc, ok := p.registry[name]
if !ok {
- return errors.E("no such service", errors.Str(name))
+ return errors.E(op, errors.Errorf("no such service: %s", name))
}
return svc.Reset()
}
// RegisterTarget resettable service.
-func (p *Plugin) RegisterTarget(name endure.Named, r Resettable) error {
+func (p *Plugin) RegisterTarget(name endure.Named, r Resetter) error {
p.registry[name.Name()] = r
return nil
}
@@ -80,5 +51,5 @@ func (p *Plugin) Available() {
// RPC returns associated rpc service.
func (p *Plugin) RPC() interface{} {
- return &rpc{srv: p, log: p.log}
+ return &rpc{srv: p}
}
diff --git a/plugins/resetter/rpc.go b/plugins/resetter/rpc.go
index 69c955b0..79171b5c 100644
--- a/plugins/resetter/rpc.go
+++ b/plugins/resetter/rpc.go
@@ -1,30 +1,29 @@
package resetter
-import "github.com/spiral/roadrunner/v2/plugins/logger"
+import "github.com/spiral/errors"
type rpc struct {
srv *Plugin
- log logger.Logger
}
// List all resettable plugins.
func (rpc *rpc) List(_ bool, list *[]string) error {
- rpc.log.Debug("started List method")
*list = make([]string, 0)
for name := range rpc.srv.registry {
*list = append(*list, name)
}
- rpc.log.Debug("services list", "services", *list)
-
- rpc.log.Debug("finished List method")
return nil
}
// Reset named plugin.
func (rpc *rpc) Reset(service string, done *bool) error {
- rpc.log.Debug("started Reset method for the service", "service", service)
- defer rpc.log.Debug("finished Reset method for the service", "service", service)
+ const op = errors.Op("resetter_rpc_reset")
+ err := rpc.srv.Reset(service)
+ if err != nil {
+ *done = false
+ return errors.E(op, err)
+ }
*done = true
- return rpc.srv.Reset(service)
+ return nil
}
diff --git a/tests/plugins/resetter/resetter_test.go b/tests/plugins/resetter/resetter_test.go
index 465d22dd..10f38a9c 100644
--- a/tests/plugins/resetter/resetter_test.go
+++ b/tests/plugins/resetter/resetter_test.go
@@ -41,11 +41,6 @@ func TestResetterInit(t *testing.T) {
mockLogger.EXPECT().Error(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
- mockLogger.EXPECT().Debug("started List method").MinTimes(1)
- mockLogger.EXPECT().Debug("services list", "services", []string{"resetter.plugin1"}).MinTimes(1)
- mockLogger.EXPECT().Debug("finished List method").MinTimes(1)
- mockLogger.EXPECT().Debug("started Reset method for the service", "service", "resetter.plugin1").MinTimes(1)
- mockLogger.EXPECT().Debug("finished Reset method for the service", "service", "resetter.plugin1").MinTimes(1)
mockLogger.EXPECT().Warn("listener accept error, connection closed", "error", gomock.Any()).AnyTimes()
err = cont.RegisterAll(