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
2cec88d3ce
commit
c55c6c84bc
5 changed files with 33 additions and 0 deletions
|
@ -65,6 +65,21 @@ func (w *Watcher) Status() health.Status {
|
||||||
return health.StatusNapping
|
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) {
|
func checkUpdateState(key string) (w *Watcher, ready bool, err error) {
|
||||||
watcherMapMu.RLock()
|
watcherMapMu.RLock()
|
||||||
w, ok := watcherMap[key]
|
w, ok := watcherMap[key]
|
||||||
|
|
|
@ -266,6 +266,12 @@ func (lb *LoadBalancer) Status() health.Status {
|
||||||
return 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) {
|
func (lb *LoadBalancer) status() (status health.Status, numHealthy int) {
|
||||||
if lb.pool.Size() == 0 {
|
if lb.pool.Size() == 0 {
|
||||||
return health.StatusUnknown, 0
|
return health.StatusUnknown, 0
|
||||||
|
|
|
@ -16,12 +16,14 @@ func getHealthInfo(r Route) map[string]string {
|
||||||
"status": "unknown",
|
"status": "unknown",
|
||||||
"uptime": "n/a",
|
"uptime": "n/a",
|
||||||
"latency": "n/a",
|
"latency": "n/a",
|
||||||
|
"detail": "n/a",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return map[string]string{
|
return map[string]string{
|
||||||
"status": mon.Status().String(),
|
"status": mon.Status().String(),
|
||||||
"uptime": mon.Uptime().Round(time.Second).String(),
|
"uptime": mon.Uptime().Round(time.Second).String(),
|
||||||
"latency": mon.Latency().Round(time.Microsecond).String(),
|
"latency": mon.Latency().Round(time.Microsecond).String(),
|
||||||
|
"detail": mon.Detail(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -168,6 +168,15 @@ func (mon *monitor) Latency() time.Duration {
|
||||||
return res.Latency
|
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.
|
// Name implements HealthMonitor.
|
||||||
func (mon *monitor) Name() string {
|
func (mon *monitor) Name() string {
|
||||||
parts := strutils.SplitRune(mon.service, '/')
|
parts := strutils.SplitRune(mon.service, '/')
|
||||||
|
|
|
@ -19,6 +19,7 @@ type (
|
||||||
Status() Status
|
Status() Status
|
||||||
Uptime() time.Duration
|
Uptime() time.Duration
|
||||||
Latency() time.Duration
|
Latency() time.Duration
|
||||||
|
Detail() string
|
||||||
}
|
}
|
||||||
HealthMonitor interface {
|
HealthMonitor interface {
|
||||||
task.TaskStarter
|
task.TaskStarter
|
||||||
|
|
Loading…
Add table
Reference in a new issue