Group AI errors by owner service
All checks were successful
CI / test (push) Successful in 23s
Build and Deploy / build-and-deploy (push) Successful in 24s

This commit is contained in:
Grendgi
2026-06-09 12:06:01 +03:00
parent da144ecefe
commit 562fad6f87
5 changed files with 12 additions and 4 deletions

View File

@@ -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';

View File

@@ -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"`

View File

@@ -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)

View File

@@ -0,0 +1 @@
DROP INDEX IF EXISTS ai_jobs_owner_error_stats_idx;

View File

@@ -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';