mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
- Integrated profiling initialization in Probe, Telemetry, TestServer, and Worker services. - Added environment variables for enabling profiling in various services. - Created Profiling utility to handle CPU profiling and send data to OTLP endpoint. - Introduced new metric types for exceptions, spans, and dashboards. - Developed utility classes for handling alert and incident metrics. - Added new React components for displaying alert and incident metrics in the dashboard.
91 lines
2.5 KiB
TypeScript
91 lines
2.5 KiB
TypeScript
import { PORT } from "./Config";
|
|
import AliveJob from "./Jobs/Alive";
|
|
import startTaskProcessingLoop from "./Jobs/ProcessScheduledTasks";
|
|
import Register from "./Services/Register";
|
|
import MetricsAPI from "./API/Metrics";
|
|
import {
|
|
getTaskHandlerRegistry,
|
|
FixExceptionTaskHandler,
|
|
} from "./TaskHandlers/Index";
|
|
import { PromiseVoidFunction } from "Common/Types/FunctionTypes";
|
|
import logger from "Common/Server/Utils/Logger";
|
|
import App from "Common/Server/Utils/StartServer";
|
|
import Telemetry from "Common/Server/Utils/Telemetry";
|
|
import Profiling from "Common/Server/Utils/Profiling";
|
|
import Express, { ExpressApplication } from "Common/Server/Utils/Express";
|
|
import "ejs";
|
|
|
|
const APP_NAME: string = "ai-agent";
|
|
|
|
const init: PromiseVoidFunction = async (): Promise<void> => {
|
|
try {
|
|
// Initialize telemetry
|
|
Telemetry.init({
|
|
serviceName: APP_NAME,
|
|
});
|
|
|
|
// Initialize profiling (opt-in via ENABLE_PROFILING env var)
|
|
Profiling.init({
|
|
serviceName: APP_NAME,
|
|
});
|
|
|
|
logger.info("AI Agent Service - Starting...");
|
|
|
|
// init the app
|
|
await App.init({
|
|
appName: APP_NAME,
|
|
port: PORT,
|
|
isFrontendApp: false,
|
|
statusOptions: {
|
|
liveCheck: async () => {},
|
|
readyCheck: async () => {},
|
|
},
|
|
});
|
|
|
|
// Add metrics API routes for KEDA autoscaling
|
|
const app: ExpressApplication = Express.getExpressApp();
|
|
app.use("/metrics", MetricsAPI);
|
|
|
|
// add default routes
|
|
await App.addDefaultRoutes();
|
|
|
|
try {
|
|
// Register this AI Agent.
|
|
await Register.registerAIAgent();
|
|
|
|
logger.debug("AI Agent registered");
|
|
|
|
AliveJob();
|
|
|
|
// Register task handlers
|
|
logger.debug("Registering task handlers...");
|
|
const taskHandlerRegistry: ReturnType<typeof getTaskHandlerRegistry> =
|
|
getTaskHandlerRegistry();
|
|
taskHandlerRegistry.register(new FixExceptionTaskHandler());
|
|
logger.debug(
|
|
`Registered ${taskHandlerRegistry.getHandlerCount()} task handler(s): ${taskHandlerRegistry.getRegisteredTaskTypes().join(", ")}`,
|
|
);
|
|
|
|
// Start task processing loop (runs in background)
|
|
startTaskProcessingLoop().catch((err: Error) => {
|
|
logger.error("Task processing loop failed:");
|
|
logger.error(err);
|
|
});
|
|
} catch (err) {
|
|
logger.error("Register AI Agent failed");
|
|
logger.error(err);
|
|
throw err;
|
|
}
|
|
} catch (err) {
|
|
logger.error("App Init Failed:");
|
|
logger.error(err);
|
|
throw err;
|
|
}
|
|
};
|
|
|
|
init().catch((err: Error) => {
|
|
logger.error(err);
|
|
logger.error("Exiting node process");
|
|
process.exit(1);
|
|
});
|