\pset pager off
WITH w AS (SELECT * FROM ops_error_logs WHERE created_at >= now() - interval '30 minutes')
SELECT 'last30m_total' k, count(*)::text v FROM w;
WITH w AS (SELECT * FROM ops_error_logs WHERE created_at >= now() - interval '30 minutes')
SELECT COALESCE(group_id,0) group_id, COALESCE(account_id,0) account_id, model, error_phase, error_owner, COALESCE(status_code,0) status_code, COALESCE(upstream_status_code,0) upstream_status_code, left(error_message,150) msg, count(*)
FROM w
WHERE NOT (error_message ILIKE '%API key required%' OR error_message ILIKE '%Invalid API key%' OR error_message ILIKE '%API key disabled%' OR error_message ILIKE '%No active subscription%' OR error_message ILIKE '%Insufficient account balance%')
GROUP BY 1,2,3,4,5,6,7,8 ORDER BY count(*) DESC LIMIT 30;
