diff options
-rw-r--r-- | service/health/service.go | 25 | ||||
-rw-r--r-- | service/metrics/service.go | 28 |
2 files changed, 38 insertions, 15 deletions
diff --git a/service/health/service.go b/service/health/service.go index c82f43b5..ce127340 100644 --- a/service/health/service.go +++ b/service/health/service.go @@ -6,12 +6,17 @@ import ( "github.com/sirupsen/logrus" "net/http" "sync" + "time" rrhttp "github.com/spiral/roadrunner/service/http" ) -// ID declares the public service name -const ID = "health" +const ( + // ID declares public service name. + ID = "health" + // maxHeaderSize declares max header size for prometheus server + maxHeaderSize = 1024 * 1024 * 100 // 104MB +) // Service to serve an endpoint for checking the health of the worker pool type Service struct { @@ -39,15 +44,23 @@ func (s *Service) Init(cfg *Config, r *rrhttp.Service, log *logrus.Logger) (bool func (s *Service) Serve() error { // Configure and start the http server s.mu.Lock() - s.http = &http.Server{Addr: s.cfg.Address, Handler: s} + s.http = &http.Server{ + Addr: s.cfg.Address, + Handler: s, + IdleTimeout: time.Hour * 24, + ReadTimeout: time.Minute * 60, + MaxHeaderBytes: maxHeaderSize, + ReadHeaderTimeout: time.Minute * 60, + WriteTimeout: time.Minute * 60, + } s.mu.Unlock() err := s.http.ListenAndServe() - if err == nil || err == http.ErrServerClosed { - return nil + if err != nil && err != http.ErrServerClosed { + return err } - return err + return nil } // Stop the health endpoint diff --git a/service/metrics/service.go b/service/metrics/service.go index 6fa4da50..0b667f2d 100644 --- a/service/metrics/service.go +++ b/service/metrics/service.go @@ -11,10 +11,15 @@ import ( "github.com/spiral/roadrunner/service/rpc" "net/http" "sync" + "time" ) -// ID declares public service name. -const ID = "metrics" +const ( + // ID declares public service name. + ID = "metrics" + // maxHeaderSize declares max header size for prometheus server + maxHeaderSize = 1024 * 1024 * 100 // 104MB +) // Service to manage application metrics using Prometheus. type Service struct { @@ -76,18 +81,23 @@ func (s *Service) Serve() error { } s.mu.Lock() - s.http = &http.Server{Addr: s.cfg.Address, Handler: promhttp.HandlerFor( - s.registry, - promhttp.HandlerOpts{}, - )} + s.http = &http.Server{ + Addr: s.cfg.Address, + Handler: promhttp.HandlerFor(s.registry, promhttp.HandlerOpts{}, ), + IdleTimeout: time.Hour * 24, + ReadTimeout: time.Minute * 60, + MaxHeaderBytes: maxHeaderSize, + ReadHeaderTimeout: time.Minute * 60, + WriteTimeout: time.Minute * 60, + } s.mu.Unlock() err = s.http.ListenAndServe() - if err == nil || err == http.ErrServerClosed { - return nil + if err != nil && err != http.ErrServerClosed { + return err } - return err + return nil } // Stop prometheus metrics service. |