2023-05-02 14:29:22 +00:00
|
|
|
import 'ejs';
|
|
|
|
import { PostgresAppInstance } from 'CommonServer/Infrastructure/PostgresDatabase';
|
|
|
|
import Express, { ExpressApplication } from 'CommonServer/Utils/Express';
|
|
|
|
import logger from 'CommonServer/Utils/Logger';
|
2022-05-24 16:46:21 +00:00
|
|
|
import App from 'CommonServer/Utils/StartServer';
|
2023-05-02 14:29:22 +00:00
|
|
|
import AliveAPI from './API/Alive';
|
|
|
|
import RegisterAPI from './API/Register';
|
2023-05-10 17:53:36 +00:00
|
|
|
import MonitorAPI from './API/Monitor';
|
2023-10-09 17:54:23 +00:00
|
|
|
import Ingestor from './API/Probe';
|
2023-07-29 15:21:47 +00:00
|
|
|
import IncomingRequestAPI from './API/IncomingRequest';
|
2023-10-10 10:16:22 +00:00
|
|
|
import OTelIngestAPI from './API/OTelIngest';
|
2023-08-19 19:49:24 +00:00
|
|
|
import { ClickhouseAppInstance } from 'CommonServer/Infrastructure/ClickhouseDatabase';
|
2022-05-24 16:46:21 +00:00
|
|
|
|
2023-05-02 14:29:22 +00:00
|
|
|
import Redis from 'CommonServer/Infrastructure/Redis';
|
2022-01-10 06:48:35 +00:00
|
|
|
|
2023-05-02 14:29:22 +00:00
|
|
|
const app: ExpressApplication = Express.getExpressApp();
|
2022-04-20 20:14:44 +00:00
|
|
|
|
2023-10-09 17:54:23 +00:00
|
|
|
const APP_NAME: string = 'ingestor';
|
2022-01-10 06:48:35 +00:00
|
|
|
|
2023-05-02 14:29:22 +00:00
|
|
|
app.use([`/${APP_NAME}`, '/'], AliveAPI);
|
|
|
|
app.use([`/${APP_NAME}`, '/'], RegisterAPI);
|
2023-05-10 17:53:36 +00:00
|
|
|
app.use([`/${APP_NAME}`, '/'], MonitorAPI);
|
2023-10-09 17:54:23 +00:00
|
|
|
app.use([`/${APP_NAME}`, '/'], Ingestor);
|
2023-07-29 15:21:47 +00:00
|
|
|
app.use([`/${APP_NAME}`, '/'], IncomingRequestAPI);
|
2023-10-10 10:16:22 +00:00
|
|
|
app.use([`/${APP_NAME}`, '/'], OTelIngestAPI);
|
2023-05-02 14:29:22 +00:00
|
|
|
|
2023-08-10 17:25:15 +00:00
|
|
|
const init: () => Promise<void> = async (): Promise<void> => {
|
2023-05-02 14:29:22 +00:00
|
|
|
try {
|
|
|
|
// init the app
|
|
|
|
await App(APP_NAME);
|
|
|
|
// connect to the database.
|
|
|
|
await PostgresAppInstance.connect(
|
|
|
|
PostgresAppInstance.getDatasourceOptions()
|
|
|
|
);
|
|
|
|
|
|
|
|
// connect redis
|
|
|
|
await Redis.connect();
|
2023-08-19 19:49:24 +00:00
|
|
|
|
2023-08-21 11:04:28 +00:00
|
|
|
await ClickhouseAppInstance.connect(
|
|
|
|
ClickhouseAppInstance.getDatasourceOptions()
|
|
|
|
);
|
2023-05-02 14:29:22 +00:00
|
|
|
} catch (err) {
|
|
|
|
logger.error('App Init Failed:');
|
|
|
|
logger.error(err);
|
2023-10-04 18:22:25 +00:00
|
|
|
throw err;
|
2023-05-02 14:29:22 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-08-10 18:00:27 +00:00
|
|
|
init().catch((err: Error) => {
|
|
|
|
logger.error(err);
|
2023-10-04 18:22:25 +00:00
|
|
|
logger.info('Exiting node process');
|
2023-09-27 19:48:50 +00:00
|
|
|
process.exit(1);
|
2023-08-10 18:00:27 +00:00
|
|
|
});
|