Implement pipeline monitoring alerts

Extend existing alert system to include real-time monitoring for rate limit violations and ban evasion attempts. This involves adding new reporting functions to `pipelineAlerts.ts`, integrating these functions into submission and company helper files, updating the admin dashboard component to display new alert types, and creating a database migration for the new alert type.
This commit is contained in:
gpt-engineer-app[bot]
2025-11-08 00:39:37 +00:00
parent 3c2c511ecc
commit 64e2b893b9
4 changed files with 145 additions and 0 deletions

View File

@@ -80,3 +80,59 @@ export async function checkAndReportQueueStatus(userId?: string): Promise<void>
});
}
}
/**
* Report rate limit violations to system alerts
* Called when checkSubmissionRateLimit() blocks a user
*/
export async function reportRateLimitViolation(
userId: string,
action: string,
retryAfter: number
): Promise<void> {
try {
await supabase.rpc('create_system_alert', {
p_alert_type: 'rate_limit_violation',
p_severity: 'medium',
p_message: `Rate limit exceeded: ${action} (retry after ${retryAfter}s)`,
p_metadata: {
user_id: userId,
action,
retry_after_seconds: retryAfter,
timestamp: new Date().toISOString()
}
});
} catch (error) {
handleNonCriticalError(error, {
action: 'Report rate limit violation to alerts'
});
}
}
/**
* Report ban evasion attempts to system alerts
* Called when banned users attempt to submit content
*/
export async function reportBanEvasionAttempt(
userId: string,
action: string,
username?: string
): Promise<void> {
try {
await supabase.rpc('create_system_alert', {
p_alert_type: 'ban_attempt',
p_severity: 'high',
p_message: `Banned user attempted submission: ${action}${username ? ` (${username})` : ''}`,
p_metadata: {
user_id: userId,
action,
username: username || 'unknown',
timestamp: new Date().toISOString()
}
});
} catch (error) {
handleNonCriticalError(error, {
action: 'Report ban evasion attempt to alerts'
});
}
}