summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2022-07-15 15:43:01 +0200
committerValery Piashchynski <[email protected]>2022-07-15 15:43:01 +0200
commit3dfd34d5d4b9f47dae203dd27af9fdba2de67960 (patch)
tree88539938a4a61faf0221379ac34754042adabadb /internal
parent5d598819f74a860b4f265fb6fde033da008d706e (diff)
- move container from the internal folder
- channel with the proper size Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'internal')
-rw-r--r--internal/cli/serve/command.go2
-rw-r--r--internal/container/config.go88
-rw-r--r--internal/container/config_test.go69
-rw-r--r--internal/container/container.go20
-rw-r--r--internal/container/container_test.go26
-rw-r--r--internal/container/plugins.go112
-rw-r--r--internal/container/plugins_test.go18
-rw-r--r--internal/container/test/endure_ok.yaml5
-rw-r--r--internal/container/test/endure_ok_debug.yaml5
-rw-r--r--internal/container/test/endure_ok_fatal.yaml5
-rw-r--r--internal/container/test/endure_ok_foobar.yaml5
-rw-r--r--internal/container/test/endure_ok_info.yaml5
-rw-r--r--internal/container/test/endure_ok_panic.yaml5
-rw-r--r--internal/container/test/endure_ok_warn.yaml5
-rw-r--r--internal/container/test/without_endure_ok.yaml0
15 files changed, 1 insertions, 369 deletions
diff --git a/internal/cli/serve/command.go b/internal/cli/serve/command.go
index 73b54c3c..a56fa819 100644
--- a/internal/cli/serve/command.go
+++ b/internal/cli/serve/command.go
@@ -6,7 +6,7 @@ import (
"os/signal"
"syscall"
- "github.com/roadrunner-server/roadrunner/v2/internal/container"
+ "github.com/roadrunner-server/roadrunner/v2/container"
"github.com/roadrunner-server/roadrunner/v2/internal/meta"
configImpl "github.com/roadrunner-server/config/v2"
diff --git a/internal/container/config.go b/internal/container/config.go
deleted file mode 100644
index fb5b028e..00000000
--- a/internal/container/config.go
+++ /dev/null
@@ -1,88 +0,0 @@
-package container
-
-import (
- "fmt"
- "time"
-
- endure "github.com/roadrunner-server/endure/pkg/container"
- "github.com/spf13/viper"
-)
-
-type Config struct {
- GracePeriod time.Duration
- PrintGraph bool
- LogLevel endure.Level
-}
-
-const (
- endureKey = "endure"
- defaultGracePeriod = time.Second * 30
-)
-
-// NewConfig creates endure container configuration.
-func NewConfig(cfgFile string) (*Config, error) {
- v := viper.New()
- v.SetConfigFile(cfgFile)
-
- err := v.ReadInConfig()
- if err != nil {
- return nil, err
- }
-
- if !v.IsSet(endureKey) {
- return &Config{ // return config with defaults
- GracePeriod: defaultGracePeriod,
- PrintGraph: false,
- LogLevel: endure.ErrorLevel,
- }, nil
- }
-
- rrCfgEndure := struct {
- GracePeriod time.Duration `mapstructure:"grace_period"`
- PrintGraph bool `mapstructure:"print_graph"`
- LogLevel string `mapstructure:"log_level"`
- }{}
-
- err = v.UnmarshalKey(endureKey, &rrCfgEndure)
- if err != nil {
- return nil, err
- }
-
- if rrCfgEndure.GracePeriod == 0 {
- rrCfgEndure.GracePeriod = defaultGracePeriod
- }
-
- if rrCfgEndure.LogLevel == "" {
- rrCfgEndure.LogLevel = "error"
- }
-
- logLevel, err := parseLogLevel(rrCfgEndure.LogLevel)
- if err != nil {
- return nil, err
- }
-
- return &Config{
- GracePeriod: rrCfgEndure.GracePeriod,
- PrintGraph: rrCfgEndure.PrintGraph,
- LogLevel: logLevel,
- }, nil
-}
-
-func parseLogLevel(s string) (endure.Level, error) {
- switch s {
- case "debug":
- return endure.DebugLevel, nil
- case "info":
- return endure.InfoLevel, nil
- case "warn", "warning":
- return endure.WarnLevel, nil
- case "error":
- return endure.ErrorLevel, nil
- case "panic":
- return endure.PanicLevel, nil
- case "fatal":
- return endure.FatalLevel, nil
- }
-
- return endure.DebugLevel, fmt.Errorf(`unknown log level "%s" (allowed: debug, info, warn, error, panic, fatal)`, s)
-}
diff --git a/internal/container/config_test.go b/internal/container/config_test.go
deleted file mode 100644
index ec07225a..00000000
--- a/internal/container/config_test.go
+++ /dev/null
@@ -1,69 +0,0 @@
-package container_test
-
-import (
- "testing"
- "time"
-
- "github.com/roadrunner-server/config/v2"
- endure "github.com/roadrunner-server/endure/pkg/container"
- "github.com/roadrunner-server/roadrunner/v2/internal/container"
- "github.com/stretchr/testify/assert"
-)
-
-func TestNewConfig_SuccessfulReading(t *testing.T) {
- c, err := container.NewConfig("test/endure_ok.yaml")
- assert.NoError(t, err)
- assert.NotNil(t, c)
-
- assert.Equal(t, time.Second*10, c.GracePeriod)
- assert.True(t, c.PrintGraph)
- assert.Equal(t, endure.WarnLevel, c.LogLevel)
-}
-
-func TestNewConfig_WithoutEndureKey(t *testing.T) {
- cfgPlugin := &config.Plugin{Type: "yaml", ReadInCfg: []byte{}}
- assert.NoError(t, cfgPlugin.Init())
-
- c, err := container.NewConfig("test/without_endure_ok.yaml")
- assert.NoError(t, err)
- assert.NotNil(t, c)
-
- assert.Equal(t, time.Second*30, c.GracePeriod)
- assert.False(t, c.PrintGraph)
- assert.Equal(t, endure.ErrorLevel, c.LogLevel)
-}
-
-func TestNewConfig_LoggingLevels(t *testing.T) {
- for _, tt := range []struct {
- path string
- giveLevel string
- wantLevel endure.Level
- wantError bool
- }{
- {path: "test/endure_ok_debug.yaml", giveLevel: "debug", wantLevel: endure.DebugLevel},
- {path: "test/endure_ok_info.yaml", giveLevel: "info", wantLevel: endure.InfoLevel},
- {path: "test/endure_ok_warn.yaml", giveLevel: "warn", wantLevel: endure.WarnLevel},
- {path: "test/endure_ok_panic.yaml", giveLevel: "panic", wantLevel: endure.PanicLevel},
- {path: "test/endure_ok_fatal.yaml", giveLevel: "fatal", wantLevel: endure.FatalLevel},
-
- {path: "test/endure_ok_foobar.yaml", giveLevel: "foobar", wantError: true},
- } {
- tt := tt
- t.Run(tt.giveLevel, func(t *testing.T) {
- cfgPlugin := &config.Plugin{Type: "yaml", ReadInCfg: []byte("endure:\n log_level: " + tt.giveLevel)}
- assert.NoError(t, cfgPlugin.Init())
-
- c, err := container.NewConfig(tt.path)
-
- if tt.wantError {
- assert.Nil(t, c)
- assert.Error(t, err)
- assert.Contains(t, err.Error(), "unknown log level")
- } else {
- assert.NoError(t, err)
- assert.NotNil(t, c)
- assert.Equal(t, tt.wantLevel, c.LogLevel)
- }
- })
- }
-}
diff --git a/internal/container/container.go b/internal/container/container.go
deleted file mode 100644
index 610fdbf9..00000000
--- a/internal/container/container.go
+++ /dev/null
@@ -1,20 +0,0 @@
-package container
-
-import (
- endure "github.com/roadrunner-server/endure/pkg/container"
-)
-
-// NewContainer creates endure container with all required options (based on container Config). Logger is nil by
-// default.
-func NewContainer(cfg Config) (*endure.Endure, error) {
- endureOptions := []endure.Options{
- endure.SetLogLevel(cfg.LogLevel),
- endure.GracefulShutdownTimeout(cfg.GracePeriod),
- }
-
- if cfg.PrintGraph {
- endureOptions = append(endureOptions, endure.Visualize(endure.StdOut, ""))
- }
-
- return endure.NewContainer(nil, endureOptions...)
-}
diff --git a/internal/container/container_test.go b/internal/container/container_test.go
deleted file mode 100644
index 210409d4..00000000
--- a/internal/container/container_test.go
+++ /dev/null
@@ -1,26 +0,0 @@
-package container_test
-
-import (
- "testing"
- "time"
-
- "github.com/roadrunner-server/roadrunner/v2/internal/container"
-
- endure "github.com/roadrunner-server/endure/pkg/container"
- "github.com/stretchr/testify/assert"
-)
-
-func TestNewContainer(t *testing.T) { // there is no legal way to test container options
- c, err := container.NewContainer(container.Config{})
- c2, err2 := container.NewContainer(container.Config{
- GracePeriod: time.Second,
- PrintGraph: true,
- LogLevel: endure.WarnLevel,
- })
-
- assert.NoError(t, err)
- assert.NotNil(t, c)
-
- assert.NoError(t, err2)
- assert.NotNil(t, c2)
-}
diff --git a/internal/container/plugins.go b/internal/container/plugins.go
deleted file mode 100644
index 3ee8cdc7..00000000
--- a/internal/container/plugins.go
+++ /dev/null
@@ -1,112 +0,0 @@
-package container
-
-import (
- "github.com/roadrunner-server/amqp/v2"
- "github.com/roadrunner-server/beanstalk/v2"
- "github.com/roadrunner-server/boltdb/v2"
- "github.com/roadrunner-server/broadcast/v2"
- "github.com/roadrunner-server/cache/v2"
- "github.com/roadrunner-server/fileserver/v2"
- grpcPlugin "github.com/roadrunner-server/grpc/v2"
- "github.com/roadrunner-server/gzip/v2"
- "github.com/roadrunner-server/headers/v2"
- httpPlugin "github.com/roadrunner-server/http/v2"
- "github.com/roadrunner-server/informer/v2"
- "github.com/roadrunner-server/jobs/v2"
- "github.com/roadrunner-server/logger/v2"
- "github.com/roadrunner-server/memory/v2"
- "github.com/roadrunner-server/metrics/v2"
- "github.com/roadrunner-server/nats/v2"
- newrelic "github.com/roadrunner-server/new_relic/v2"
- rrOtel "github.com/roadrunner-server/otel/v2"
- "github.com/roadrunner-server/prometheus/v2"
- proxyIP "github.com/roadrunner-server/proxy_ip_parser/v2"
- "github.com/roadrunner-server/redis/v2"
- "github.com/roadrunner-server/reload/v2"
- "github.com/roadrunner-server/resetter/v2"
- rpcPlugin "github.com/roadrunner-server/rpc/v2"
- "github.com/roadrunner-server/send/v2"
- "github.com/roadrunner-server/server/v2"
- "github.com/roadrunner-server/service/v2"
- "github.com/roadrunner-server/sqs/v2"
- "github.com/roadrunner-server/static/v2"
- "github.com/roadrunner-server/status/v2"
- "github.com/roadrunner-server/websockets/v2"
-
- "github.com/roadrunner-server/kv/v2"
- "github.com/roadrunner-server/memcached/v2"
- "github.com/roadrunner-server/tcp/v2"
- rrt "github.com/temporalio/roadrunner-temporal"
-)
-
-// Plugins returns active plugins for the endure container. Feel free to add or remove any plugins.
-func Plugins() []interface{} { //nolint:funlen
- return []interface{}{
- // bundled
- // informer plugin (./rr workers, ./rr workers -i)
- &informer.Plugin{},
- // resetter plugin (./rr reset)
- &resetter.Plugin{},
-
- // logger plugin
- &logger.Plugin{},
- // metrics plugin
- &metrics.Plugin{},
- // reload plugin
- &reload.Plugin{},
- // rpc plugin (workers, reset)
- &rpcPlugin.Plugin{},
- // server plugin (NewWorker, NewWorkerPool)
- &server.Plugin{},
- // service plugin
- &service.Plugin{},
-
- // ========= JOBS bundle
- &jobs.Plugin{},
- &amqp.Plugin{},
- &sqs.Plugin{},
- &nats.Plugin{},
- &beanstalk.Plugin{},
- // =========
-
- // http server plugin with middleware
- &httpPlugin.Plugin{},
- &newrelic.Plugin{},
- &static.Plugin{},
- &headers.Plugin{},
- &status.Plugin{},
- &gzip.Plugin{},
- &prometheus.Plugin{},
- &cache.Plugin{},
- &send.Plugin{},
- &proxyIP.Plugin{},
- &fileserver.Plugin{},
- &rrOtel.Plugin{},
- // ===================
-
- &grpcPlugin.Plugin{},
- // kv + ws + jobs plugin
- &memory.Plugin{},
- // KV + Jobs
- &boltdb.Plugin{},
-
- // broadcast via memory or redis
- // used in conjunction with Websockets, memory and redis plugins
- &broadcast.Plugin{},
- // ======== websockets broadcast bundle
- &websockets.Plugin{},
- &redis.Plugin{},
- // =========
-
- // ============== KV
- &kv.Plugin{},
- &memcached.Plugin{},
- // ==============
-
- // raw TCP connections handling
- &tcp.Plugin{},
-
- // temporal plugins
- &rrt.Plugin{},
- }
-}
diff --git a/internal/container/plugins_test.go b/internal/container/plugins_test.go
deleted file mode 100644
index b857f09a..00000000
--- a/internal/container/plugins_test.go
+++ /dev/null
@@ -1,18 +0,0 @@
-package container
-
-import (
- "reflect"
- "testing"
-)
-
-func TestPlugins(t *testing.T) {
- for _, p := range Plugins() {
- if p == nil {
- t.Error("plugin cannot be nil")
- }
-
- if pk := reflect.TypeOf(p).Kind(); pk != reflect.Ptr && pk != reflect.Struct {
- t.Errorf("plugin %v must be a structure or pointer to the structure", p)
- }
- }
-}
diff --git a/internal/container/test/endure_ok.yaml b/internal/container/test/endure_ok.yaml
deleted file mode 100644
index 03db7c23..00000000
--- a/internal/container/test/endure_ok.yaml
+++ /dev/null
@@ -1,5 +0,0 @@
-endure:
- grace_period: 10s
- print_graph: true
- retry_on_fail: true
- log_level: warn
diff --git a/internal/container/test/endure_ok_debug.yaml b/internal/container/test/endure_ok_debug.yaml
deleted file mode 100644
index 5953c4de..00000000
--- a/internal/container/test/endure_ok_debug.yaml
+++ /dev/null
@@ -1,5 +0,0 @@
-endure:
- grace_period: 10s
- print_graph: true
- retry_on_fail: true
- log_level: debug
diff --git a/internal/container/test/endure_ok_fatal.yaml b/internal/container/test/endure_ok_fatal.yaml
deleted file mode 100644
index 69e16467..00000000
--- a/internal/container/test/endure_ok_fatal.yaml
+++ /dev/null
@@ -1,5 +0,0 @@
-endure:
- grace_period: 10s
- print_graph: true
- retry_on_fail: true
- log_level: fatal
diff --git a/internal/container/test/endure_ok_foobar.yaml b/internal/container/test/endure_ok_foobar.yaml
deleted file mode 100644
index 90728d2c..00000000
--- a/internal/container/test/endure_ok_foobar.yaml
+++ /dev/null
@@ -1,5 +0,0 @@
-endure:
- grace_period: 10s
- print_graph: true
- retry_on_fail: true
- log_level: foobar
diff --git a/internal/container/test/endure_ok_info.yaml b/internal/container/test/endure_ok_info.yaml
deleted file mode 100644
index 7ad62861..00000000
--- a/internal/container/test/endure_ok_info.yaml
+++ /dev/null
@@ -1,5 +0,0 @@
-endure:
- grace_period: 10s
- print_graph: true
- retry_on_fail: true
- log_level: info
diff --git a/internal/container/test/endure_ok_panic.yaml b/internal/container/test/endure_ok_panic.yaml
deleted file mode 100644
index 5ac4dc9e..00000000
--- a/internal/container/test/endure_ok_panic.yaml
+++ /dev/null
@@ -1,5 +0,0 @@
-endure:
- grace_period: 10s
- print_graph: true
- retry_on_fail: true
- log_level: panic
diff --git a/internal/container/test/endure_ok_warn.yaml b/internal/container/test/endure_ok_warn.yaml
deleted file mode 100644
index 03db7c23..00000000
--- a/internal/container/test/endure_ok_warn.yaml
+++ /dev/null
@@ -1,5 +0,0 @@
-endure:
- grace_period: 10s
- print_graph: true
- retry_on_fail: true
- log_level: warn
diff --git a/internal/container/test/without_endure_ok.yaml b/internal/container/test/without_endure_ok.yaml
deleted file mode 100644
index e69de29b..00000000
--- a/internal/container/test/without_endure_ok.yaml
+++ /dev/null