Implement pipeline monitoring alerts

Approve and implement the Supabase migration for the pipeline monitoring alert system. This includes expanding alert types, adding new monitoring functions, and updating existing ones with escalating thresholds.
This commit is contained in:
gpt-engineer-app[bot]
2025-11-07 05:05:32 +00:00
parent a74b8d6e74
commit d903e96e13
7 changed files with 544 additions and 20 deletions

View File

@@ -438,6 +438,18 @@ async function submitCompositeCreation(
}
if (errors.length > 0) {
// Report to system alerts (non-blocking)
import('./pipelineAlerts').then(async ({ reportTempRefError }) => {
try {
const { data: { user } } = await supabase.auth.getUser();
if (user) {
await reportTempRefError(uploadedPrimary.type, errors, user.id);
}
} catch (e) {
console.warn('Failed to report temp ref error:', e);
}
});
throw new Error(`Temp reference validation failed: ${errors.join(', ')}`);
}
};

82
src/lib/pipelineAlerts.ts Normal file
View File

@@ -0,0 +1,82 @@
/**
* Pipeline Alert Reporting
*
* Client-side utilities for reporting critical pipeline issues to system alerts.
* Non-blocking operations that enhance monitoring without disrupting user flows.
*/
import { supabase } from '@/lib/supabaseClient';
import { handleNonCriticalError } from '@/lib/errorHandler';
/**
* Report temp ref validation errors to system alerts
* Called when validateTempRefs() fails in entitySubmissionHelpers
*/
export async function reportTempRefError(
entityType: 'park' | 'ride',
errors: string[],
userId: string
): Promise<void> {
try {
await supabase.rpc('create_system_alert', {
p_alert_type: 'temp_ref_error',
p_severity: 'high',
p_message: `Temp reference validation failed for ${entityType}: ${errors.join(', ')}`,
p_metadata: {
entity_type: entityType,
errors,
user_id: userId,
timestamp: new Date().toISOString()
}
});
} catch (error) {
handleNonCriticalError(error, {
action: 'Report temp ref error to alerts'
});
}
}
/**
* Report submission queue backlog
* Called when IndexedDB queue exceeds threshold
*/
export async function reportQueueBacklog(
pendingCount: number,
userId?: string
): Promise<void> {
// Only report if backlog > 10
if (pendingCount <= 10) return;
try {
await supabase.rpc('create_system_alert', {
p_alert_type: 'submission_queue_backlog',
p_severity: pendingCount > 50 ? 'high' : 'medium',
p_message: `Submission queue backlog: ${pendingCount} pending submissions`,
p_metadata: {
pending_count: pendingCount,
user_id: userId,
timestamp: new Date().toISOString()
}
});
} catch (error) {
handleNonCriticalError(error, {
action: 'Report queue backlog to alerts'
});
}
}
/**
* Check queue status and report if needed
* Called on app startup and periodically
*/
export async function checkAndReportQueueStatus(userId?: string): Promise<void> {
try {
const { getPendingCount } = await import('./submissionQueue');
const pendingCount = await getPendingCount();
await reportQueueBacklog(pendingCount, userId);
} catch (error) {
handleNonCriticalError(error, {
action: 'Check queue status'
});
}
}