add health module with component probing and controller implementation
This commit is contained in:
commit
7dc291e222
6 files changed
+289
No files matched your search
@@ -0,0 +1,51 @@
|
||||
package health
|
||||
|
||||
import "context"
|
||||
|
||||
type Controller interface {
|
||||
ProbeAll(ctx context.Context) ([]*ControllerComponentStatus, error)
|
||||
}
|
||||
|
||||
type ControllerComponentStatus struct {
|
||||
IsHealthy bool `json:"is_healthy"`
|
||||
IsReady bool `json:"is_ready"`
|
||||
|
||||
Message string `json:"message"`
|
||||
URL string `json:"url"`
|
||||
Additional map[string]string `json:"additional"`
|
||||
Error error
|
||||
}
|
||||
|
||||
type controllerImpl struct {
|
||||
components []ProbableComponent
|
||||
}
|
||||
|
||||
func (c *controllerImpl) ProbeAll(ctx context.Context) ([]*ControllerComponentStatus, error) {
|
||||
result := make([]*ControllerComponentStatus, len(c.components))
|
||||
for i, p := range c.components {
|
||||
status, err := p.Probe(ctx)
|
||||
if err != nil {
|
||||
result[i] = &ControllerComponentStatus{
|
||||
IsHealthy: false,
|
||||
IsReady: false,
|
||||
|
||||
Message: err.Error(),
|
||||
Error: err,
|
||||
}
|
||||
} else {
|
||||
result[i] = &ControllerComponentStatus{
|
||||
IsHealthy: status.IsHealthy,
|
||||
IsReady: status.IsReady,
|
||||
Message: status.Message,
|
||||
URL: status.URL,
|
||||
Additional: status.Additional,
|
||||
Error: status.Error,
|
||||
}
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func NewControllerFor(components ...ProbableComponent) Controller {
|
||||
return &controllerImpl{components: components}
|
||||
}
|
||||
Reference in new issue
Block a user