Connect to Lovable Cloud

Fix security definer view issue by enabling security_invoker on grouped_alerts_view and implement grouped alerts system with new keys, hooks, components, and monitoring overview integration. Added migration to adjust view, updated query keys, created useGroupedAlerts, useAlertGroupActions, GroupedAlertsPanel, and updated MonitoringOverview to include grouped alerts.
This commit is contained in:
gpt-engineer-app[bot]
2025-11-11 01:51:42 +00:00
parent 97f586232f
commit 01aba7df90
6 changed files with 508 additions and 8 deletions

View File

@@ -0,0 +1,51 @@
-- Fix security definer view issue by enabling security_invoker
-- This ensures the view respects RLS policies and runs with the querying user's permissions
DROP VIEW IF EXISTS grouped_alerts_view;
CREATE OR REPLACE VIEW grouped_alerts_view
WITH (security_invoker=on)
AS
WITH system_alerts_grouped AS (
SELECT
alert_type AS group_key,
alert_type,
severity,
'system'::text AS source,
NULL::text AS function_name,
NULL::text AS metric_type,
COUNT(*) AS alert_count,
MIN(created_at) AS first_seen,
MAX(created_at) AS last_seen,
ARRAY_AGG(id::text ORDER BY created_at DESC) AS alert_ids,
ARRAY_AGG(message ORDER BY created_at DESC) AS messages,
BOOL_OR(resolved_at IS NOT NULL) AS has_resolved,
COUNT(*) FILTER (WHERE resolved_at IS NULL) AS unresolved_count
FROM system_alerts
WHERE created_at > NOW() - INTERVAL '7 days'
GROUP BY alert_type, severity
),
rate_limit_alerts_grouped AS (
SELECT
CONCAT(metric_type, ':', COALESCE(function_name, 'global')) AS group_key,
NULL::text AS alert_type,
'high'::text AS severity,
'rate_limit'::text AS source,
function_name,
metric_type,
COUNT(*) AS alert_count,
MIN(created_at) AS first_seen,
MAX(created_at) AS last_seen,
ARRAY_AGG(id::text ORDER BY created_at DESC) AS alert_ids,
ARRAY_AGG(alert_message ORDER BY created_at DESC) AS messages,
BOOL_OR(resolved_at IS NOT NULL) AS has_resolved,
COUNT(*) FILTER (WHERE resolved_at IS NULL) AS unresolved_count
FROM rate_limit_alerts
WHERE created_at > NOW() - INTERVAL '7 days'
GROUP BY metric_type, function_name
)
SELECT * FROM system_alerts_grouped
UNION ALL
SELECT * FROM rate_limit_alerts_grouped;
-- Grant access to authenticated users
GRANT SELECT ON grouped_alerts_view TO authenticated;