fix(webui): list services with the State Store marked down when it is unreachable

This commit is contained in:
sam committed 2026-10-06 00:48:45 +11:00
1 parent d427671fc5
commit 2e579663c1
4 files changed
+29 -16

No files matched your search

+17
View File
@@ -89,6 +89,9 @@ const (
StateUp = "up"
StateDegraded = "degraded"
StateDown = "down"
// StateUnknown is a service whose record cannot be read because the
// State Store holding it is unreachable.
StateUnknown = "unknown"
)
// Service is one expected service as the mesh view shows it: its newest
@@ -123,6 +126,20 @@ func Mesh(records []storecontract.Presence, now time.Time) []Service {
return services
}
// Unreachable is the mesh view when the State Store cannot be read: the store
// is down and every other service is unknown, since its record lives there.
func Unreachable() []Service {
services := make([]Service, 0, len(Services()))
for _, name := range Services() {
service := Service{Presence: storecontract.Presence{Service: name}, State: StateUnknown}
if name == StateStore {
service.State, service.Detail = StateDown, "unreachable"
}
services = append(services, service)
}
return services
}
func state(record storecontract.Presence, reported bool, now time.Time) string {
switch {
case !reported || Stale(record.ReportedAt, now):
+7 -11
View File
@@ -12,23 +12,19 @@ type serviceView struct {
}
// handleServices lists every expected service with its presence and the
// control-plane resource versions it applied.
// control-plane resource versions it applied. Both live in the State Store, so
// when it cannot be read the list still answers, naming the store as down.
func (s *Server) handleServices(w http.ResponseWriter, r *http.Request) {
if s.Presence == nil {
http.Error(w, "presence unavailable", http.StatusServiceUnavailable)
return
}
records, err := s.Presence.ListPresence(r.Context())
if err != nil {
http.Error(w, "presence unavailable", http.StatusServiceUnavailable)
return
mesh := presence.Unreachable()
if records, err := s.Presence.ListPresence(r.Context()); err == nil {
mesh = presence.Mesh(records, s.clock())
}
applied, err := s.readApplyStatus(r.Context())
if err != nil {
http.Error(w, "apply status unavailable", http.StatusServiceUnavailable)
return
}
mesh := presence.Mesh(records, s.clock())
// Apply status is decoration on the list; without it the list still stands.
applied, _ := s.readApplyStatus(r.Context())
out := make([]serviceView, 0, len(mesh))
for _, service := range mesh {
view := serviceView{Service: service, Applied: []applyStatusRecord{}}