Skip to content

Commit

Permalink
feat: add redis to meta
Browse files Browse the repository at this point in the history
  • Loading branch information
bigint committed Jul 10, 2024
1 parent 7a2587b commit 1a7841c
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions apps/api/src/routes/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import catchedError from 'src/helpers/catchedError';
import { SCORE_WORKER_URL } from 'src/helpers/constants';
import createClickhouseClient from 'src/helpers/createClickhouseClient';
import { rateLimiter } from 'src/helpers/middlewares/rateLimiter';
import redisClient from 'src/helpers/redis';

const measureQueryTime = async (
queryFunction: () => Promise<any>
Expand All @@ -28,6 +29,7 @@ export const get = [
const lensPromise = measureQueryTime(() =>
lensPg.query(`SELECT 1 as count;`)
);
const redisPromise = measureQueryTime(() => redisClient.get('ping'));
const clickhouseClient = createClickhouseClient();
const clickhousePromise = measureQueryTime(() =>
clickhouseClient.query({
Expand All @@ -42,23 +44,33 @@ export const get = [
);

// Execute all promises simultaneously
const [heyResult, lensResult, clickhouseResult, scoreWorkerResult] =
await Promise.all([
heyPromise,
lensPromise,
clickhousePromise,
scoreWorkerPromise
]);
const [
heyResult,
lensResult,
redisResult,
clickhouseResult,
scoreWorkerResult
] = await Promise.all([
heyPromise,
lensPromise,
redisPromise,
clickhousePromise,
scoreWorkerPromise
]);

console.log(redisResult);

// Check responses
const [hey, heyTime] = heyResult;
const [lens, lensTime] = lensResult;
const [redis, redisTime] = redisResult;
const [clickhouseRows, clickhouseTime] = clickhouseResult;
const [scoreWorker, scoreWorkerTime] = scoreWorkerResult;

if (
Number(hey[0].count) !== 1 ||
Number(lens[0].count) !== 1 ||
redis.toString() !== 'pong' ||
scoreWorker.data.split(' ')[0] !== 'WITH' ||
!clickhouseRows.json
) {
Expand All @@ -75,6 +87,7 @@ export const get = [
clickhouse: `${Number(clickhouseTime / BigInt(1000000))}ms`,
hey: `${Number(heyTime / BigInt(1000000))}ms`,
lens: `${Number(lensTime / BigInt(1000000))}ms`,
redis: `${Number(redisTime / BigInt(1000000))}ms`,
scoreWorker: `${Number(scoreWorkerTime / BigInt(1000000))}ms`
}
});
Expand Down

0 comments on commit 1a7841c

Please sign in to comment.