mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-27 10:46:59 -05:00
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:
@@ -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'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user