diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index 27bdef53d9..16f8e99e1e 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -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) diff --git a/cmd/neofs-node/main.go b/cmd/neofs-node/main.go index 394ef514b4..b75048bbec 100644 --- a/cmd/neofs-node/main.go +++ b/cmd/neofs-node/main.go @@ -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) { diff --git a/cmd/neofs-node/netmap.go b/cmd/neofs-node/netmap.go index 2942dc7c8a..592d689182 100644 --- a/cmd/neofs-node/netmap.go +++ b/cmd/neofs-node/netmap.go @@ -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, diff --git a/cmd/neofs-node/private.go b/cmd/neofs-node/private.go index 5d6ec82da7..4b647f2ce9 100644 --- a/cmd/neofs-node/private.go +++ b/cmd/neofs-node/private.go @@ -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()) +}