Group AI errors by owner service
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
CREATE INDEX IF NOT EXISTS ai_jobs_owner_error_stats_idx
|
||||
ON ai_jobs (owner_service, task_type, model_profile, error_code, updated_at DESC)
|
||||
WHERE status = 'failed';
|
||||
@@ -111,6 +111,7 @@ type QueueStat struct {
|
||||
}
|
||||
|
||||
type ErrorStat struct {
|
||||
OwnerService string `json:"owner_service,omitempty"`
|
||||
TaskType string `json:"task_type"`
|
||||
ModelProfile string `json:"model_profile"`
|
||||
ErrorCode string `json:"error_code"`
|
||||
|
||||
@@ -599,13 +599,13 @@ ORDER BY owner_service, task_type, model_profile, status
|
||||
}
|
||||
|
||||
errorRows, err := s.pool.Query(ctx, `
|
||||
SELECT task_type, model_profile, COALESCE(NULLIF(error_code, ''), 'unknown') AS error_code,
|
||||
SELECT owner_service, task_type, model_profile, COALESCE(NULLIF(error_code, ''), 'unknown') AS error_code,
|
||||
count(*) AS total,
|
||||
count(*) FILTER (WHERE updated_at > NOW() - INTERVAL '24 hours') AS last_24h
|
||||
FROM ai_jobs
|
||||
WHERE status = 'failed'
|
||||
GROUP BY task_type, model_profile, COALESCE(NULLIF(error_code, ''), 'unknown')
|
||||
ORDER BY last_24h DESC, total DESC
|
||||
GROUP BY owner_service, task_type, model_profile, COALESCE(NULLIF(error_code, ''), 'unknown')
|
||||
ORDER BY owner_service, last_24h DESC, total DESC
|
||||
`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -613,7 +613,7 @@ ORDER BY last_24h DESC, total DESC
|
||||
defer errorRows.Close()
|
||||
for errorRows.Next() {
|
||||
var stat model.ErrorStat
|
||||
if err := errorRows.Scan(&stat.TaskType, &stat.ModelProfile, &stat.ErrorCode, &stat.Total, &stat.Last24h); err != nil {
|
||||
if err := errorRows.Scan(&stat.OwnerService, &stat.TaskType, &stat.ModelProfile, &stat.ErrorCode, &stat.Total, &stat.Last24h); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out.Errors = append(out.Errors, stat)
|
||||
|
||||
Reference in New Issue
Block a user