fixed healthcheck failed to disable and nil dereference

This commit is contained in:
yusing
2024-10-19 00:13:55 +08:00
parent 53557e38b6
commit b296fb2965
11 changed files with 60 additions and 20 deletions

View File

@@ -7,7 +7,7 @@ import (
)
type HealthCheckConfig struct {
Disabled bool `json:"disabled,omitempty" yaml:"disabled"`
Disable bool `json:"disable,omitempty" yaml:"disable"`
Path string `json:"path,omitempty" yaml:"path"`
UseGet bool `json:"use_get,omitempty" yaml:"use_get"`
Interval time.Duration `json:"interval" yaml:"interval"`

View File

@@ -75,20 +75,25 @@ func (mon *monitor) Start(routeSubtask task.Task) E.NestedError {
mon.service = routeSubtask.Parent().Name()
mon.task = routeSubtask
if err := mon.checkUpdateHealth(); err != nil {
mon.task.Finish(fmt.Sprintf("healthchecker %s failure: %s", mon.service, err))
return err
if mon.config.Interval <= 0 {
return E.Invalid("interval", mon.config.Interval)
}
go func() {
defer func() {
monMap.Delete(mon.task.Name())
if mon.status.Load() != StatusError {
mon.status.Store(StatusUnknown)
}
mon.task.Finish(mon.task.FinishCause().Error())
}()
if err := mon.checkUpdateHealth(); err != nil {
logger.Errorf("healthchecker %s failure: %s", mon.service, err)
return
}
monMap.Store(mon.service, mon)
defer monMap.Delete(mon.service)
ticker := time.NewTicker(mon.config.Interval)
defer ticker.Stop()