mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-19 20:32:35 +02:00
feat(health): add health check detail to health api
This commit is contained in:
parent
4df31263b5
commit
b090598b68
5 changed files with 33 additions and 0 deletions
|
@ -65,6 +65,21 @@ func (w *Watcher) Status() health.Status {
|
|||
return health.StatusNapping
|
||||
}
|
||||
|
||||
// Detail implements health.HealthMonitor.
|
||||
func (w *Watcher) Detail() string {
|
||||
state := w.state.Load()
|
||||
if state.err != nil {
|
||||
return state.err.Error()
|
||||
}
|
||||
if !state.ready {
|
||||
return "not ready"
|
||||
}
|
||||
if state.status == idlewatcher.ContainerStatusRunning {
|
||||
return "starting"
|
||||
}
|
||||
return "napping"
|
||||
}
|
||||
|
||||
func checkUpdateState(key string) (w *Watcher, ready bool, err error) {
|
||||
watcherMapMu.RLock()
|
||||
w, ok := watcherMap[key]
|
||||
|
|
|
@ -266,6 +266,12 @@ func (lb *LoadBalancer) Status() health.Status {
|
|||
return status
|
||||
}
|
||||
|
||||
// Detail implements health.HealthMonitor.
|
||||
func (lb *LoadBalancer) Detail() string {
|
||||
_, numHealthy := lb.status()
|
||||
return fmt.Sprintf("%d/%d servers are healthy", numHealthy, lb.pool.Size())
|
||||
}
|
||||
|
||||
func (lb *LoadBalancer) status() (status health.Status, numHealthy int) {
|
||||
if lb.pool.Size() == 0 {
|
||||
return health.StatusUnknown, 0
|
||||
|
|
|
@ -16,12 +16,14 @@ func getHealthInfo(r Route) map[string]string {
|
|||
"status": "unknown",
|
||||
"uptime": "n/a",
|
||||
"latency": "n/a",
|
||||
"detail": "n/a",
|
||||
}
|
||||
}
|
||||
return map[string]string{
|
||||
"status": mon.Status().String(),
|
||||
"uptime": mon.Uptime().Round(time.Second).String(),
|
||||
"latency": mon.Latency().Round(time.Microsecond).String(),
|
||||
"detail": mon.Detail(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -168,6 +168,15 @@ func (mon *monitor) Latency() time.Duration {
|
|||
return res.Latency
|
||||
}
|
||||
|
||||
// Detail implements HealthMonitor.
|
||||
func (mon *monitor) Detail() string {
|
||||
res := mon.lastResult.Load()
|
||||
if res == nil {
|
||||
return ""
|
||||
}
|
||||
return res.Detail
|
||||
}
|
||||
|
||||
// Name implements HealthMonitor.
|
||||
func (mon *monitor) Name() string {
|
||||
parts := strutils.SplitRune(mon.service, '/')
|
||||
|
|
|
@ -19,6 +19,7 @@ type (
|
|||
Status() Status
|
||||
Uptime() time.Duration
|
||||
Latency() time.Duration
|
||||
Detail() string
|
||||
}
|
||||
HealthMonitor interface {
|
||||
task.TaskStarter
|
||||
|
|
Loading…
Add table
Reference in a new issue