Skip to content

Commit

Permalink
Force metrics enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
iknite committed Feb 19, 2019
1 parent dd2ead7 commit f9bd2de
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 30 deletions.
5 changes: 1 addition & 4 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func newStartCommand(ctx *cmdContext) *cobra.Command {
conf.APIKey = ctx.apiKey
conf.NodeID = v.GetString("server.node-id")
conf.EnableProfiling = v.GetBool("server.profiling")
conf.EnableMetrics = v.GetBool("server.metrics")
conf.PrivateKeyPath, _ = homedir.Expand(v.GetString("server.key"))
conf.SSLCertificate, _ = homedir.Expand(v.GetString("server.tls.certificate"))
conf.SSLCertificateKey, _ = homedir.Expand(v.GetString("server.tls.certificate_key"))
Expand Down Expand Up @@ -86,15 +85,14 @@ func newStartCommand(ctx *cmdContext) *cobra.Command {
hostname, _ := os.Hostname()
f.StringVar(&conf.NodeID, "node-id", hostname, "Unique name for node. If not set, fallback to hostname")
f.BoolVarP(&conf.EnableProfiling, "profiling", "f", false, "Allow a pprof url (localhost:6060) for profiling purposes")
f.BoolVarP(&conf.EnableMetrics, "metrics", "m", false, "Allow export metrics through --metrics-addr (default localhost:8600)")
f.StringVar(&conf.PrivateKeyPath, "keypath", fmt.Sprintf("%s/%s", ctx.path, "id_ed25519"), "Server Singning private key file path")
f.StringVar(&conf.SSLCertificate, "certificate", fmt.Sprintf("%s/%s", ctx.path, "server.crt"), "Server crt file")
f.StringVar(&conf.SSLCertificateKey, "certificate-key", fmt.Sprintf("%s/%s", ctx.path, "server.key"), "Server key file")

f.StringVar(&conf.HTTPAddr, "http-addr", ":8800", "Endpoint for REST requests on (host:port)")
f.StringVar(&conf.RaftAddr, "raft-addr", ":8500", "Raft bind address (host:port)")
f.StringVar(&conf.MgmtAddr, "mgmt-addr", ":8700", "Management endpoint bind address (host:port)")
f.StringVar(&conf.MgmtAddr, "metrics-addr", ":8600", "Metrics export bind address (host:port)")
f.StringVar(&conf.MetricsAddr, "metrics-addr", ":8600", "Metrics export bind address (host:port)")
f.StringSliceVar(&conf.RaftJoinAddr, "join-addr", []string{}, "Raft: Comma-delimited list of nodes ([host]:port), through which a cluster can be joined")
f.StringVar(&conf.GossipAddr, "gossip-addr", ":8400", "Gossip: management endpoint bind address (host:port)")
f.StringSliceVar(&conf.GossipJoinAddr, "gossip-join-addr", []string{}, "Gossip: Comma-delimited list of nodes ([host]:port), through which a cluster can be joined")
Expand All @@ -106,7 +104,6 @@ func newStartCommand(ctx *cmdContext) *cobra.Command {
// Lookups
v.BindPFlag("server.node-id", f.Lookup("node-id"))
v.BindPFlag("server.profiling", f.Lookup("profiling"))
v.BindPFlag("server.metrics", f.Lookup("metrics"))
v.BindPFlag("server.key", f.Lookup("keypath"))
v.BindPFlag("server.tls.certificate", f.Lookup("certificate"))
v.BindPFlag("server.tls.certificate_key", f.Lookup("certificate-key"))
Expand Down
4 changes: 0 additions & 4 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ type Config struct {
// Enables tampering endpoint.
EnableTampering bool

// Enables metrics endpoint.
EnableMetrics bool

// Enable TLS service
EnableTLS bool

Expand Down Expand Up @@ -99,7 +96,6 @@ func DefaultConfig() *Config {
RaftPath: currentDir + "/wal",
EnableProfiling: false,
EnableTampering: false,
EnableMetrics: false,
EnableTLS: false,
SSLCertificate: "",
SSLCertificateKey: "",
Expand Down
38 changes: 16 additions & 22 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,12 @@ func NewServer(conf *Config) (*Server, error) {
server.profilingServer = newHTTPServer("localhost:6060", nil)
}

if conf.EnableMetrics {
r := prometheus.NewRegistry()
metrics.Register(r)
server.prometheusRegistry = r
metricsMux := metricshttp.NewMetricsHTTP(r)
r := prometheus.NewRegistry()
metrics.Register(r)
server.prometheusRegistry = r
metricsMux := metricshttp.NewMetricsHTTP(r)

server.metricsServer = newHTTPServer(conf.MetricsAddr, metricsMux)
}
server.metricsServer = newHTTPServer(conf.MetricsAddr, metricsMux)

return server, nil
}
Expand Down Expand Up @@ -209,14 +207,12 @@ func (s *Server) Start() error {
return err
}

if s.conf.EnableMetrics {
go func() {
log.Debugf(" * Starting metrics HTTP server in addr: %s", s.conf.MetricsAddr)
if err := s.metricsServer.ListenAndServe(); err != http.ErrServerClosed {
log.Errorf("Can't start metrics HTTP server: %s", err)
}
}()
}
go func() {
log.Debugf(" * Starting metrics HTTP server in addr: %s", s.conf.MetricsAddr)
if err := s.metricsServer.ListenAndServe(); err != http.ErrServerClosed {
log.Errorf("Can't start metrics HTTP server: %s", err)
}
}()

if s.profilingServer != nil {
go func() {
Expand Down Expand Up @@ -291,14 +287,12 @@ func (s *Server) Start() error {
func (s *Server) Stop() error {
fmt.Printf("\nShutting down QED server %s", s.conf.NodeID)

if s.conf.EnableMetrics {
log.Debugf("Metrics enabled: stopping server...")
if err := s.metricsServer.Shutdown(context.Background()); err != nil { // TODO include timeout instead nil
log.Error(err)
return err
}
log.Debugf("Done.\n")
log.Debugf("Metrics enabled: stopping server...")
if err := s.metricsServer.Shutdown(context.Background()); err != nil { // TODO include timeout instead nil
log.Error(err)
return err
}
log.Debugf("Done.\n")

if s.tamperingServer != nil {
log.Debugf("Tampering enabled: stopping server...")
Expand Down

0 comments on commit f9bd2de

Please sign in to comment.