Skip to content

Commit e57487d

Browse files
authored
feat(#60): CHT API Server and CHT Replication dashboards (#75)
1 parent 2a56a1b commit e57487d

File tree

5 files changed

+3402
-0
lines changed

5 files changed

+3402
-0
lines changed

development/fake-cht/package-lock.json

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

development/fake-cht/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
"scripts": {
55
"start": "node src/index.js"
66
},
7+
"engines" : {
8+
"node" : ">=18.0.0"
9+
},
710
"dependencies": {
811
"express": "^4.18.2",
912
"pg": "^8.10.0",

development/fake-cht/src/index.js

+31
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,40 @@ try {
116116
app.use(prometheusMiddleware({
117117
metricsPath: '/api/v1/express-metrics',
118118
metricsPrefix: 'cht_api',
119+
// based on one-month analysed period of production traffic
120+
durationBuckets: [
121+
0.004, 0.007, 0.013, 0.025, 0.05,
122+
0.1, 0.25, 0.5, 1, 2,
123+
3, 5, 7.5, 10, 25,
124+
45, 90, 180, 360, 600,
125+
1200, 1800, 3600
126+
],
119127
}));
120128

129+
const replicationRoutes = [
130+
'/api/v1/replication/get-ids',
131+
'/api/v1/initial-replication/get-ids'
132+
];
133+
134+
app.get(replicationRoutes, (req, res) => {
135+
const timeout = getRandomInt(0, 5000);
136+
setTimeout(() => {
137+
if (timeout > 4000) {
138+
res
139+
.status(504)
140+
.send({ message: 'Timeout' });
141+
return;
142+
}
143+
res.json({ id: new Date().getTime() });
144+
}, timeout);
145+
});
146+
121147
app.get('/api/v2/monitoring', (req, res) => {
148+
// generate requests to other endpoints
149+
replicationRoutes.forEach(replicationRoute => {
150+
fetch(`http://fake-cht:8081${replicationRoute}`);
151+
});
152+
122153
const metrics = {
123154
version: getVersion(),
124155
couchdb: getAllCouchDbs(lastResponse.couchdb),

0 commit comments

Comments
 (0)