address PR comments

This commit is contained in:
Dan Laine 2020-07-03 13:45:54 -04:00
parent d92420d4f4
commit fa4cd10efe
2 changed files with 21 additions and 14 deletions

View File

@ -461,18 +461,16 @@ func (n *Node) initKeystoreAPI() error {
// initMetricsAPI initializes the Metrics API
// Assumes n.APIServer is already set
func (n *Node) initMetricsAPI() error {
n.Log.Info("initializing metrics")
registry, handler := metrics.NewService()
if n.Config.MetricsAPIEnabled {
n.Log.Info("initializing metrics API")
if err := n.APIServer.AddRoute(handler, &sync.RWMutex{}, "metrics", "", n.HTTPLog); err != nil {
return err
}
} else {
n.Log.Info("skipping metrics API initialization because it has been disabled")
}
// It is assumed by components of the system that the Metrics interface is
// non-nil. So, it is set regardless of if the metrics API is available or not.
n.Config.ConsensusParams.Metrics = registry
return nil
if !n.Config.MetricsAPIEnabled {
n.Log.Info("skipping metrics API initialization because it has been disabled")
return nil
}
n.Log.Info("initializing metrics API")
return n.APIServer.AddRoute(handler, &sync.RWMutex{}, "metrics", "", n.HTTPLog)
}
// initAdminAPI initializes the Admin API service
@ -529,7 +527,7 @@ func (n *Node) initHealthAPI() error {
return nil, nil
}
// Passes if the P, X and C chains are finished bootstrapping
if err := service.RegisterMonotonicCheckFunc("defaultChainsBootstrapped", isBootstrappedFunc); err != nil {
if err := service.RegisterMonotonicCheckFunc("chains.default.bootstrapped", isBootstrappedFunc); err != nil {
return err
}
return n.APIServer.AddRoute(service.Handler(), &sync.RWMutex{}, "health", "", n.HTTPLog)

View File

@ -15,7 +15,7 @@ import (
type EngineTest struct {
T *testing.T
Bootstrapped,
CantIsBootstrapped,
CantStartup,
CantGossip,
CantShutdown,
@ -44,6 +44,7 @@ type EngineTest struct {
CantQueryFailed,
CantChits bool
IsBootstrappedF func() bool
ContextF func() *snow.Context
StartupF, GossipF, ShutdownF func() error
NotifyF func(Message) error
@ -59,7 +60,7 @@ var _ Engine = &EngineTest{}
// Default ...
func (e *EngineTest) Default(cant bool) {
e.Bootstrapped = cant
e.CantIsBootstrapped = cant
e.CantStartup = cant
e.CantGossip = cant
@ -360,5 +361,13 @@ func (e *EngineTest) Chits(validatorID ids.ShortID, requestID uint32, containerI
// IsBootstrapped ...
func (e *EngineTest) IsBootstrapped() bool {
return e.Bootstrapped
if e.IsBootstrappedF != nil {
return e.IsBootstrappedF()
} else if e.CantIsBootstrapped {
if e.T != nil {
e.T.Fatalf("Unexpectedly called IsBootstrapped")
}
panic("Unexpectedly called IsBootstrapped")
}
return e.IsBootstrappedF()
}