forked from TrueCloudLab/frostfs-node
[#306] cmd/node: Switch health status on boot and shutdown
Implement HealthChecker on node app structure. Set health status to ONLINE after node boot. Set health status to OFFLINE on shutdown. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
44a0fb5a69
commit
df3746fa68
4 changed files with 20 additions and 0 deletions
|
@ -28,6 +28,7 @@ import (
|
|||
nmwrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/network"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/private"
|
||||
tokenStorage "github.com/nspcc-dev/neofs-node/pkg/services/session/storage"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/util/response"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||
|
@ -35,6 +36,7 @@ import (
|
|||
"github.com/panjf2000/ants/v2"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/viper"
|
||||
"go.uber.org/atomic"
|
||||
"go.uber.org/zap"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
@ -181,6 +183,8 @@ type cfg struct {
|
|||
respSvc *response.Service
|
||||
|
||||
cfgPrivateService cfgPrivateService
|
||||
|
||||
healthStatus *atomic.Int32
|
||||
}
|
||||
|
||||
type cfgGRPC struct {
|
||||
|
@ -338,6 +342,7 @@ func initCfg(path string) *cfg {
|
|||
cfgObject: cfgObject{
|
||||
pool: initObjectPool(viperCfg),
|
||||
},
|
||||
healthStatus: atomic.NewInt32(int32(private.HealthStatus_STATUS_UNDEFINED)),
|
||||
}
|
||||
|
||||
initLocalStorage(c)
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"flag"
|
||||
"log"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/private"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/util/grace"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
@ -54,6 +55,8 @@ func bootUp(c *cfg) {
|
|||
serveGRPC(c)
|
||||
bootstrapNode(c)
|
||||
startWorkers(c)
|
||||
|
||||
c.setHealthStatus(private.HealthStatus_ONLINE)
|
||||
}
|
||||
|
||||
func wait(c *cfg) {
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
netmapEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
|
||||
netmapTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/netmap/grpc"
|
||||
netmapService "github.com/nspcc-dev/neofs-node/pkg/services/netmap"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/private"
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/atomic"
|
||||
"go.uber.org/zap"
|
||||
|
@ -116,6 +117,8 @@ func addNewEpochNotificationHandler(c *cfg, h event.Handler) {
|
|||
}
|
||||
|
||||
func goOffline(c *cfg) {
|
||||
c.setHealthStatus(private.HealthStatus_OFFLINE)
|
||||
|
||||
err := c.cfgNetmap.wrapper.UpdatePeerState(
|
||||
crypto.MarshalPublicKey(&c.key.PublicKey),
|
||||
netmap.NodeStateOffline,
|
||||
|
|
|
@ -41,6 +41,7 @@ func initPrivateService(c *cfg) {
|
|||
privSvc := privateSvc.New(
|
||||
privateSvc.WithKey(c.key),
|
||||
privateSvc.WithAllowedKeys(keys),
|
||||
privateSvc.WithHealthChecker(c),
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -65,3 +66,11 @@ func initPrivateService(c *cfg) {
|
|||
fatalOnErr(c.cfgPrivateService.server.Serve(lis))
|
||||
}))
|
||||
}
|
||||
|
||||
func (c *cfg) setHealthStatus(st private.HealthStatus) {
|
||||
c.healthStatus.Store(int32(st))
|
||||
}
|
||||
|
||||
func (c *cfg) HealthStatus() private.HealthStatus {
|
||||
return private.HealthStatus(c.healthStatus.Load())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue