Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#60): dashboards with CHT api express metrics #75

Merged
merged 19 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion development/fake-cht/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "fake-cht",
"version": "1.0.0",
"scripts": {
"start": "node src/index.js"
"start": "node --experimental-fetch src/index.js"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's wrong with Node 18? 😆

},
"dependencies": {
"express": "^4.18.2",
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