Files
dd0c/products/05-aws-cost-anomaly/migrations/005_zombies.sql
Max f1f4dee7ab
Some checks failed
CI — P3 Alert / test (push) Successful in 28s
CI — P5 Cost / test (push) Successful in 42s
CI — P6 Run / saas (push) Successful in 41s
CI — P6 Run / build-push (push) Has been cancelled
CI — P3 Alert / build-push (push) Failing after 53s
CI — P5 Cost / build-push (push) Failing after 5s
feat(cost): add zombie hunter, Slack interactions, composite scoring
- Zombie resource hunter: detects idle EC2/RDS/EBS/EIP/NAT resources
- Slack interactive handler: acknowledge, snooze, create-ticket actions
- Composite anomaly scorer: Z-Score + rate-of-change + pattern + novelty
- Cold-start fast path for new resources (<7 days data)
- 005_zombies.sql migration
2026-03-03 06:39:20 +00:00

28 lines
1.2 KiB
SQL

-- Zombie resource detection + composite scoring
-- Zombie resources table
CREATE TABLE zombie_resources (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
tenant_id UUID NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,
resource_id TEXT NOT NULL,
resource_type TEXT NOT NULL CHECK (resource_type IN ('ec2', 'rds', 'ebs', 'eip', 'nat_gateway')),
region TEXT NOT NULL,
account_id TEXT NOT NULL,
estimated_monthly_waste NUMERIC(10,2) NOT NULL DEFAULT 0,
last_activity TIMESTAMPTZ,
recommendation TEXT NOT NULL,
status TEXT NOT NULL DEFAULT 'open' CHECK (status IN ('open', 'dismissed', 'remediated')),
detected_at TIMESTAMPTZ NOT NULL DEFAULT now(),
UNIQUE(tenant_id, resource_id, resource_type)
);
CREATE INDEX idx_zombie_resources_tenant ON zombie_resources(tenant_id, status, detected_at DESC);
-- RLS
ALTER TABLE zombie_resources ENABLE ROW LEVEL SECURITY;
CREATE POLICY tenant_iso_zombies ON zombie_resources
USING (tenant_id::text = current_setting('app.tenant_id', true));
-- Composite scoring columns on anomalies
ALTER TABLE anomalies ADD COLUMN IF NOT EXISTS composite_score NUMERIC(5,2);
ALTER TABLE anomalies ADD COLUMN IF NOT EXISTS score_breakdown JSONB;