Skip to content

Commit 54e10c6

Browse files
committed
PEER-244,245: Add Matching Service
TODO: Debug redis connection issues with client code in container Signed-off-by: SeeuSim <[email protected]>
1 parent acedb1a commit 54e10c6

File tree

10 files changed

+112
-13
lines changed

10 files changed

+112
-13
lines changed

backend/matching/.env.compose

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ EXPRESS_PORT=9004
77

88
MATCHING_DB_USERNAME="peerprep-match-express"
99
MATCHING_DB_PASSWORD="G7jBgyz9wGAFQ5La"
10-
REDIS_ARGS="--requirepass G7jBgyz9wGAFQ5La --user ${MATCHING_DB_USERNAME} on >G7jBgyz9wGAFQ5La ~* allcommands --user default off nopass nocommands"
10+
REDIS_ARGS="--requirepass G7jBgyz9wGAFQ5La --user peerprep-match-express on >G7jBgyz9wGAFQ5La ~* allcommands --user default off nopass nocommands"

backend/matching/src/lib/db/client.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@ class RedisClient {
1313
host: DB_HOSTNAME,
1414
port: DB_PORT,
1515
},
16-
}).on('error', (err) => {
17-
logger.error(`Redis Client error: ${err}`);
18-
});
16+
})
17+
.on('error', (err) => {
18+
const { name, message, stack, cause } = err as Error;
19+
logger.error({ name, message, stack, cause }, 'Redis Client error');
20+
})
21+
.on('connect', () => {
22+
logger.info('Redis Client connected');
23+
});
1924
}
2025
}
2126

backend/matching/src/lib/db/seed.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const main = async () => {
2424
return;
2525
}
2626

27-
logger.info('Connected');
2827
const isSeeded = await redisClient.hGetAll(SEED_KEY);
2928

3029
if (Object.keys(isSeeded).length > 0) {

backend/question/.env.compose

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# PEERPREP_UI_HOST="http://frontend:3000"
33

44
EXPRESS_PORT=9002
5-
EXPRESS_DB_HOST="qn-db"
6-
EXPRESS_DB_PORT=5433
5+
EXPRESS_DB_HOST="question-db"
6+
EXPRESS_DB_PORT=5432
77
POSTGRES_DB="question"
88
POSTGRES_USER="peerprep-qn-express"
99
POSTGRES_PASSWORD="Xk8qEcEI2sizjfEn/lF6mLqiyBECjIHY3q6sdXf9poQ="

backend/question/src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ export const dbConfig = {
1212
password: process.env.POSTGRES_PASSWORD,
1313
};
1414

15-
export const LOAD_TEST_POD = process.env.LOAD_TEST_POD || 'http://user-service-load-test';
15+
export const LOAD_TEST_POD = process.env.LOAD_TEST_POD || 'http://question-service-load-test';

k8s/03-match-db-service.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ spec:
1414
ports:
1515
- name: match-db-6379
1616
port: 6379
17-
targetPort: user-db-6379
17+
targetPort: match-db-6379

k8s/04-match-svc-deployment.yaml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: matching-service
5+
namespace: peerprep
6+
labels:
7+
project: peerprep
8+
peerprep.service: matching-service
9+
spec:
10+
replicas: 1
11+
selector:
12+
matchLabels:
13+
project: peerprep
14+
peerprep.service: matching-service
15+
strategy:
16+
type: Recreate
17+
template:
18+
metadata:
19+
labels:
20+
project: peerprep
21+
peerprep.service: matching-service
22+
peerprep.network.match-api: "true"
23+
peerprep.network.match-db: "true"
24+
spec:
25+
initContainers:
26+
- name: wait-for-redis
27+
image: redis:alpine
28+
env:
29+
- name: MATCHING_DB_USER
30+
valueFrom:
31+
secretKeyRef:
32+
name: matching-secret
33+
key: MATCHING_DB_PASSWORD
34+
- name: MATCHING_DB_PASSWORD
35+
valueFrom:
36+
secretKeyRef:
37+
name: matching-secret
38+
key: MATCHING_DB_PASSWORD
39+
- name: MATCHING_DB_HOST
40+
value: match-db
41+
command:
42+
- /bin/sh
43+
- -c
44+
- |
45+
# until REDISCLI_AUTH="$MATCHING_DB_PASSWORD" redis-cli -h match-db --user "$MATCHING_DB_USER" ping; do
46+
until redis-cli -h match-db ping; do
47+
echo "Waiting for Redis to be ready..."
48+
sleep 1
49+
done
50+
echo "Redis is Healthy"
51+
52+
containers:
53+
- name: match-express
54+
image: ay2425s1cs3219g16/match-express:main
55+
imagePullPolicy: IfNotPresent
56+
envFrom:
57+
- secretRef:
58+
name: matching-secret
59+
livenessProbe:
60+
exec:
61+
command:
62+
- /bin/sh
63+
- -c
64+
- wget --no-verbose --tries=1 --spider http://localhost:9004/health || exit 1
65+
periodSeconds: 30
66+
initialDelaySeconds: 5
67+
timeoutSeconds: 10
68+
failureThreshold: 5
69+
ports:
70+
- name: match-svc-ctr
71+
containerPort: 9004
72+
resources:
73+
requests:
74+
cpu: 500m
75+
memory: 512Mi
76+
limits:
77+
cpu: 1
78+
memory: 1Gi
79+

k8s/04-match-svc-service.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: matching-service
5+
namespace: peerprep
6+
labels:
7+
project: peerprep
8+
peerprep.service: matching-service
9+
spec:
10+
type: ClusterIP
11+
selector:
12+
project: peerprep
13+
peerprep.service: matching-service
14+
ports:
15+
- name: match-svc-prt
16+
port: 9004
17+
targetPort: match-svc-ctr

k8s/04-question-svc-deployment.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ spec:
6464
containers:
6565
- name: question-express
6666
image: ay2425s1cs3219g16/question-express:main
67-
# image: ay2425s1cs3219g16/question-express:sha-ff94455
6867
imagePullPolicy: IfNotPresent
6968
envFrom:
7069
- secretRef:
@@ -83,7 +82,7 @@ spec:
8382
timeoutSeconds: 10
8483
failureThreshold: 5
8584
ports:
86-
- name: question-svc-ctr
85+
- name: qn-svc-ctr
8786
containerPort: 9002
8887
resources:
8988
requests:

k8s/04-question-svc-service.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ spec:
1212
project: peerprep
1313
peerprep.service: question-service
1414
ports:
15-
- name: question-svc-prt
15+
- name: qn-svc-prt
1616
port: 9002
17-
targetPort: question-svc-ctr
17+
targetPort: qn-svc-ctr

0 commit comments

Comments
 (0)