From fa4cd10efe1fcb610e0bc74a58be07a07eaace49 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Fri, 3 Jul 2020 13:45:54 -0400 Subject: [PATCH] address PR comments --- node/node.go | 20 +++++++++----------- snow/engine/common/test_engine.go | 15 ++++++++++++--- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/node/node.go b/node/node.go index 49598a5..ea40c77 100644 --- a/node/node.go +++ b/node/node.go @@ -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) diff --git a/snow/engine/common/test_engine.go b/snow/engine/common/test_engine.go index 6e41dce..d64e479 100644 --- a/snow/engine/common/test_engine.go +++ b/snow/engine/common/test_engine.go @@ -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() }