fix: expose ai health component errors

This commit is contained in:
Grendgi
2026-06-17 16:35:47 +03:00
parent 22d85ce646
commit aad905c2c8

View File

@@ -17,10 +17,10 @@ type healthDetailResponse struct {
} }
type healthComponent struct { type healthComponent struct {
Name string `json:"name"` Name string `json:"name"`
Status string `json:"status"` Status string `json:"status"`
Message string `json:"message,omitempty"` Error string `json:"error,omitempty"`
Data map[string]any `json:"data,omitempty"` Data map[string]any `json:"data,omitempty"`
} }
func (s *Server) handleHealthDetail(w http.ResponseWriter, r *http.Request) { func (s *Server) handleHealthDetail(w http.ResponseWriter, r *http.Request) {
@@ -34,9 +34,9 @@ func (s *Server) handleHealthDetail(w http.ResponseWriter, r *http.Request) {
if err := s.store.Ping(ctx); err != nil { if err := s.store.Ping(ctx); err != nil {
resp.Components = append(resp.Components, healthComponent{ resp.Components = append(resp.Components, healthComponent{
Name: "postgres", Name: "postgres",
Status: "down", Status: "down",
Message: err.Error(), Error: err.Error(),
}) })
resp.Status = worseHealthStatus(resp.Status, "down") resp.Status = worseHealthStatus(resp.Status, "down")
writeJSON(w, http.StatusServiceUnavailable, resp) writeJSON(w, http.StatusServiceUnavailable, resp)
@@ -47,9 +47,9 @@ func (s *Server) handleHealthDetail(w http.ResponseWriter, r *http.Request) {
stats, err := s.store.Stats(ctx, s.cfg.WorkerLeaseTimeout) stats, err := s.store.Stats(ctx, s.cfg.WorkerLeaseTimeout)
if err != nil { if err != nil {
resp.Components = append(resp.Components, healthComponent{ resp.Components = append(resp.Components, healthComponent{
Name: "queue", Name: "queue",
Status: "down", Status: "down",
Message: err.Error(), Error: err.Error(),
}) })
resp.Status = worseHealthStatus(resp.Status, "down") resp.Status = worseHealthStatus(resp.Status, "down")
writeJSON(w, http.StatusServiceUnavailable, resp) writeJSON(w, http.StatusServiceUnavailable, resp)
@@ -101,9 +101,9 @@ func (s *Server) healthProviders(ctx context.Context) healthComponent {
} }
} }
return healthComponent{ return healthComponent{
Name: "providers", Name: "providers",
Status: status, Status: status,
Message: strings.Join(messages, "; "), Error: strings.Join(messages, "; "),
Data: map[string]any{ Data: map[string]any{
"providers": providers, "providers": providers,
}, },
@@ -131,9 +131,9 @@ func healthQueue(stats *model.Stats) healthComponent {
message = "there are stale running jobs" message = "there are stale running jobs"
} }
return healthComponent{ return healthComponent{
Name: "queue", Name: "queue",
Status: status, Status: status,
Message: message, Error: message,
Data: map[string]any{ Data: map[string]any{
"pending": pending, "pending": pending,
"running": running, "running": running,
@@ -160,9 +160,9 @@ func healthErrors(stats *model.Stats) healthComponent {
message = "there are failed jobs in the last 24 hours" message = "there are failed jobs in the last 24 hours"
} }
return healthComponent{ return healthComponent{
Name: "errors", Name: "errors",
Status: status, Status: status,
Message: message, Error: message,
Data: map[string]any{ Data: map[string]any{
"failed_total": failedTotal, "failed_total": failedTotal,
"failed_24h": failed24h, "failed_24h": failed24h,
@@ -201,9 +201,9 @@ func healthThroughput(stats *model.Stats) healthComponent {
message = "some active queues have no completed jobs in the last 24 hours" message = "some active queues have no completed jobs in the last 24 hours"
} }
return healthComponent{ return healthComponent{
Name: "throughput", Name: "throughput",
Status: status, Status: status,
Message: message, Error: message,
Data: map[string]any{ Data: map[string]any{
"done_24h": done24h, "done_24h": done24h,
"retried_24h": retried24h, "retried_24h": retried24h,
@@ -221,9 +221,9 @@ func healthInfra(infra infraStatusResponse) healthComponent {
message = infra.SidecarError message = infra.SidecarError
} }
return healthComponent{ return healthComponent{
Name: "infra", Name: "infra",
Status: status, Status: status,
Message: message, Error: message,
Data: map[string]any{ Data: map[string]any{
"sidecar": infra.Sidecar, "sidecar": infra.Sidecar,
}, },