Skip to content

Commit 7c1bc9f

Browse files
author
Vikas Agarwal
committed
Testing new improved health check
1 parent 0da69ca commit 7c1bc9f

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

connect/service.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ const getUsersById = (ids) => {
166166
* @return {Promise} resolves to the list of user details
167167
*/
168168
const getUsersByHandle = (handles) => {
169-
const query = _.map(handles, (handle) => 'handle:"' + handle.trim().replace('"', '\\"') + '"').join(' OR ');
169+
const query = _.map(handles, (handle) => 'handle:' + handle.trim()).join(' OR ');
170170
return M2m.getMachineToken(config.AUTH0_CLIENT_ID, config.AUTH0_CLIENT_SECRET)
171171
.catch((err) => {
172172
err.message = 'Error generating m2m token: ' + err.message;

src/app.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,37 @@ function startKafkaConsumer(handlers, notificationServiceHandlers) {
7575
});
7676
});
7777

78+
var latestSubscriptions = null;
79+
7880
const check = function () {
79-
logger.debug('Checking Health...') ;
81+
logger.debug("Checking health");
8082
if (!consumer.client.initialBrokers && !consumer.client.initialBrokers.length) {
8183
logger.debug('Found unhealthy Kafka Brokers...');
8284
return false;
8385
}
8486
let connected = true;
87+
let currentSubscriptions = consumer.subscriptions;
88+
for(var sIdx in currentSubscriptions) {
89+
// current subscription
90+
let sub = currentSubscriptions[sIdx];
91+
// previous subscription
92+
let prevSub = latestSubscriptions ? latestSubscriptions[sIdx] : null;
93+
// levarage the `paused` field (https://github.com/oleksiyk/kafka/blob/master/lib/base_consumer.js#L66) to
94+
// determine if there was a possibility of an unhandled exception. If we find paused status for the same
95+
// topic in two consecutive health checks, we assume it was stuck because of unhandled error
96+
if (prevSub && prevSub.paused && sub.paused) {
97+
logger.error(`Found subscription for ${sIdx} in paused state for consecutive health checks`);
98+
return false;
99+
}
100+
}
101+
// stores the latest subscription status in global variable
102+
latestSubscriptions = consumer.subscriptions;
85103
consumer.client.initialBrokers.forEach(conn => {
86-
logger.debug(`url ${conn.server()} - connected=${conn.connected}`);
87-
connected = conn.connected & connected;
104+
logger.debug(`url ${conn.server()} - connected=${conn.connected}`)
105+
connected = conn.connected & connected
88106
});
89-
logger.debug('Found all Kafka Brokers healthy...');
90-
return connected;
91-
};
107+
return connected
108+
}
92109

93110
consumer
94111
.init()

0 commit comments

Comments
 (0)