[#306] private: Define and use HealthChecker interface to get the status
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
e8bd2eac0d
commit
44a0fb5a69
2 changed files with 23 additions and 2 deletions
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue