add admin diagnostics readiness and event metrics
This commit is contained in:
+14
-20
@@ -3,10 +3,10 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"orchestra/internal/admin"
|
||||
"orchestra/internal/authz"
|
||||
"orchestra/internal/delivery"
|
||||
"orchestra/internal/domain"
|
||||
@@ -253,17 +253,18 @@ func main() {
|
||||
}
|
||||
json.NewEncoder(w).Encode(out)
|
||||
})
|
||||
mux.HandleFunc("/metrics", func(w http.ResponseWriter, r *http.Request) {
|
||||
tasks := s.Tasks()
|
||||
counts := map[domain.TaskState]int{}
|
||||
for _, t := range tasks {
|
||||
counts[t.State]++
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/plain; version=0.0.4")
|
||||
for _, state := range []domain.TaskState{domain.StateQueued, domain.StateLeased, domain.StateCompleted, domain.StateFailed, domain.StateBlocked} {
|
||||
fmt.Fprintf(w, "orchestra_tasks{state=\"%s\"} %d\n", state, counts[state])
|
||||
}
|
||||
})
|
||||
adminServer := &admin.Server{Store: s, RouterReady: rt != nil, Providers: providerHealth, Probes: map[string]admin.ProbeFunc{
|
||||
"router": func() (bool, string) { return rt != nil, "configured router" },
|
||||
"gitea": func() (bool, string) {
|
||||
return os.Getenv("ORCHESTRA_GITEA_URL") == "" || providerHealth["gitea"] != nil, "configured provider"
|
||||
},
|
||||
"jsonl": func() (bool, string) {
|
||||
return os.Getenv("ORCHESTRA_JSONL") == "" || providerHealth["jsonl"] != nil, "configured provider"
|
||||
},
|
||||
}}
|
||||
mux.HandleFunc("/metrics", adminServer.Metrics)
|
||||
mux.HandleFunc("/v1/events/subscribe", adminServer.Subscribe)
|
||||
mux.HandleFunc("/v1/admin/diagnostics", adminServer.Diagnostics)
|
||||
mux.HandleFunc("/v1/tasks/", func(w http.ResponseWriter, r *http.Request) {
|
||||
parts := strings.Split(strings.Trim(r.URL.Path, "/"), "/")
|
||||
if len(parts) < 4 || len(parts) > 5 || r.Method != "POST" {
|
||||
@@ -407,14 +408,7 @@ func main() {
|
||||
}()
|
||||
}
|
||||
mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("ok\n")) })
|
||||
mux.HandleFunc("/readyz", func(w http.ResponseWriter, r *http.Request) {
|
||||
checks := map[string]any{"store": true, "router": rt != nil, "gitea": os.Getenv("ORCHESTRA_GITEA_URL") != "", "jsonl": os.Getenv("ORCHESTRA_JSONL") != ""}
|
||||
ready := rt != nil || (os.Getenv("ORCHESTRA_CONFIG") == "")
|
||||
if !ready {
|
||||
w.WriteHeader(http.StatusServiceUnavailable)
|
||||
}
|
||||
json.NewEncoder(w).Encode(map[string]any{"ready": ready, "checks": checks})
|
||||
})
|
||||
mux.HandleFunc("/readyz", adminServer.Readiness)
|
||||
mux.HandleFunc("/v1/providers/health", func(w http.ResponseWriter, r *http.Request) {
|
||||
out := map[string]provider.Health{}
|
||||
for name, sup := range providerHealth {
|
||||
|
||||
Reference in New Issue
Block a user