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 {
Name string `json:"name"`
Status string `json:"status"`
Message string `json:"message,omitempty"`
Data map[string]any `json:"data,omitempty"`
Name string `json:"name"`
Status string `json:"status"`
Error string `json:"error,omitempty"`
Data map[string]any `json:"data,omitempty"`
}
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 {
resp.Components = append(resp.Components, healthComponent{
Name: "postgres",
Status: "down",
Message: err.Error(),
Name: "postgres",
Status: "down",
Error: err.Error(),
})
resp.Status = worseHealthStatus(resp.Status, "down")
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)
if err != nil {
resp.Components = append(resp.Components, healthComponent{
Name: "queue",
Status: "down",
Message: err.Error(),
Name: "queue",
Status: "down",
Error: err.Error(),
})
resp.Status = worseHealthStatus(resp.Status, "down")
writeJSON(w, http.StatusServiceUnavailable, resp)
@@ -101,9 +101,9 @@ func (s *Server) healthProviders(ctx context.Context) healthComponent {
}
}
return healthComponent{
Name: "providers",
Status: status,
Message: strings.Join(messages, "; "),
Name: "providers",
Status: status,
Error: strings.Join(messages, "; "),
Data: map[string]any{
"providers": providers,
},
@@ -131,9 +131,9 @@ func healthQueue(stats *model.Stats) healthComponent {
message = "there are stale running jobs"
}
return healthComponent{
Name: "queue",
Status: status,
Message: message,
Name: "queue",
Status: status,
Error: message,
Data: map[string]any{
"pending": pending,
"running": running,
@@ -160,9 +160,9 @@ func healthErrors(stats *model.Stats) healthComponent {
message = "there are failed jobs in the last 24 hours"
}
return healthComponent{
Name: "errors",
Status: status,
Message: message,
Name: "errors",
Status: status,
Error: message,
Data: map[string]any{
"failed_total": failedTotal,
"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"
}
return healthComponent{
Name: "throughput",
Status: status,
Message: message,
Name: "throughput",
Status: status,
Error: message,
Data: map[string]any{
"done_24h": done24h,
"retried_24h": retried24h,
@@ -221,9 +221,9 @@ func healthInfra(infra infraStatusResponse) healthComponent {
message = infra.SidecarError
}
return healthComponent{
Name: "infra",
Status: status,
Message: message,
Name: "infra",
Status: status,
Error: message,
Data: map[string]any{
"sidecar": infra.Sidecar,
},