Skip to content
This repository was archived by the owner on Jul 19, 2023. It is now read-only.

Commit 7d20115

Browse files
authored
When ready check fails display names (#675)
Currently the health check under `/ready` will only show the count of services in a particular state, this will make sure we will display the state and the services names.
1 parent 9b4b1a7 commit 7d20115

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

pkg/phlare/phlare.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"io"
1010
"net/http"
1111
"os"
12+
"sort"
1213

1314
"github.com/bufbuild/connect-go"
1415
"github.com/go-kit/log"
@@ -24,6 +25,7 @@ import (
2425
"github.com/prometheus/client_golang/prometheus"
2526
commonconfig "github.com/prometheus/common/config"
2627
"github.com/prometheus/common/version"
28+
"github.com/samber/lo"
2729
"github.com/weaveworks/common/logging"
2830
"github.com/weaveworks/common/server"
2931
"github.com/weaveworks/common/signals"
@@ -413,9 +415,18 @@ func (f *Phlare) readyHandler(sm *services.Manager) http.HandlerFunc {
413415
msg := bytes.Buffer{}
414416
msg.WriteString("Some services are not Running:\n")
415417

416-
byState := sm.ServicesByState()
417-
for st, ls := range byState {
418-
msg.WriteString(fmt.Sprintf("%v: %d\n", st, len(ls)))
418+
byState := map[services.State][]string{}
419+
for name, svc := range f.serviceMap {
420+
state := svc.State()
421+
byState[state] = append(byState[state], name)
422+
}
423+
424+
states := lo.Keys(byState)
425+
sort.Slice(states, func(i, j int) bool { return states[i] < states[j] })
426+
427+
for _, st := range states {
428+
sort.Strings(byState[st])
429+
msg.WriteString(fmt.Sprintf("%v: %v\n", st, byState[st]))
419430
}
420431

421432
http.Error(w, msg.String(), http.StatusServiceUnavailable)

0 commit comments

Comments
 (0)