Amal Jose commited on
Commit ·
03d6d9d
1
Parent(s): 5a1ffec
fix: Changed kafka service to aiven.io
Browse filesFiles changed (6)
3 unmodified lines456789103 unmodified linesscript: "./dist/server.js",instances: 3,exec_mode: "cluster",max_memory_restart: "4G",3 unmodified lines456789103 unmodified linesscript: "./dist/server.js",instances: 2,exec_mode: "cluster",max_memory_restart: "4G",
36 unmodified lines37383940414236 unmodified linesKAFKA_USERNAME: z.string(),KAFKA_PASSWORD: z.string(),CLICKHOUSE_USERNAME: z.string(),CLICKHOUSE_PASSWORD: z.string(),36 unmodified lines373839404142434436 unmodified linesKAFKA_USERNAME: z.string(),KAFKA_PASSWORD: z.string(),KAFKA_CA: z.string().transform((i) => i.replace(/\\n/g, "\n")),KAFKA_BROKERS: z.string(),CLICKHOUSE_USERNAME: z.string(),CLICKHOUSE_PASSWORD: z.string(),
2 unmodified lines3456789102 unmodified linesexport const kafka = new Kafka({clientId: `api-server`,brokers: ["pkc-l7pr2.ap-south-1.aws.confluent.cloud:9092"],ssl: true,sasl: {mechanism: "plain",username: ENVS.KAFKA_USERNAME as string,2 unmodified lines34567891011122 unmodified linesexport const kafka = new Kafka({clientId: `api-server`,brokers: ENVS.KAFKA_BROKERS.split(",").filter(Boolean),ssl: {ca: ENVS.KAFKA_CA},sasl: {mechanism: "plain",username: ENVS.KAFKA_USERNAME as string,
30 unmodified lines3132333435363738394041424344454630 unmodified linesconsole.log(" Kafka consumers connected");const [logsTopics, analyticsTopics] = getAllTopics();await this.logsConsumer.subscribe({ topics: logsTopics });await this.analyticsConsumer.subscribe({ topics: analyticsTopics });console.log(` Subscribed to topics:`, [...logsTopics, ...analyticsTopics]);await this.logsConsumer.run({autoCommit: false,eachBatch: universalKafkaHandler,});await this.analyticsConsumer.run({autoCommit: true,eachBatch: universalKafkaHandler,});30 unmodified lines313233343536373839404142434445464748495030 unmodified linesconsole.log(" Kafka consumers connected");const [logsTopics, analyticsTopics] = getAllTopics();await this.logsConsumer.subscribe({ topics: logsTopics, });await this.analyticsConsumer.subscribe({ topics: analyticsTopics });console.log(` Subscribed to topics:`, [...logsTopics, ...analyticsTopics]);await this.logsConsumer.run({autoCommit: true,autoCommitInterval: 10000,eachBatchAutoResolve: true,eachBatch: universalKafkaHandler,});await this.analyticsConsumer.run({autoCommit: true,autoCommitInterval: 10000,eachBatchAutoResolve: true,eachBatch: universalKafkaHandler,});
20 unmodified lines2122232425262728293031323334353637383940414243444567 unmodified lines11311411511611711811912012112212312412512612723 unmodified lines15115215315415515615715815916016116216316416516620 unmodified lines"deployment.logs": {mode: "batch",topic: "deployment.logs", // <------- Actual kafka topic namehandler: DeploymentEventHandler.handleLogsBatch,schema: DeploymentLogEventSchema,processFn: DeploymentEventHandler.handlerMessageEmitting,consumer: consumerLogsMessages,},"deployment.updates": {mode: "single",topic: "deployment.updates", // <------- Actual kafka topic namehandler: DeploymentEventHandler.handleUpdates,processFn: processLogUpdates,schema: DeploymentUpdatesEventSchema,consumer: consumerLogsUpdates,},},analytics: {"project.analytics": {mode: "batch",topic: "project.analytics", // <------- Actual kafka topic namehandler: ProjectAnalyticsHandler.handleDataBatch,schema: analyticsEventSchema,consumer: consumerAnalyticsProjects,},67 unmodified linesconst data = JSON.parse(msg.value?.toString() as any);await config.processFn(data, config);resolveOffset(msg.offset);lastOffset = msg.offset;} catch (error: any) {console.error("Failed to process message:", error); // send to dlq task-------, Not best to discard the data, Use dlqs for error handlingresolveOffset(msg.offset);lastOffset = msg.offset;}}lastOffset && commitOffsetsIfNecessary(lastOffset as unknown as Offsets);await heartbeat();}23 unmodified lineslogsCollectedFromBatch.push(mappedData);if (index % 50 === 0) await heartbeat();config.processFn(parsedData, config);resolveOffset(msg.offset);} catch (error: any) {console.error("Failed to process message:", error); // send to dlq task-------resolveOffset(msg.offset);}index += 1;}config.handler(logsCollectedFromBatch, false);commitOffsetsIfNecessary();await heartbeat();}20 unmodified lines2122232425262728293031323334353637383940414243444567 unmodified lines11311411511611711811912012112212312412512612723 unmodified lines15115215315415515615715815916016116216316416516620 unmodified lines"deployment.logs": {mode: "batch",topic: "deployment.logs", // <------- Actual kafka topic namehandler: DeploymentEventHandler.handleLogsBatch, // Saves logs to DB as batchschema: DeploymentLogEventSchema,processFn: DeploymentEventHandler.handlerMessageEmitting, // Emits logs to other instances and frontendconsumer: consumerLogsMessages, // consumer},"deployment.updates": {mode: "single",topic: "deployment.updates", // <------- Actual kafka topic namehandler: DeploymentEventHandler.handleUpdates, // Emits updates received to other instances, frontend and also to DBschema: DeploymentUpdatesEventSchema,processFn: processLogUpdates, // Validates updates received and then passes to processFnconsumer: consumerLogsUpdates, // consumer},},analytics: {"project.analytics": {mode: "batch",topic: "project.analytics", // <------- Actual kafka topic namehandler: ProjectAnalyticsHandler.handleDataBatch, // Add analytics to DB as batchschema: analyticsEventSchema,consumer: consumerAnalyticsProjects,},67 unmodified linesconst data = JSON.parse(msg.value?.toString() as any);await config.processFn(data, config);// resolveOffset(msg.offset);lastOffset = msg.offset;} catch (error: any) {console.error("Failed to process message:", error); // send to dlq task-------, Not best to discard the data, Use dlqs for error handling// resolveOffset(msg.offset);lastOffset = msg.offset;}}// lastOffset && commitOffsetsIfNecessary(lastOffset as unknown as Offsets);await heartbeat();}23 unmodified lineslogsCollectedFromBatch.push(mappedData);if (index % 50 === 0) await heartbeat();config.processFn(parsedData, config);// resolveOffset(msg.offset);} catch (error: any) {console.error("Failed to process message:", error); // send to dlq task-------// resolveOffset(msg.offset);}index += 1;}config.handler(logsCollectedFromBatch, false);// commitOffsetsIfNecessary();await heartbeat();}
72 unmodified lines73747576777879802 unmodified lines8384858687888948 unmodified lines13813914014114214314412 unmodified lines15715815972 unmodified linesasync function commitAllMessages() {const kafka = new Kafka({clientId: `api-server`,brokers: ["pkc-l7pr2.ap-south-1.aws.confluent.cloud:9092"],ssl: true,sasl: {mechanism: "plain",username: process.env.KAFKA_USERNAME as string,2 unmodified lines});const topic = "deployment.logs";const groupId = "vercel-logs-group";const admin = kafka.admin();await admin.connect();48 unmodified lines// query: "TRUNCATE analytics"// })}getClickhouseData().then(() => process.exit(0));async function idChecker() {const obj = new Set();const id = "";12 unmodified linesconsole.log(obj);}// idChecker()72 unmodified lines737475767778798081822 unmodified lines8586878889909148 unmodified lines14014114214314414514612 unmodified lines15916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624772 unmodified linesasync function commitAllMessages() {const kafka = new Kafka({clientId: `api-server`,brokers: ["kafka-lynfera-renderstest446446-7987.f.aivencloud.com:11100"],ssl: {ca: process.env.KAFKA_CA?.replace(/\\n/g, "\n")},sasl: {mechanism: "plain",username: process.env.KAFKA_USERNAME as string,2 unmodified lines});const topic = "deployment.logs";const groupId = "lynfera-logs-group";const admin = kafka.admin();await admin.connect();48 unmodified lines// query: "TRUNCATE analytics"// })}// getClickhouseData().then(() => process.exit(0));async function idChecker() {const obj = new Set();const id = "";12 unmodified linesconsole.log(obj);}// idChecker()async function gitPushStatusChanger() {console.log("Starting ...");const repoUser = "AmalJose664/Three-d-Projects"const res = await fetch(`https://api.github.com/repos/${repoUser}/check-runs/${71949271798}`, {method: "PATCH",headers: {Authorization: `Bearer ${"token here"}`,Accept: "application/vnd.github+json","Content-Type": "application/json",},body: JSON.stringify({status: "completed",conclusion: "cancelled", // or "failure"}),});// const res = await fetch(`https://api.github.com/repos//${repoUser}/check-runs`, {// method: "POST",// headers: {// Authorization: `Bearer ${installationToken}`,// Accept: "application/vnd.github+json",// "Content-Type": "application/json",// },// body: JSON.stringify({// name: "Lynfera Deploy",// head_sha: "5ea33e0389101cbc2a6122f48397c07761692a28",// status: "in_progress",// }),// });const check = await res.json();console.log({ check });}//gitPushStatusChanger();function generateOTP(length = 6) {return Math.floor(10 ** (length - 1) + Math.random() * 9 * 10 ** (length - 1));}async function sendEmailOTP(email) {const otp = generateOTP();try {const response = await fetch("https://api.brevo.com/v3/smtp/email", {method: "POST",headers: {"Content-Type": "application/json","api-key": ""},body: JSON.stringify({sender: {name: "Your App",email: "callbackff200002@gmail.com"},to: [{ email: email }],subject: "Your OTP Code",htmlContent: `<div style="font-family: Arial; padding: 10px;"><h2>Your OTP Code</h2><p>Your OTP is:</p><h1 style="letter-spacing: 5px;">${otp}</h1><p>This code is valid for 5 minutes.</p></div>`})});const data = await response.json();if (!response.ok) {throw new Error(JSON.stringify(data));}console.log("OTP email sent:", data);return otp; // store in DB/cache for verification} catch (error) {console.error("Error sending OTP:", error.message);}}// sendEmailOTP("renderstest446446@gmail.com")
ecosystem.config.cjs+1-1
src/config/env.config.ts+2
src/config/kafka.config.ts+4-2
src/events/consumers.ts+6-2
src/events/regitry.ts+13-13
testFns.ts+92-4