Skip to content

Commit

Permalink
feat(#60): CHT API Server and CHT Replication dashboards (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennsippell committed Sep 21, 2023
1 parent 2a56a1b commit e57487d
Show file tree
Hide file tree
Showing 5 changed files with 3,402 additions and 0 deletions.
3 changes: 3 additions & 0 deletions development/fake-cht/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions development/fake-cht/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"scripts": {
"start": "node src/index.js"
},
"engines" : {
"node" : ">=18.0.0"
},
"dependencies": {
"express": "^4.18.2",
"pg": "^8.10.0",
Expand Down
31 changes: 31 additions & 0 deletions development/fake-cht/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,40 @@ try {
app.use(prometheusMiddleware({
metricsPath: '/api/v1/express-metrics',
metricsPrefix: 'cht_api',
// based on one-month analysed period of production traffic
durationBuckets: [
0.004, 0.007, 0.013, 0.025, 0.05,
0.1, 0.25, 0.5, 1, 2,
3, 5, 7.5, 10, 25,
45, 90, 180, 360, 600,
1200, 1800, 3600
],
}));

const replicationRoutes = [
'/api/v1/replication/get-ids',
'/api/v1/initial-replication/get-ids'
];

app.get(replicationRoutes, (req, res) => {
const timeout = getRandomInt(0, 5000);
setTimeout(() => {
if (timeout > 4000) {
res
.status(504)
.send({ message: 'Timeout' });
return;
}
res.json({ id: new Date().getTime() });
}, timeout);
});

app.get('/api/v2/monitoring', (req, res) => {
// generate requests to other endpoints
replicationRoutes.forEach(replicationRoute => {
fetch(`http://fake-cht:8081${replicationRoute}`);
});

const metrics = {
version: getVersion(),
couchdb: getAllCouchDbs(lastResponse.couchdb),
Expand Down
Loading

0 comments on commit e57487d

Please sign in to comment.