CI/CD: - Add .github/workflows/deploy.yml (lint, test, build Docker, Coolify deploy) Observability: - Add Pino logger (services/logger.js) — structured JSON logging - Add Prometheus metrics (services/metrics.js) — /metrics endpoint - Replace console.error with pino in error handler - Track http_request_duration, http_requests_total, active_loads, total_commission Testing: - Add Jest config to package.json - Add integration tests (tests/integration/app.test.js) — health, metrics, auth, 404 - Add unit tests (tests/unit/utils.test.js) — formatINR, getStatusColor, calcCommission, WhatsApp parser - Add devDeps: jest, supertest, eslint, prettier UX: - Debounced search (400ms) on Loads list page - Cache-busting asset versioning (?v=timestamp) on CSS/JS includes - ESLint + Prettier configs Package updates: - Add pino, pino-http, prom-client to dependencies - Add jest, eslint, prettier, supertest, nodemon to devDependencies
37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
const client = require('prom-client');
|
|
|
|
// Create a Registry
|
|
const register = new client.Registry();
|
|
|
|
// Add default metrics (CPU, memory, etc.)
|
|
client.collectDefaultMetrics({ register });
|
|
|
|
// Custom metrics
|
|
const httpRequestDuration = new client.Histogram({
|
|
name: 'http_request_duration_seconds',
|
|
help: 'Duration of HTTP requests in seconds',
|
|
labelNames: ['method', 'route', 'status_code'],
|
|
buckets: [0.01, 0.05, 0.1, 0.5, 1, 2, 5],
|
|
});
|
|
register.registerMetric(httpRequestDuration);
|
|
|
|
const httpRequestTotal = new client.Counter({
|
|
name: 'http_requests_total',
|
|
help: 'Total number of HTTP requests',
|
|
labelNames: ['method', 'route', 'status_code'],
|
|
});
|
|
register.registerMetric(httpRequestTotal);
|
|
|
|
const activeLoads = new client.Gauge({
|
|
name: 'freightdesk_active_loads',
|
|
help: 'Number of active (non-settled) loads',
|
|
});
|
|
register.registerMetric(activeLoads);
|
|
|
|
const totalCommission = new client.Gauge({
|
|
name: 'freightdesk_total_commission',
|
|
help: 'Total commission earned (INR)',
|
|
});
|
|
register.registerMetric(totalCommission);
|
|
|
|
module.exports = { register, httpRequestDuration, httpRequestTotal, activeLoads, totalCommission };
|