diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/gzip/plugin.go | 8 | ||||
-rw-r--r-- | plugins/http/plugin.go | 17 | ||||
-rw-r--r-- | plugins/static/plugin.go | 3 | ||||
-rw-r--r-- | plugins/status/config.go (renamed from plugins/checker/config.go) | 2 | ||||
-rw-r--r-- | plugins/status/interface.go (renamed from plugins/checker/interface.go) | 2 | ||||
-rw-r--r-- | plugins/status/plugin.go (renamed from plugins/checker/plugin.go) | 15 | ||||
-rw-r--r-- | plugins/status/rpc.go (renamed from plugins/checker/rpc.go) | 2 |
7 files changed, 21 insertions, 28 deletions
diff --git a/plugins/gzip/plugin.go b/plugins/gzip/plugin.go index eee6c1d3..949c6888 100644 --- a/plugins/gzip/plugin.go +++ b/plugins/gzip/plugin.go @@ -8,19 +8,19 @@ import ( const PluginName = "gzip" -type Gzip struct{} +type Plugin struct{} // needed for the Endure -func (g *Gzip) Init() error { +func (g *Plugin) Init() error { return nil } -func (g *Gzip) Middleware(next http.Handler) http.HandlerFunc { +func (g *Plugin) Middleware(next http.Handler) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { gziphandler.GzipHandler(next).ServeHTTP(w, r) } } -func (g *Gzip) Name() string { +func (g *Plugin) Name() string { return PluginName } diff --git a/plugins/http/plugin.go b/plugins/http/plugin.go index bab03edc..d9903d65 100644 --- a/plugins/http/plugin.go +++ b/plugins/http/plugin.go @@ -17,12 +17,12 @@ import ( "github.com/spiral/errors" "github.com/spiral/roadrunner/v2/pkg/pool" "github.com/spiral/roadrunner/v2/pkg/worker" - "github.com/spiral/roadrunner/v2/plugins/checker" "github.com/spiral/roadrunner/v2/plugins/config" "github.com/spiral/roadrunner/v2/plugins/http/attributes" httpConfig "github.com/spiral/roadrunner/v2/plugins/http/config" "github.com/spiral/roadrunner/v2/plugins/logger" "github.com/spiral/roadrunner/v2/plugins/server" + "github.com/spiral/roadrunner/v2/plugins/status" "github.com/spiral/roadrunner/v2/utils" "golang.org/x/net/http2" "golang.org/x/net/http2/h2c" @@ -109,12 +109,9 @@ func (s *Plugin) Init(cfg config.Configurer, log logger.Logger, server server.Se func (s *Plugin) logCallback(event interface{}) { if ev, ok := event.(ResponseEvent); ok { - s.log.Debug("", + s.log.Debug(fmt.Sprintf("%d %s %s", ev.Response.Status, ev.Request.Method, ev.Request.URI), "remote", ev.Request.RemoteAddr, - "ts", ev.Elapsed().String(), - "resp.status", ev.Response.Status, - "method", ev.Request.Method, - "uri", ev.Request.URI, + "elapsed", ev.Elapsed().String(), ) } } @@ -303,8 +300,6 @@ func (s *Plugin) ServeHTTP(w http.ResponseWriter, r *http.Request) { // Workers returns associated pool workers func (s *Plugin) Workers() []worker.BaseProcess { - s.Lock() - defer s.Unlock() return s.pool.Workers() } @@ -365,17 +360,17 @@ func (s *Plugin) AddMiddleware(name endure.Named, m Middleware) { } // Status return status of the particular plugin -func (s *Plugin) Status() checker.Status { +func (s *Plugin) Status() status.Status { workers := s.Workers() for i := 0; i < len(workers); i++ { if workers[i].State().IsActive() { - return checker.Status{ + return status.Status{ Code: http.StatusOK, } } } // if there are no workers, threat this as error - return checker.Status{ + return status.Status{ Code: http.StatusInternalServerError, } } diff --git a/plugins/static/plugin.go b/plugins/static/plugin.go index 1687cf11..5f108701 100644 --- a/plugins/static/plugin.go +++ b/plugins/static/plugin.go @@ -47,7 +47,7 @@ func (s *Plugin) Init(cfg config.Configurer, log logger.Logger) error { err = s.cfg.Valid() if err != nil { - return errors.E(op, errors.Disabled, err) + return errors.E(op, err) } return nil @@ -88,7 +88,6 @@ func (s *Plugin) handleStatic(w http.ResponseWriter, r *http.Request) bool { f, err := s.root.Open(fPath) if err != nil { - s.log.Error("file open error", "error", err) if s.cfg.AlwaysServe(fPath) { w.WriteHeader(404) return true diff --git a/plugins/checker/config.go b/plugins/status/config.go index 5f952592..23a6ede2 100644 --- a/plugins/checker/config.go +++ b/plugins/status/config.go @@ -1,4 +1,4 @@ -package checker +package status type Config struct { Address string diff --git a/plugins/checker/interface.go b/plugins/status/interface.go index dd9dcada..0a92bc52 100644 --- a/plugins/checker/interface.go +++ b/plugins/status/interface.go @@ -1,4 +1,4 @@ -package checker +package status // Status consists of status code from the service type Status struct { diff --git a/plugins/checker/plugin.go b/plugins/status/plugin.go index 59a37613..6fbe67cf 100644 --- a/plugins/checker/plugin.go +++ b/plugins/status/plugin.go @@ -1,4 +1,4 @@ -package checker +package status import ( "fmt" @@ -6,7 +6,6 @@ import ( "time" "github.com/gofiber/fiber/v2" - fiberLogger "github.com/gofiber/fiber/v2/middleware/logger" endure "github.com/spiral/endure/pkg/container" "github.com/spiral/errors" "github.com/spiral/roadrunner/v2/plugins/config" @@ -43,12 +42,12 @@ func (c *Plugin) Init(log logger.Logger, cfg config.Configurer) error { func (c *Plugin) Serve() chan error { errCh := make(chan error, 1) c.server = fiber.New(fiber.Config{ - ReadTimeout: time.Second * 5, - WriteTimeout: time.Second * 5, - IdleTimeout: time.Second * 5, + ReadTimeout: time.Second * 5, + WriteTimeout: time.Second * 5, + IdleTimeout: time.Second * 5, + DisableStartupMessage: true, }) - c.server.Group("/v1", c.healthHandler) - c.server.Use(fiberLogger.New()) + c.server.Use("/health", c.healthHandler) go func() { @@ -120,7 +119,7 @@ func (c *Plugin) healthHandler(ctx *fiber.Ctx) error { if len(plugins.Plugins) == 0 { ctx.Status(http.StatusOK) - _, _ = ctx.WriteString("No plugins provided in query. Query should be in form of: /v1/health?plugin=plugin1&plugin=plugin2 \n") + _, _ = ctx.WriteString("No plugins provided in query. Query should be in form of: health?plugin=plugin1&plugin=plugin2 \n") return nil } diff --git a/plugins/checker/rpc.go b/plugins/status/rpc.go index a965dcd4..396ff451 100644 --- a/plugins/checker/rpc.go +++ b/plugins/status/rpc.go @@ -1,4 +1,4 @@ -package checker +package status import ( "github.com/spiral/errors" |