diff --git a/internal/metrics/uptime/uptime.go b/internal/metrics/uptime/uptime.go index e8cbbae..cf5c083 100644 --- a/internal/metrics/uptime/uptime.go +++ b/internal/metrics/uptime/uptime.go @@ -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, }) } diff --git a/internal/route/routes/routequery/query.go b/internal/route/routes/routequery/query.go index 5a0140e..ff4114c 100644 --- a/internal/route/routes/routequery/query.go +++ b/internal/route/routes/routequery/query.go @@ -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 }