Flesh out dd0c/cost: ingestion with Welford optimistic locking, anomaly API, governance, baselines
- Ingestion API: batch cost events, Welford baseline update with optimistic locking (version column), anomaly detection inline - Anomaly API: list (filtered), acknowledge, snooze (1-168h), mark expected, dashboard summary with hourly trend - Governance API: mode status, promotion eligibility check with FP rate calculation - Baseline API: list with computed stddev, reset per resource - Data layer: withTenant() RLS wrapper, Zod config with ANOMALY_THRESHOLD - Fastify server entry point
This commit is contained in:
29
products/05-aws-cost-anomaly/src/index.ts
Normal file
29
products/05-aws-cost-anomaly/src/index.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import Fastify from 'fastify';
|
||||
import cors from '@fastify/cors';
|
||||
import pino from 'pino';
|
||||
import { config } from './config/index.js';
|
||||
import { registerAnomalyRoutes } from './api/anomalies.js';
|
||||
import { registerBaselineRoutes } from './api/baselines.js';
|
||||
import { registerGovernanceRoutes } from './api/governance.js';
|
||||
import { registerIngestionRoutes } from './api/ingestion.js';
|
||||
|
||||
const logger = pino({ name: 'dd0c-cost', level: config.LOG_LEVEL });
|
||||
|
||||
const app = Fastify({ logger: true });
|
||||
|
||||
await app.register(cors, { origin: config.CORS_ORIGIN });
|
||||
|
||||
app.get('/health', async () => ({ status: 'ok', service: 'dd0c-cost' }));
|
||||
|
||||
registerIngestionRoutes(app);
|
||||
registerAnomalyRoutes(app);
|
||||
registerBaselineRoutes(app);
|
||||
registerGovernanceRoutes(app);
|
||||
|
||||
try {
|
||||
await app.listen({ port: config.PORT, host: '0.0.0.0' });
|
||||
logger.info({ port: config.PORT }, 'dd0c/cost started');
|
||||
} catch (err) {
|
||||
logger.fatal(err, 'Failed to start');
|
||||
process.exit(1);
|
||||
}
|
||||
Reference in New Issue
Block a user