[API] Add broker API

This commit is contained in:
Oleg Shuralev 2020-01-08 01:00:26 +03:00
parent 994a140aba
commit 338fee267a
No known key found for this signature in database
GPG key ID: 0459DF80E1A2FD1B
3 changed files with 56 additions and 5 deletions

View file

@ -0,0 +1,25 @@
const randomBrokerMetrics = () => ({
bytesInPerSec: Math.ceil(Math.random() * 10000),
brokerCount: 1,
zooKeeperStatus: 1,
activeControllers: 1,
uncleanLeaderElectionCount: 0,
networkPoolUsage: Math.random(),
requestPoolUsage: Math.random(),
onlinePartitionCount: Math.ceil(Math.random() * 1000),
underReplicatedPartitionCount: Math.ceil(Math.random() * 10),
offlinePartitionCount: Math.ceil(Math.random() * 10),
diskUsage: [
{
brokerId: 1,
segmentSize: Math.ceil(Math.random() * 1_000_000_000),
},
],
diskUsageDistribution: 'even',
});
module.exports = {
'wrYGf-csNgiGdK7B_ADF7Z': randomBrokerMetrics(),
'dMMQx-WRh77BKYas_g2ZTz': randomBrokerMetrics(),
};

21
api/mocks/brokers.js Normal file
View file

@ -0,0 +1,21 @@
const randomBroker = () => ({
bytesInPerSec: Math.ceil(Math.random() * 10000),
bytesOutPerSec: Math.ceil(Math.random() * 10000),
segmentSize: Math.ceil(Math.random() * 1_000_000_000),
partitionReplicas: 134,
});
module.exports = {
'wrYGf-csNgiGdK7B_ADF7Z': [
{
brokerId: 1,
...randomBroker(),
},
],
'dMMQx-WRh77BKYas_g2ZTz': [
{
brokerId: 2,
...randomBroker(),
},
],
};

View file

@ -1,11 +1,16 @@
'use strict' 'use strict'
module.exports = function (fastify, opts, next) { const brokers = require('../mocks/brokers');
fastify.get('/brokers', function (request, reply) { const brokerMetrics = require('../mocks/brokerMetrics');
reply.send([
]); module.exports = function (fastify, opts, next) {
}); fastify
.get('/clusters/:clusterId/brokers', function (request, reply) {
reply.send(brokers[request.params.clusterId]);
})
.get('/clusters/:clusterId/metrics/broker', function (request, reply) {
reply.send(brokerMetrics[request.params.clusterId]);
});
next(); next();
} }