summaryrefslogtreecommitdiff
path: root/service/metrics/service.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2019-12-23 14:43:47 +0300
committerWolfy-J <[email protected]>2019-12-23 14:43:47 +0300
commitc7b0a4a81827284f7565c56aa476eea34fb6382f (patch)
treeee30e93169c37fb058fbe55af6b3f954eabd9646 /service/metrics/service.go
parent7f694966730f6dac09d0d0ea3bf51276b8e4dfe4 (diff)
- test fixes
Diffstat (limited to 'service/metrics/service.go')
-rw-r--r--service/metrics/service.go21
1 files changed, 18 insertions, 3 deletions
diff --git a/service/metrics/service.go b/service/metrics/service.go
index b581f041..6fa4da50 100644
--- a/service/metrics/service.go
+++ b/service/metrics/service.go
@@ -4,8 +4,10 @@ package metrics
import (
"context"
+ "fmt"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
+ "github.com/sirupsen/logrus"
"github.com/spiral/roadrunner/service/rpc"
"net/http"
"sync"
@@ -17,6 +19,7 @@ const ID = "metrics"
// Service to manage application metrics using Prometheus.
type Service struct {
cfg *Config
+ log *logrus.Logger
mu sync.Mutex
http *http.Server
collectors sync.Map
@@ -24,8 +27,9 @@ type Service struct {
}
// Init service.
-func (s *Service) Init(cfg *Config, r *rpc.Service) (bool, error) {
+func (s *Service) Init(cfg *Config, r *rpc.Service, log *logrus.Logger) (bool, error) {
s.cfg = cfg
+ s.log = log
s.registry = prometheus.NewRegistry()
s.registry.MustRegister(prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{}))
@@ -78,7 +82,12 @@ func (s *Service) Serve() error {
)}
s.mu.Unlock()
- return s.http.ListenAndServe()
+ err = s.http.ListenAndServe()
+ if err == nil || err == http.ErrServerClosed {
+ return nil
+ }
+
+ return err
}
// Stop prometheus metrics service.
@@ -88,7 +97,13 @@ func (s *Service) Stop() {
if s.http != nil {
// gracefully stop server
- go s.http.Shutdown(context.Background())
+ go func() {
+ err := s.http.Shutdown(context.Background())
+ if err != nil {
+ // Function should be Stop() error
+ s.log.Error(fmt.Errorf("error shutting down the metrics server: error %v", err))
+ }
+ }()
}
}