diff options
author | Valery Piashchynski <[email protected]> | 2023-01-06 13:49:04 +0100 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2023-01-06 13:49:04 +0100 |
commit | 3bb4d3a497b609557e884ec29a94c204dfac86a2 (patch) | |
tree | 79efa8e3a9fdb626462a5236265c298f36f77e2e /container | |
parent | f6bc8835dc4d996992b6d4a2751ac10dc6138e4f (diff) |
Initial support for the endure v2 container
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'container')
-rw-r--r-- | container/config.go | 22 | ||||
-rw-r--r-- | container/config_test.go | 17 | ||||
-rw-r--r-- | container/container.go | 20 | ||||
-rw-r--r-- | container/container_test.go | 14 | ||||
-rw-r--r-- | container/plugins.go | 8 |
5 files changed, 25 insertions, 56 deletions
diff --git a/container/config.go b/container/config.go index fb5b028e..09efde04 100644 --- a/container/config.go +++ b/container/config.go @@ -4,14 +4,14 @@ import ( "fmt" "time" - endure "github.com/roadrunner-server/endure/pkg/container" "github.com/spf13/viper" + "golang.org/x/exp/slog" ) type Config struct { GracePeriod time.Duration PrintGraph bool - LogLevel endure.Level + LogLevel slog.Leveler } const ( @@ -33,7 +33,7 @@ func NewConfig(cfgFile string) (*Config, error) { return &Config{ // return config with defaults GracePeriod: defaultGracePeriod, PrintGraph: false, - LogLevel: endure.ErrorLevel, + LogLevel: slog.LevelError, }, nil } @@ -68,21 +68,17 @@ func NewConfig(cfgFile string) (*Config, error) { }, nil } -func parseLogLevel(s string) (endure.Level, error) { +func parseLogLevel(s string) (slog.Leveler, error) { switch s { case "debug": - return endure.DebugLevel, nil + return slog.LevelDebug, nil case "info": - return endure.InfoLevel, nil + return slog.LevelInfo, nil case "warn", "warning": - return endure.WarnLevel, nil + return slog.LevelWarn, nil case "error": - return endure.ErrorLevel, nil - case "panic": - return endure.PanicLevel, nil - case "fatal": - return endure.FatalLevel, nil + return slog.LevelError, nil } - return endure.DebugLevel, fmt.Errorf(`unknown log level "%s" (allowed: debug, info, warn, error, panic, fatal)`, s) + return slog.LevelInfo, fmt.Errorf(`unknown log level "%s" (allowed: debug, info, warn, error, panic, fatal)`, s) } diff --git a/container/config_test.go b/container/config_test.go index 018bb60f..e3bdf0d6 100644 --- a/container/config_test.go +++ b/container/config_test.go @@ -5,9 +5,9 @@ import ( "time" "github.com/roadrunner-server/config/v3" - endure "github.com/roadrunner-server/endure/pkg/container" "github.com/roadrunner-server/roadrunner/v2/container" "github.com/stretchr/testify/assert" + "golang.org/x/exp/slog" ) func TestNewConfig_SuccessfulReading(t *testing.T) { @@ -17,7 +17,7 @@ func TestNewConfig_SuccessfulReading(t *testing.T) { assert.Equal(t, time.Second*10, c.GracePeriod) assert.True(t, c.PrintGraph) - assert.Equal(t, endure.WarnLevel, c.LogLevel) + assert.Equal(t, slog.LevelWarn, c.LogLevel) } func TestNewConfig_WithoutEndureKey(t *testing.T) { @@ -30,21 +30,20 @@ func TestNewConfig_WithoutEndureKey(t *testing.T) { assert.Equal(t, time.Second*30, c.GracePeriod) assert.False(t, c.PrintGraph) - assert.Equal(t, endure.ErrorLevel, c.LogLevel) + assert.Equal(t, slog.LevelError, c.LogLevel) } func TestNewConfig_LoggingLevels(t *testing.T) { for _, tt := range []struct { path string giveLevel string - wantLevel endure.Level + wantLevel slog.Leveler 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_debug.yaml", giveLevel: "debug", wantLevel: slog.LevelDebug}, + {path: "test/endure_ok_info.yaml", giveLevel: "info", wantLevel: slog.LevelInfo}, + {path: "test/endure_ok_warn.yaml", giveLevel: "warn", wantLevel: slog.LevelWarn}, + {path: "test/endure_ok_error.yaml", giveLevel: "error", wantLevel: slog.LevelError}, {path: "test/endure_ok_foobar.yaml", giveLevel: "foobar", wantError: true}, } { diff --git a/container/container.go b/container/container.go deleted file mode 100644 index 610fdbf9..00000000 --- a/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/container/container_test.go b/container/container_test.go index ed080d38..a1d68e6b 100644 --- a/container/container_test.go +++ b/container/container_test.go @@ -4,22 +4,16 @@ import ( "testing" "time" - endure "github.com/roadrunner-server/endure/pkg/container" - "github.com/roadrunner-server/roadrunner/v2/container" + "github.com/roadrunner-server/endure/v2" "github.com/stretchr/testify/assert" + "golang.org/x/exp/slog" ) 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, - }) + c := endure.New(slog.LevelDebug, endure.Visualize(), endure.GracefulShutdownTimeout(time.Second)) + c2 := endure.New(slog.LevelDebug, endure.Visualize(), endure.GracefulShutdownTimeout(time.Second)) - assert.NoError(t, err) assert.NotNil(t, c) - assert.NoError(t, err2) assert.NotNil(t, c2) } diff --git a/container/plugins.go b/container/plugins.go index 22d90b7f..442a0134 100644 --- a/container/plugins.go +++ b/container/plugins.go @@ -1,7 +1,7 @@ package container import ( - cache "github.com/darkweak/souin/plugins/roadrunner" + //cache "github.com/darkweak/souin/plugins/roadrunner" "github.com/roadrunner-server/amqp/v3" appLogger "github.com/roadrunner-server/app-logger/v3" "github.com/roadrunner-server/beanstalk/v3" @@ -14,7 +14,7 @@ import ( httpPlugin "github.com/roadrunner-server/http/v3" "github.com/roadrunner-server/informer/v3" "github.com/roadrunner-server/jobs/v3" - "github.com/roadrunner-server/kafka/v3" + //"github.com/roadrunner-server/kafka/v3" "github.com/roadrunner-server/kv/v3" "github.com/roadrunner-server/logger/v3" "github.com/roadrunner-server/memcached/v3" @@ -71,7 +71,7 @@ func Plugins() []any { //nolint:funlen &nats.Plugin{}, &beanstalk.Plugin{}, // new in 2.11 - &kafka.Plugin{}, + //&kafka.Plugin{}, // ========= // // http server plugin with middleware @@ -103,6 +103,6 @@ func Plugins() []any { //nolint:funlen // temporal plugin &rrt.Plugin{}, // third-party-- - &cache.Plugin{}, + //&cache.Plugin{}, } } |