Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 930b84a

Browse files
authored
Merge pull request #19 from topcoder-platform/develop
bringing prod up to date
2 parents d143e04 + 2ce82ac commit 930b84a

24 files changed

+2282
-2959
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ node_modules/
44
.DS_Store
55
.nyc_output
66
coverage/
7-
.env
7+
*.env

.vscode/launch.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"name": "Launch Program",
11+
"envFile": "${workspaceFolder}/dev.env",
12+
"skipFiles": [
13+
"<node_internals>/**"
14+
],
15+
"program": "${workspaceFolder}/src/app.js"
16+
17+
}
18+
]
19+
}

README.md

Lines changed: 56 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
## Dependencies
44

5-
- nodejs https://nodejs.org/en/ (v10)
5+
- Nodejs (v10)
66
- Kafka (v2)
7-
- Mongodb (v4)
87

98
## Configuration
109

@@ -20,15 +19,26 @@ The following parameters can be set in config files or in env variables:
2019
- KAFKA_CLIENT_CERT_KEY: Kafka connection private key, optional;
2120
if not provided, then SSL connection is not used, direct insecure connection is used;
2221
if provided, it can be either path to private key file or private key content
22+
- KAFKA_GROUP_ID: Kafka group id
2323
- CREATE_DATA_TOPIC: Kafka topic related to creation
2424
- UPDATE_DATA_TOPIC: Kafka topic related to update
2525
- DELETE_DATA_TOPIC: Kafka topic related to deletion
26-
- GROUP_IDS: List of Group IDs which should be used for filtering
26+
- LEADERBOARD_API_URL: Leaderboard API URL
2727
- SUBMISSION_API_URL: Submission API URL
28-
- CHALLENGE_API_URL: Challenge API URL
29-
- MEMBER_API_URL: Member API URL
30-
- All variables starting with prefix `AUTH0` corresponds to Auth0 related credentials
31-
- MONGODB_URL: Mongo DB URL
28+
- AUTH0_URL: Auth0 URL, used to get TC M2M token
29+
- AUTH0_AUDIENCE: Auth0 audience, used to get TC M2M token
30+
- TOKEN_CACHE_TIME: Auth0 token cache time, used to get TC M2M token
31+
- AUTH0_CLIENT_ID: Auth0 client id, used to get TC M2M token
32+
- AUTH0_CLIENT_SECRET: Auth0 client secret, used to get TC M2M token
33+
- AUTH0_PROXY_SERVER_URL: Proxy Auth0 URL, used to get TC M2M token
34+
35+
Also note that there is a `/health` endpoint that checks for the health of the app. This sets up an expressjs server and listens on the environment variable `PORT`. It's not part of the configuration file and needs to be passed as an environment variable
36+
37+
Configuration for the tests is at `config/test.js`, only add such new configurations different from `config/default.js`
38+
39+
- WAIT_TIME: wait time used in test, default is 1000 or one second
40+
- LEADERBOARD_API_URL: Leaderboard API URL used in testing
41+
- SUBMISSION_API_URL: Submission API URL used in testing
3242

3343
## Local Kafka setup
3444

@@ -47,7 +57,7 @@ The following parameters can be set in config files or in env variables:
4757
```bash
4858
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic submission.notification.create
4959
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic submission.notification.update
50-
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic notifications.autopilot.events
60+
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic submission.notification.delete
5161
```
5262

5363
- verify that the topics are created:
@@ -58,7 +68,7 @@ The following parameters can be set in config files or in env variables:
5868
- In the console, write some message, one message per line:
5969

6070
```bash
61-
{ "topic":"submission.notification.create", "originator":"submission-api", "timestamp":"2018-08-06T15:46:05.575Z", "mime-type":"application/json", "payload":{ "resource":"review", "id": "d34d4180-65aa-42ec-a945-5fd21dec0502", "score": 92.0, "typeId": "c56a4180-65aa-42ec-a945-5fd21dec0501", "reviewerId": "c23a4180-65aa-42ec-a945-5fd21dec0503", "scoreCardId": "b25a4180-65aa-42ec-a945-5fd21dec0503", "submissionId": "fad49103-37ac-4a04-8294-c840483178a5", "created": "2018-05-20T07:00:30.123Z", "updated": "2018-06-01T07:36:28.178Z", "createdBy": "admin", "updatedBy": "admin" } }
71+
{"topic":"submission.notification.create","originator":"submission-api","timestamp":"2018-08-06T15:46:05.575Z","mime-type":"application/json","payload":{"resource":"review","id":"49871146-eb0a-4d0e-ab9a-adc94018c5da","submissionId":"6ff0c009-51ee-4c8e-aa0d-159c20503cc2","score":-1,"scoreCardId":30001852,"metadata":{"testType":"provisional","tests":{"pending":0,"failed":1,"total":10}},"created":"2019-11-06T15:02:35.539Z","updated":"2019-11-06T15:02:35.539Z","createdBy":"I3etJtTqlz1XHgCXduBN1us705ufrykl@clients","updatedBy":"I3etJtTqlz1XHgCXduBN1us705ufrykl@clients","status":"completed","reviewerId":"0301619c-3d9e-44c3-85cb-c20311100f7f","typeId":"52c91e85-745f-4e62-b592-9879a2dfe9fd"}}
6272
```
6373

6474
- optionally, use another terminal, go to same directory, start a consumer to view the messages:
@@ -97,65 +107,71 @@ npm start
97107
- git add .
98108
- git commit -m init
99109
- heroku create
100-
- heroku config:set KAFKA_URL=... AUTH0_URL=...
110+
- heroku config:set KAFKA_URL=... AUTH0_URL=...
101111
- git push heroku master
102112

103113
## Verification
104114

105-
1. Ensure that Kafka is up and running and the topics `submission.notification.create, submission.notification.update and notifications.autopilot.events` are created in Kafka
115+
1. Ensure that Kafka is up and running and the topics `submission.notification.create, submission.notification.update and submission.notification.delete` are created in Kafka
106116

107-
2. Ensure that MONGODB_URL configured is correct and ensure that Submission API URL is pointing to `https://api.topcoder-dev.com/v5/submissions` (To verify based on the data present in Dev)
117+
2. Refer `README.md` in `leaderboard-api` to start leaderboard api, all operations are under `leaderboard-api` project root folder
108118

109-
3. Attach to the topic `submission.notification.create` using Kafka console producer
119+
3. Set the necessary environment variables and then run `npm start` command to start processor app(Under this project's root folder)
110120

111-
```bash
112-
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic submission.notification.create
113-
```
121+
4. Attach to the topic `submission.notification.create` using Kafka console producer
114122

115-
4. Write the following message to the Console
123+
```bash
124+
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic submission.notification.create
125+
```
116126

117-
```bash
118-
{ "topic":"submission.notification.create", "originator":"submission-api", "timestamp":"2018-08-06T15:46:05.575Z", "mime-type":"application/json", "payload":{ "resource":"reviewSummation", "id": "d24d4180-65aa-42ec-a945-5fd21dec0507", "aggregateScore": 87.5, "isPassing": true, "scoreCardId": "b25a4180-65aa-42ec-a945-5fd21dec0503", "submissionId": "fad49103-37ac-4a04-8294-c840483178a5", "created": "2018-05-20T07:00:30.123Z", "updated": "2018-06-01T07:36:28.178Z", "createdBy": "admin", "updatedBy": "admin" } }
119-
```
127+
5. Write the following message to the Console
120128

121-
5. You could see in the console that message will be processed
129+
```bash
130+
{"topic":"submission.notification.create","originator":"submission-api","timestamp":"2018-08-06T15:46:05.575Z","mime-type":"application/json","payload":{"resource":"review","id":"49871146-eb0a-4d0e-ab9a-adc94018c5da","submissionId":"6ff0c009-51ee-4c8e-aa0d-159c20503cc2","score":-1,"scoreCardId":30001852,"metadata":{"testType":"provisional","tests":{"pending":0,"failed":1,"total":10}},"created":"2019-11-06T15:02:35.539Z","updated":"2019-11-06T15:02:35.539Z","createdBy":"I3etJtTqlz1XHgCXduBN1us705ufrykl@clients","updatedBy":"I3etJtTqlz1XHgCXduBN1us705ufrykl@clients","status":"completed","reviewerId":"0301619c-3d9e-44c3-85cb-c20311100f7f","typeId":"52c91e85-745f-4e62-b592-9879a2dfe9fd"}}
131+
```
122132

123-
6. Data in the Database could be verified directly or by using the `/leaderboard` end point
133+
6. You could see in the console that message will be processed, and find the following message: `Record with Challenge ID # 30051825 and Member ID # 8547899 does not exists in database. Creating the record`. Also check the leaderboard-api console for more information(Console in step 2)
124134

125-
7. Open Postman and import the environment, collection in `docs` directory
135+
7. Attach to the topic `submission.notification.update` using Kafka console producer
126136

127-
8. Trigger the `leaderboard` end point to the verify the data present in Mongo DB
137+
```bash
138+
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic submission.notification.update
139+
```
128140

129-
9. Attach to the topic `submission.notifcation.update` using Kafka console producer and write the below message
141+
8. Write the following message to the Console
130142

131-
```bash
132-
{ "topic":"submission.notification.update", "originator":"submission-api", "timestamp":"2018-08-06T15:46:05.575Z", "mime-type":"application/json", "payload":{ "resource":"reviewSummation", "id": "d24d4180-65aa-42ec-a945-5fd21dec0507", "aggregateScore": 85.83 } }
133-
```
143+
```bash
144+
{"topic":"submission.notification.update","originator":"submission-api","timestamp":"2018-08-06T15:46:05.575Z","mime-type":"application/json","payload":{"resource":"review","id":"49871146-eb0a-4d0e-ab9a-adc94018c5da","submissionId":"6ff0c009-51ee-4c8e-aa0d-159c20503cc2","score":52,"scoreCardId":30001852,"metadata":{"testType":"provisional","tests":{"pending":0,"failed":2,"total":8}},"created":"2019-11-06T15:02:35.539Z","updated":"2019-11-06T15:02:35.539Z","createdBy":"I3etJtTqlz1XHgCXduBN1us705ufrykl@clients","updatedBy":"I3etJtTqlz1XHgCXduBN1us705ufrykl@clients","status":"completed","reviewerId":"0301619c-3d9e-44c3-85cb-c20311100f7f","typeId":"52c91e85-745f-4e62-b592-9879a2dfe9fd"}}
145+
```
134146

135-
10. Validate the data using Postman
147+
9. You could see in the console that message will be processed, and find the following message: `Record with Challenge ID # 30051825 and Member ID # 8547899 exists in database. Updating the score`. Also check the leaderboard-api console for more information(Console in step 2)
136148

137-
11. Attach to the topic `submission.notifcation.delete` using Kafka console producer and write the below message
149+
10. Attach to the topic `submission.notification.delete` using Kafka console producer
138150

139-
```bash
140-
{ "topic":"submission.notification.delete", "originator":"submission-api", "timestamp":"2018-08-06T15:46:05.575Z", "mime-type":"application/json", "payload":{ "resource":"reviewSummation", "id": "d24d4180-65aa-42ec-a945-5fd21dec0507" } }
141-
```
151+
```bash
152+
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic submission.notification.delete
153+
```
154+
155+
11. Write the following message to the Console. Also check the leaderboard-api console for more information(Console in step 2)
142156

143-
12. Validate the data using Postman
157+
```bash
158+
{ "topic":"submission.notification.delete", "originator":"submission-api", "timestamp":"2018-08-06T15:46:05.575Z", "mime-type":"application/json", "payload":{ "resource":"review", "id": "49871146-eb0a-4d0e-ab9a-adc94018c5da" } }
159+
```
144160
145-
## Running unit tests and coverage
161+
12. You could see in the console that message will be processed
146162
147-
To run tests, following Environment variables need to be set up
163+
## Tests
148164
149-
- TEST_MONGODB_URL MongoDB URL pointing to Test DB instance
165+
Note: you need to stop the processor app before execute test.
150166
151-
To run unit tests alone
167+
- Run the following command to execute unit test and generate coverage report
152168
153169
```bash
154170
npm run test
155171
```
156172
157-
To run unit tests with coverage report
173+
- Run the following command to execute e2e test and generate coverage report
158174
159175
```bash
160-
npm run cov
176+
npm run e2e
161177
```

config/default.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,21 @@ module.exports = {
1212
KAFKA_CLIENT_CERT: process.env.KAFKA_CLIENT_CERT,
1313
KAFKA_CLIENT_CERT_KEY: process.env.KAFKA_CLIENT_CERT_KEY,
1414

15+
KAFKA_GROUP_ID: process.env.KAFKA_GROUP_ID || 'tc-leaderboard-processor',
16+
1517
// Kafka topics related to Creation, Update and Delete
1618
CREATE_DATA_TOPIC: process.env.CREATE_DATA_TOPIC || 'submission.notification.create',
1719
UPDATE_DATA_TOPIC: process.env.UPDATE_DATA_TOPIC || 'submission.notification.update',
1820
DELETE_DATA_TOPIC: process.env.DELETE_DATA_TOPIC || 'submission.notification.delete',
1921

20-
GROUP_IDS: process.env.GROUP_IDS || '202343,20000000', // Comma separated string of Group IDs
21-
22+
LEADERBOARD_API_URL: process.env.LEADERBOARD_API_URL || 'https://api.topcoder-dev.com/v5/leaderboard',
2223
SUBMISSION_API_URL: process.env.SUBMISSION_API_URL || 'https://api.topcoder-dev.com/v5/submissions',
23-
REVIEW_SUMMATION_API_URL: process.env.REVIEW_SUMMATION_API_URL || 'https://api.topcoder-dev.com/v5/reviewSummations',
24-
CHALLENGE_API_URL: process.env.CHALLENGE_API_URL || 'https://api.topcoder-dev.com/v3/challenges',
25-
MEMBER_API_URL: process.env.MEMBER_API_URL || 'https://api.topcoder-dev.com/v3/users',
24+
REVIEW_TYPE_URL: process.env.REVIEW_TYPE_URL || 'https://api.topcoder-dev.com/v5/reviewTypes',
2625

27-
AUTH0_URL: process.env.AUTH0_URL, // Auth0 credentials for Leaderboard Service
26+
AUTH0_URL: process.env.AUTH0_URL,
2827
AUTH0_AUDIENCE: process.env.AUTH0_AUDIENCE,
2928
TOKEN_CACHE_TIME: process.env.TOKEN_CACHE_TIME,
3029
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID,
3130
AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET,
32-
AUTH0_PROXY_SERVER_URL: process.env.AUTH0_PROXY_SERVER_URL,
33-
MONGODB_URL: process.env.MONGODB_URL || 'mongodb://localhost:27017/leaderboardDB'
31+
AUTH0_PROXY_SERVER_URL: process.env.AUTH0_PROXY_SERVER_URL
3432
}

config/test.js

100755100644
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
/**
2-
* Configuration file to be used while running tests
2+
* The configuration file.
33
*/
44

55
module.exports = {
6-
MONGODB_URL: process.env.TEST_MONGODB_URL || 'mongodb://localhost:27017/leaderboardTestDB'
6+
LEADERBOARD_API_URL: 'https://api.topcoder-dev.com/v5/leaderboard',
7+
SUBMISSION_API_URL: 'https://api.topcoder-dev.com/v5/submissions',
8+
WAIT_TIME: 1000
79
}

0 commit comments

Comments
 (0)