fix: align ai health status contract
This commit is contained in:
@@ -28,30 +28,30 @@ func (s *Server) handleHealthDetail(w http.ResponseWriter, r *http.Request) {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
resp := healthDetailResponse{
|
resp := healthDetailResponse{
|
||||||
Status: "healthy",
|
Status: "ok",
|
||||||
Generated: time.Now().UTC(),
|
Generated: time.Now().UTC(),
|
||||||
}
|
}
|
||||||
|
|
||||||
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: "unhealthy",
|
Status: "down",
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
resp.Status = worseHealthStatus(resp.Status, "unhealthy")
|
resp.Status = worseHealthStatus(resp.Status, "down")
|
||||||
writeJSON(w, http.StatusServiceUnavailable, resp)
|
writeJSON(w, http.StatusServiceUnavailable, resp)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
resp.Components = append(resp.Components, healthComponent{Name: "postgres", Status: "healthy"})
|
resp.Components = append(resp.Components, healthComponent{Name: "postgres", Status: "ok"})
|
||||||
|
|
||||||
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: "unhealthy",
|
Status: "down",
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
resp.Status = worseHealthStatus(resp.Status, "unhealthy")
|
resp.Status = worseHealthStatus(resp.Status, "down")
|
||||||
writeJSON(w, http.StatusServiceUnavailable, resp)
|
writeJSON(w, http.StatusServiceUnavailable, resp)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -68,7 +68,7 @@ func (s *Server) handleHealthDetail(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
statusCode := http.StatusOK
|
statusCode := http.StatusOK
|
||||||
if resp.Status == "unhealthy" {
|
if resp.Status == "down" {
|
||||||
statusCode = http.StatusServiceUnavailable
|
statusCode = http.StatusServiceUnavailable
|
||||||
}
|
}
|
||||||
writeJSON(w, statusCode, resp)
|
writeJSON(w, statusCode, resp)
|
||||||
@@ -79,7 +79,7 @@ func (s *Server) healthProviders(ctx context.Context) healthComponent {
|
|||||||
s.checkLLM(ctx),
|
s.checkLLM(ctx),
|
||||||
s.checkAudioLLM(ctx, transcription.ProviderWhisperLargeV3, s.cfg.AudioBaseURL, s.cfg.AudioAPIKey, s.cfg.AudioModel, s.cfg.AudioTimeout),
|
s.checkAudioLLM(ctx, transcription.ProviderWhisperLargeV3, s.cfg.AudioBaseURL, s.cfg.AudioAPIKey, s.cfg.AudioModel, s.cfg.AudioTimeout),
|
||||||
}
|
}
|
||||||
status := "healthy"
|
status := "ok"
|
||||||
messages := make([]string, 0)
|
messages := make([]string, 0)
|
||||||
for _, provider := range providers {
|
for _, provider := range providers {
|
||||||
switch {
|
switch {
|
||||||
@@ -87,7 +87,7 @@ func (s *Server) healthProviders(ctx context.Context) healthComponent {
|
|||||||
status = worseHealthStatus(status, "degraded")
|
status = worseHealthStatus(status, "degraded")
|
||||||
messages = append(messages, provider.Name+" not configured")
|
messages = append(messages, provider.Name+" not configured")
|
||||||
case !provider.OK:
|
case !provider.OK:
|
||||||
status = worseHealthStatus(status, "unhealthy")
|
status = worseHealthStatus(status, "down")
|
||||||
if provider.Error != "" {
|
if provider.Error != "" {
|
||||||
messages = append(messages, provider.Name+": "+provider.Error)
|
messages = append(messages, provider.Name+": "+provider.Error)
|
||||||
} else {
|
} else {
|
||||||
@@ -124,7 +124,7 @@ func healthQueue(stats *model.Stats) healthComponent {
|
|||||||
oldestRunningAgeSeconds = row.OldestRunningAgeSeconds
|
oldestRunningAgeSeconds = row.OldestRunningAgeSeconds
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
status := "healthy"
|
status := "ok"
|
||||||
message := ""
|
message := ""
|
||||||
if staleRunning > 0 {
|
if staleRunning > 0 {
|
||||||
status = "degraded"
|
status = "degraded"
|
||||||
@@ -153,7 +153,7 @@ func healthErrors(stats *model.Stats) healthComponent {
|
|||||||
failedTotal += row.Total
|
failedTotal += row.Total
|
||||||
failed24h += row.Last24h
|
failed24h += row.Last24h
|
||||||
}
|
}
|
||||||
status := "healthy"
|
status := "ok"
|
||||||
message := ""
|
message := ""
|
||||||
if failed24h > 0 {
|
if failed24h > 0 {
|
||||||
status = "degraded"
|
status = "degraded"
|
||||||
@@ -194,7 +194,7 @@ func healthThroughput(stats *model.Stats) healthComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
status := "healthy"
|
status := "ok"
|
||||||
message := ""
|
message := ""
|
||||||
if len(stuckStages) > 0 {
|
if len(stuckStages) > 0 {
|
||||||
status = "degraded"
|
status = "degraded"
|
||||||
@@ -214,7 +214,7 @@ func healthThroughput(stats *model.Stats) healthComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func healthInfra(infra infraStatusResponse) healthComponent {
|
func healthInfra(infra infraStatusResponse) healthComponent {
|
||||||
status := "healthy"
|
status := "ok"
|
||||||
message := ""
|
message := ""
|
||||||
if infra.SidecarError != "" {
|
if infra.SidecarError != "" {
|
||||||
status = "degraded"
|
status = "degraded"
|
||||||
@@ -231,11 +231,11 @@ func healthInfra(infra infraStatusResponse) healthComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func worseHealthStatus(current, next string) string {
|
func worseHealthStatus(current, next string) string {
|
||||||
if current == "unhealthy" || next == "unhealthy" {
|
if current == "down" || next == "down" {
|
||||||
return "unhealthy"
|
return "down"
|
||||||
}
|
}
|
||||||
if current == "degraded" || next == "degraded" {
|
if current == "degraded" || next == "degraded" {
|
||||||
return "degraded"
|
return "degraded"
|
||||||
}
|
}
|
||||||
return "healthy"
|
return "ok"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user