mirror of
https://github.com/yusing/godoxy.git
synced 2025-06-05 19:22:34 +02:00
fix(healthcheck): handle cases for zero port
This commit is contained in:
parent
b411c6d504
commit
bdb3343a7c
1 changed files with 18 additions and 2 deletions
|
@ -31,6 +31,8 @@ type (
|
|||
checkHealth HealthCheckFunc
|
||||
startTime time.Time
|
||||
|
||||
isZeroPort bool
|
||||
|
||||
task *task.Task
|
||||
}
|
||||
)
|
||||
|
@ -63,14 +65,24 @@ func NewMonitor(r routes.Route) health.HealthMonCheck {
|
|||
return mon
|
||||
}
|
||||
|
||||
func newMonitor(url *url.URL, config *health.HealthCheckConfig, healthCheckFunc HealthCheckFunc) *monitor {
|
||||
func newMonitor(u *url.URL, config *health.HealthCheckConfig, healthCheckFunc HealthCheckFunc) *monitor {
|
||||
mon := &monitor{
|
||||
config: config,
|
||||
checkHealth: healthCheckFunc,
|
||||
startTime: time.Now(),
|
||||
}
|
||||
mon.url.Store(url)
|
||||
if u == nil {
|
||||
u = &url.URL{}
|
||||
}
|
||||
mon.url.Store(u)
|
||||
mon.status.Store(health.StatusHealthy)
|
||||
|
||||
port := u.Port()
|
||||
mon.isZeroPort = port == "" || port == "0"
|
||||
if mon.isZeroPort {
|
||||
mon.status.Store(health.StatusUnknown)
|
||||
mon.lastResult.Store(&health.HealthCheckResult{Healthy: false, Detail: "no port detected"})
|
||||
}
|
||||
return mon
|
||||
}
|
||||
|
||||
|
@ -87,6 +99,10 @@ func (mon *monitor) Start(parent task.Parent) gperr.Error {
|
|||
return ErrNegativeInterval
|
||||
}
|
||||
|
||||
if mon.isZeroPort {
|
||||
return nil
|
||||
}
|
||||
|
||||
mon.service = parent.Name()
|
||||
mon.task = parent.Subtask("health_monitor", true)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue