Skip to content

Commit

Permalink
added additional logging
Browse files Browse the repository at this point in the history
  • Loading branch information
gotham13 committed Apr 9, 2024
1 parent 890d8eb commit 739de53
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/routes/queue-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ router.post("/log", async (req: Request, res: Response) => {
data: log,
}))
);
console.log("Received %d Logs", logs.length);
res.json({
success: true,
});
Expand Down
7 changes: 6 additions & 1 deletion src/utils/logstash-client.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import Logstash from "./logstash";

let errorLogger = (error: Error) => {
console.log(error);
console.error(error);
};

let connectedLogger = () => {
console.log("Connection Established With Logstash");
};

export default new Logstash({
error_logger: errorLogger,
connected_logger: connectedLogger,
host: process.env.LOGSTASH_HOST,
port: process.env.LOGSTASH_PORT
? parseInt(process.env.LOGSTASH_PORT)
Expand Down
3 changes: 2 additions & 1 deletion src/utils/logstash/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default class LogstashTransport {
? new SecureConnection(options)
: new PlainConnection(options);
this.manager = new Manager(options, this.connection);
this.manager.on("connected", options.connected_logger.bind(this));
this.manager.on("error", options.error_logger.bind(this));
this.manager.start();
}
Expand All @@ -23,4 +24,4 @@ export default class LogstashTransport {
close() {
this.manager.close();
}
};
}
1 change: 1 addition & 0 deletions src/utils/logstash/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface LogstashTransportSSLOptions {

interface LogstashTransportOptions extends LogstashTransportSSLOptions {
error_logger: (...args: any[]) => void;
connected_logger: () => void;
host?: string;
port?: number;
node_name?: string;
Expand Down
11 changes: 6 additions & 5 deletions src/utils/queue-batch-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ export default async (queue: Queue, logstash: Logstash) => {
for (let job of jobs) {
jobData.push(job.data);
}
if(jobData.length>0) {
if (jobData.length > 0) {
logstash.log(jobData, async () => {
for (let job of jobs) {
await job.remove();
}
});
for (let job of jobs) {
await job.remove();
}
console.log("Pushed %d Logs To Logstash", jobData.length);
});
}
};
11 changes: 10 additions & 1 deletion src/utils/queue-client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Queue } from "bullmq";
export default new Queue("logs", {
const queue = new Queue("logs", {
connection: {
host: process.env.REDIS_HOST,
username: process.env.REDIS_USERNAME,
Expand All @@ -11,3 +11,12 @@ export default new Queue("logs", {
},
prefix: process.env.QUEUE_PREFIX,
});

async function checkQueueHealth(queue: Queue) {
const jobCounts = await queue.getJobCounts();
console.log("Connection Established With Redis Queue", jobCounts);
}

checkQueueHealth(queue);

export default queue;

0 comments on commit 739de53

Please sign in to comment.