[#306] private: Define and use HealthChecker interface to get the status

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-01-13 16:34:59 +03:00 committed by Alex Vanin
parent e8bd2eac0d
commit 44a0fb5a69
2 changed files with 23 additions and 2 deletions

View file

@ -23,8 +23,7 @@ func (s *Server) HealthCheck(_ context.Context, req *private.HealthCheckRequest)
body := new(private.HealthCheckResponse_Body) body := new(private.HealthCheckResponse_Body)
resp.SetBody(body) resp.SetBody(body)
// FIXME: calculate the status body.SetStatus(s.healthChecker.HealthStatus())
body.SetStatus(private.HealthStatus_ONLINE)
// sign the response // sign the response
if err := SignMessage(s.key, resp); err != nil { if err := SignMessage(s.key, resp); err != nil {

View file

@ -2,6 +2,8 @@ package private
import ( import (
"crypto/ecdsa" "crypto/ecdsa"
"github.com/nspcc-dev/neofs-node/pkg/services/private"
) )
// Server is an entity that serves // Server is an entity that serves
@ -10,6 +12,16 @@ type Server struct {
*cfg *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. // Option of the Server's constructor.
type Option func(*cfg) type Option func(*cfg)
@ -17,6 +29,8 @@ type cfg struct {
key *ecdsa.PrivateKey key *ecdsa.PrivateKey
allowedKeys [][]byte allowedKeys [][]byte
healthChecker HealthChecker
} }
func defaultCfg() *cfg { func defaultCfg() *cfg {
@ -51,3 +65,11 @@ func WithAllowedKeys(keys [][]byte) Option {
c.allowedKeys = append(c.allowedKeys, keys...) 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
}
}