mirror of
https://github.com/yusing/godoxy.git
synced 2026-01-11 22:30:47 +01:00
fix incorrect uptime history data
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user