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.
107 lines
3.0 KiB
TypeScript
107 lines
3.0 KiB
TypeScript
import WorkerRoutes from "./Routes";
|
|
import WorkflowFeatureSet from "./FeatureSet/Workflow/Index";
|
|
import { PromiseVoidFunction } from "Common/Types/FunctionTypes";
|
|
import InfrastructureStatus from "Common/Server/Infrastructure/Status";
|
|
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 Realtime from "Common/Server/Utils/Realtime";
|
|
import PostgresAppInstance from "Common/Server/Infrastructure/PostgresDatabase";
|
|
import Redis from "Common/Server/Infrastructure/Redis";
|
|
import { ClickhouseAppInstance } from "Common/Server/Infrastructure/ClickhouseDatabase";
|
|
import { WORKER_CONCURRENCY } from "./Config";
|
|
import "ejs";
|
|
|
|
const APP_NAME: string = "worker";
|
|
|
|
const init: PromiseVoidFunction = async (): Promise<void> => {
|
|
try {
|
|
logger.debug("Initializing Worker");
|
|
|
|
// Initialize telemetry
|
|
Telemetry.init({
|
|
serviceName: APP_NAME,
|
|
});
|
|
|
|
// Initialize profiling (opt-in via ENABLE_PROFILING env var)
|
|
Profiling.init({
|
|
serviceName: APP_NAME,
|
|
});
|
|
|
|
logger.debug("Telemetry initialized");
|
|
|
|
logger.info(`Worker Service - Queue concurrency: ${WORKER_CONCURRENCY}`);
|
|
|
|
const statusCheck: PromiseVoidFunction = async (): Promise<void> => {
|
|
// Check the status of infrastructure components
|
|
return await InfrastructureStatus.checkStatusWithRetry({
|
|
checkClickhouseStatus: true,
|
|
checkPostgresStatus: true,
|
|
checkRedisStatus: true,
|
|
retryCount: 3,
|
|
});
|
|
};
|
|
|
|
// Initialize the app with service name and status checks
|
|
await App.init({
|
|
appName: APP_NAME,
|
|
statusOptions: {
|
|
liveCheck: statusCheck,
|
|
readyCheck: statusCheck,
|
|
},
|
|
});
|
|
|
|
logger.debug("App initialized");
|
|
|
|
// Connect to Postgres database
|
|
await PostgresAppInstance.connect();
|
|
|
|
logger.debug("Postgres connected");
|
|
|
|
// Connect to Redis
|
|
await Redis.connect();
|
|
|
|
logger.debug("Redis connected");
|
|
|
|
// Connect to Clickhouse database
|
|
await ClickhouseAppInstance.connect(
|
|
ClickhouseAppInstance.getDatasourceOptions(),
|
|
);
|
|
|
|
logger.debug("Clickhouse connected");
|
|
|
|
// Initialize real-time functionalities
|
|
await Realtime.init();
|
|
|
|
logger.debug("Realtime initialized");
|
|
|
|
// Register worker routes (must be before default 404 catch-alls)
|
|
await WorkerRoutes.init();
|
|
|
|
logger.debug("Routes initialized");
|
|
|
|
// Initialize workflow feature set
|
|
await WorkflowFeatureSet.init();
|
|
|
|
logger.debug("Workflow feature set initialized");
|
|
|
|
// Add default routes to the app (catch-alls should be last)
|
|
await App.addDefaultRoutes();
|
|
|
|
logger.debug("Default routes added");
|
|
|
|
logger.info("Worker Initialized Successfully");
|
|
} catch (err) {
|
|
logger.error("Worker Init Failed:");
|
|
logger.error(err);
|
|
throw err;
|
|
}
|
|
};
|
|
|
|
init().catch((err: Error) => {
|
|
logger.error(err);
|
|
logger.error("Exiting node process");
|
|
process.exit(1);
|
|
});
|