mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 12:42:34 +02:00
fix incorrect uptime history data
This commit is contained in:
parent
9f54f40f5a
commit
964e94b3ba
2 changed files with 22 additions and 12 deletions
|
@ -17,7 +17,7 @@ import (
|
|||
|
||||
type (
|
||||
StatusByAlias struct {
|
||||
Map map[string]health.WithHealthInfo
|
||||
Map map[string]map[string]any
|
||||
Timestamp time.Time
|
||||
}
|
||||
Status struct {
|
||||
|
@ -36,10 +36,9 @@ func init() {
|
|||
}
|
||||
|
||||
func getStatuses(ctx context.Context, _ *StatusByAlias) (*StatusByAlias, error) {
|
||||
now := time.Now()
|
||||
return &StatusByAlias{
|
||||
Map: routequery.HealthInfo(),
|
||||
Timestamp: now,
|
||||
Timestamp: time.Now(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -52,8 +51,8 @@ func aggregateStatuses(entries []*StatusByAlias, query url.Values) (int, Aggrega
|
|||
for _, entry := range entries {
|
||||
for alias, status := range entry.Map {
|
||||
statuses[alias] = append(statuses[alias], &Status{
|
||||
Status: status.Status(),
|
||||
Latency: status.Latency(),
|
||||
Status: status["status"].(health.Status),
|
||||
Latency: status["latency"].(time.Duration),
|
||||
Timestamp: entry.Timestamp,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -29,21 +29,32 @@ func getHealthInfo(r route.Route) map[string]string {
|
|||
}
|
||||
}
|
||||
|
||||
func getHealthInfoRaw(r route.Route) map[string]any {
|
||||
mon := r.HealthMonitor()
|
||||
if mon == nil {
|
||||
return map[string]any{
|
||||
"status": health.StatusUnknown,
|
||||
"latency": time.Duration(0),
|
||||
}
|
||||
}
|
||||
return map[string]any{
|
||||
"status": mon.Status(),
|
||||
"latency": mon.Latency(),
|
||||
}
|
||||
}
|
||||
|
||||
func HealthMap() map[string]map[string]string {
|
||||
healthMap := make(map[string]map[string]string)
|
||||
healthMap := make(map[string]map[string]string, routes.NumRoutes())
|
||||
routes.RangeRoutes(func(alias string, r route.Route) {
|
||||
healthMap[alias] = getHealthInfo(r)
|
||||
})
|
||||
return healthMap
|
||||
}
|
||||
|
||||
func HealthInfo() map[string]health.WithHealthInfo {
|
||||
healthMap := make(map[string]health.WithHealthInfo, routes.NumRoutes())
|
||||
func HealthInfo() map[string]map[string]any {
|
||||
healthMap := make(map[string]map[string]any, routes.NumRoutes())
|
||||
routes.RangeRoutes(func(alias string, r route.Route) {
|
||||
mon := r.HealthMonitor()
|
||||
if mon != nil {
|
||||
healthMap[alias] = mon
|
||||
}
|
||||
healthMap[alias] = getHealthInfoRaw(r)
|
||||
})
|
||||
return healthMap
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue