diff --git a/pkg/services/private/server/healthcheck.go b/pkg/services/private/server/healthcheck.go index daf41aa5..9d0c266e 100644 --- a/pkg/services/private/server/healthcheck.go +++ b/pkg/services/private/server/healthcheck.go @@ -23,8 +23,7 @@ func (s *Server) HealthCheck(_ context.Context, req *private.HealthCheckRequest) body := new(private.HealthCheckResponse_Body) resp.SetBody(body) - // FIXME: calculate the status - body.SetStatus(private.HealthStatus_ONLINE) + body.SetStatus(s.healthChecker.HealthStatus()) // sign the response if err := SignMessage(s.key, resp); err != nil { diff --git a/pkg/services/private/server/server.go b/pkg/services/private/server/server.go index 02722672..e6263d0d 100644 --- a/pkg/services/private/server/server.go +++ b/pkg/services/private/server/server.go @@ -2,6 +2,8 @@ package private import ( "crypto/ecdsa" + + "github.com/nspcc-dev/neofs-node/pkg/services/private" ) // Server is an entity that serves @@ -10,6 +12,16 @@ type Server struct { *cfg } +// HealthChecker is component interface for calculating +// the current health status of a node. +type HealthChecker interface { + // Must calculate and return current node health status. + // + // If status can not be calculated for any reason, + // private.HealthStatus_STATUS_UNDEFINED should be returned. + HealthStatus() private.HealthStatus +} + // Option of the Server's constructor. type Option func(*cfg) @@ -17,6 +29,8 @@ type cfg struct { key *ecdsa.PrivateKey allowedKeys [][]byte + + healthChecker HealthChecker } func defaultCfg() *cfg { @@ -51,3 +65,11 @@ func WithAllowedKeys(keys [][]byte) Option { c.allowedKeys = append(c.allowedKeys, keys...) } } + +// WithHealthChecker returns option to set component +// to calculate node health status. +func WithHealthChecker(hc HealthChecker) Option { + return func(c *cfg) { + c.healthChecker = hc + } +}