fix(monitoring): report observed research and paper readiness (O02)
This commit is contained in:
parent
70d173a908
commit
8c858b9d5c
23 changed files with 1340 additions and 319 deletions
|
|
@ -48,7 +48,9 @@ export function createRoutes(
|
|||
// Create routes with container
|
||||
const healthRoutes = createHealthRoutes(container);
|
||||
const exchangeRoutes = createExchangeRoutes(container);
|
||||
const monitoringRoutes = createMonitoringRoutes(container);
|
||||
const monitoringRoutes = createMonitoringRoutes(container, {
|
||||
origin: integrations ? integrations.paperOrchestratorOrigin : process.env.ORCHESTRATOR_URL,
|
||||
});
|
||||
const pipelineRoutes = createPipelineRoutes(container);
|
||||
const backtestRoutes = createBacktestRoutes(container);
|
||||
const backtestV2Routes = createBacktestV2Routes(container);
|
||||
|
|
|
|||
|
|
@ -6,9 +6,17 @@ import { Hono } from 'hono';
|
|||
import type { IServiceContainer } from '@stock-bot/handlers';
|
||||
import { MonitoringService } from '../services/monitoring.service';
|
||||
|
||||
export function createMonitoringRoutes(container: IServiceContainer) {
|
||||
export function createMonitoringRoutes(
|
||||
container: IServiceContainer,
|
||||
options: ConstructorParameters<typeof MonitoringService>[1] = {}
|
||||
) {
|
||||
const monitoring = new Hono();
|
||||
const monitoringService = new MonitoringService(container);
|
||||
const monitoringService = new MonitoringService(container, options);
|
||||
|
||||
monitoring.get('/readiness', async c => {
|
||||
c.header('Cache-Control', 'no-store');
|
||||
return c.json(await monitoringService.getReadiness(c.req.raw));
|
||||
});
|
||||
|
||||
/**
|
||||
* Get overall system health
|
||||
|
|
@ -22,12 +30,12 @@ export function createMonitoringRoutes(container: IServiceContainer) {
|
|||
health.status === 'healthy' ? 200 : health.status === 'degraded' ? 503 : 500;
|
||||
|
||||
return c.json(health, statusCode);
|
||||
} catch (error) {
|
||||
} catch {
|
||||
return c.json(
|
||||
{
|
||||
status: 'error',
|
||||
message: 'Failed to retrieve system health',
|
||||
error: error instanceof Error ? error.message : 'Unknown error',
|
||||
error: 'Diagnostic dependency unavailable',
|
||||
},
|
||||
500
|
||||
);
|
||||
|
|
@ -41,11 +49,11 @@ export function createMonitoringRoutes(container: IServiceContainer) {
|
|||
try {
|
||||
const stats = await monitoringService.getCacheStats();
|
||||
return c.json(stats);
|
||||
} catch (error) {
|
||||
} catch {
|
||||
return c.json(
|
||||
{
|
||||
error: 'Failed to retrieve cache statistics',
|
||||
message: error instanceof Error ? error.message : 'Unknown error',
|
||||
message: 'Diagnostic dependency unavailable',
|
||||
},
|
||||
500
|
||||
);
|
||||
|
|
@ -59,11 +67,11 @@ export function createMonitoringRoutes(container: IServiceContainer) {
|
|||
try {
|
||||
const stats = await monitoringService.getQueueStats();
|
||||
return c.json({ queues: stats });
|
||||
} catch (error) {
|
||||
} catch {
|
||||
return c.json(
|
||||
{
|
||||
error: 'Failed to retrieve queue statistics',
|
||||
message: error instanceof Error ? error.message : 'Unknown error',
|
||||
message: 'Diagnostic dependency unavailable',
|
||||
},
|
||||
500
|
||||
);
|
||||
|
|
@ -90,11 +98,11 @@ export function createMonitoringRoutes(container: IServiceContainer) {
|
|||
}
|
||||
|
||||
return c.json(queueStats);
|
||||
} catch (error) {
|
||||
} catch {
|
||||
return c.json(
|
||||
{
|
||||
error: 'Failed to retrieve queue statistics',
|
||||
message: error instanceof Error ? error.message : 'Unknown error',
|
||||
message: 'Diagnostic dependency unavailable',
|
||||
},
|
||||
500
|
||||
);
|
||||
|
|
@ -108,11 +116,11 @@ export function createMonitoringRoutes(container: IServiceContainer) {
|
|||
try {
|
||||
const stats = await monitoringService.getDatabaseStats();
|
||||
return c.json({ databases: stats });
|
||||
} catch (error) {
|
||||
} catch {
|
||||
return c.json(
|
||||
{
|
||||
error: 'Failed to retrieve database statistics',
|
||||
message: error instanceof Error ? error.message : 'Unknown error',
|
||||
message: 'Diagnostic dependency unavailable',
|
||||
},
|
||||
500
|
||||
);
|
||||
|
|
@ -139,11 +147,11 @@ export function createMonitoringRoutes(container: IServiceContainer) {
|
|||
}
|
||||
|
||||
return c.json(dbStats);
|
||||
} catch (error) {
|
||||
} catch {
|
||||
return c.json(
|
||||
{
|
||||
error: 'Failed to retrieve database statistics',
|
||||
message: error instanceof Error ? error.message : 'Unknown error',
|
||||
message: 'Diagnostic dependency unavailable',
|
||||
},
|
||||
500
|
||||
);
|
||||
|
|
@ -157,11 +165,11 @@ export function createMonitoringRoutes(container: IServiceContainer) {
|
|||
try {
|
||||
const metrics = await monitoringService.getServiceMetrics();
|
||||
return c.json(metrics);
|
||||
} catch (error) {
|
||||
} catch {
|
||||
return c.json(
|
||||
{
|
||||
error: 'Failed to retrieve service metrics',
|
||||
message: error instanceof Error ? error.message : 'Unknown error',
|
||||
message: 'Diagnostic dependency unavailable',
|
||||
},
|
||||
500
|
||||
);
|
||||
|
|
@ -189,11 +197,11 @@ export function createMonitoringRoutes(container: IServiceContainer) {
|
|||
parsed: stats,
|
||||
raw: null, // Raw Redis commands are not part of the cache capability.
|
||||
});
|
||||
} catch (error) {
|
||||
} catch {
|
||||
return c.json(
|
||||
{
|
||||
error: 'Failed to retrieve cache info',
|
||||
message: error instanceof Error ? error.message : 'Unknown error',
|
||||
message: 'Diagnostic dependency unavailable',
|
||||
},
|
||||
500
|
||||
);
|
||||
|
|
@ -218,11 +226,11 @@ export function createMonitoringRoutes(container: IServiceContainer) {
|
|||
try {
|
||||
const services = await monitoringService.getServiceStatus();
|
||||
return c.json({ services });
|
||||
} catch (error) {
|
||||
} catch {
|
||||
return c.json(
|
||||
{
|
||||
error: 'Failed to retrieve service status',
|
||||
message: error instanceof Error ? error.message : 'Unknown error',
|
||||
message: 'Diagnostic dependency unavailable',
|
||||
},
|
||||
500
|
||||
);
|
||||
|
|
@ -236,11 +244,11 @@ export function createMonitoringRoutes(container: IServiceContainer) {
|
|||
try {
|
||||
const stats = await monitoringService.getProxyStats();
|
||||
return c.json(stats || { enabled: false });
|
||||
} catch (error) {
|
||||
} catch {
|
||||
return c.json(
|
||||
{
|
||||
error: 'Failed to retrieve proxy statistics',
|
||||
message: error instanceof Error ? error.message : 'Unknown error',
|
||||
message: 'Diagnostic dependency unavailable',
|
||||
},
|
||||
500
|
||||
);
|
||||
|
|
@ -254,45 +262,11 @@ export function createMonitoringRoutes(container: IServiceContainer) {
|
|||
try {
|
||||
const overview = await monitoringService.getSystemOverview();
|
||||
return c.json(overview);
|
||||
} catch (error) {
|
||||
} catch {
|
||||
return c.json(
|
||||
{
|
||||
error: 'Failed to retrieve system overview',
|
||||
message: error instanceof Error ? error.message : 'Unknown error',
|
||||
},
|
||||
500
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Test direct BullMQ queue access
|
||||
*/
|
||||
monitoring.get('/test/queue/:name', async c => {
|
||||
const queueName = c.req.param('name');
|
||||
const { Queue } = await import('bullmq');
|
||||
|
||||
const connection = {
|
||||
host: 'localhost',
|
||||
port: 6379,
|
||||
db: 0, // All queues in DB 0
|
||||
};
|
||||
|
||||
const queue = new Queue(queueName, { connection });
|
||||
|
||||
try {
|
||||
const counts = await queue.getJobCounts();
|
||||
await queue.close();
|
||||
return c.json({
|
||||
queueName,
|
||||
counts,
|
||||
});
|
||||
} catch (error) {
|
||||
await queue.close();
|
||||
return c.json(
|
||||
{
|
||||
queueName,
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
message: 'Diagnostic dependency unavailable',
|
||||
},
|
||||
500
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue