Skip to content

Commit

Permalink
Add a prometheus registry to the Server struct
Browse files Browse the repository at this point in the history
This way the Server can be shut down leaving no state behind. We need this in
tests, when Servers are created and shut down repeatedly.
  • Loading branch information
panchoh authored and iknite committed Feb 19, 2019
1 parent 76d1d4d commit a649f2f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
5 changes: 3 additions & 2 deletions api/metricshttp/metricshttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package metricshttp
import (
"net/http"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)

func NewMetricsHttp() *http.ServeMux {
func NewMetricsHTTP(r *prometheus.Registry) *http.ServeMux {
mux := http.NewServeMux()
mux.Handle("/metrics", promhttp.Handler())
mux.Handle("/metrics", promhttp.HandlerFor(r, promhttp.HandlerOpts{}))
return mux
}
25 changes: 14 additions & 11 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,25 @@ import (
"github.com/bbva/qed/sign"
"github.com/bbva/qed/storage/badger"
"github.com/bbva/qed/util"
"github.com/prometheus/client_golang/prometheus"
)

// Server encapsulates the data and login to start/stop a QED server
type Server struct {
conf *Config
bootstrap bool // Set bootstrap to true when bringing up the first node as a master

httpServer *http.Server
mgmtServer *http.Server
raftBalloon *raftwal.RaftBalloon
tamperingServer *http.Server
profilingServer *http.Server
metricsServer *http.Server
signer sign.Signer
sender *sender.Sender
agent *gossip.Agent
agentsQueue chan *protocol.Snapshot
httpServer *http.Server
mgmtServer *http.Server
raftBalloon *raftwal.RaftBalloon
tamperingServer *http.Server
profilingServer *http.Server
metricsServer *http.Server
prometheusRegistry *prometheus.Registry
signer sign.Signer
sender *sender.Sender
agent *gossip.Agent
agentsQueue chan *protocol.Snapshot
}

func serverInfo(conf *Config) http.HandlerFunc {
Expand Down Expand Up @@ -167,7 +169,8 @@ func NewServer(conf *Config) (*Server, error) {
server.profilingServer = newHTTPServer("localhost:6060", nil)
}
if conf.EnableMetrics {
metricsMux := metricshttp.NewMetricsHttp()
server.prometheusRegistry = prometheus.NewRegistry()
metricsMux := metricshttp.NewMetricsHTTP(server.prometheusRegistry)
server.metricsServer = newHTTPServer("localhost:9990", metricsMux)
}

Expand Down

0 comments on commit a649f2f

Please sign in to comment.