Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Two Readiness checks #2

Closed
jahluwalia opened this issue Nov 1, 2018 · 2 comments
Closed

Two Readiness checks #2

jahluwalia opened this issue Nov 1, 2018 · 2 comments
Assignees

Comments

@jahluwalia
Copy link

jahluwalia commented Nov 1, 2018

I originally posted this in cloud-health, but have moved it here.

I registered two readiness checks (one to check a valid mongodb connection, one to check a valid redis connection). If I call resolve on the second (redis), but not the first (mongo), my status is still UP. Shouldn't it be still STARTING? If i hit the /ready api, the returned checks array is emtpy.

If I swap out registerReadinessCheck for registerLIvenessCheck both the /ready and /health routes return both checks, but the states are still off.

Here is the code:

I initialize as follows:

const health = require('@cloudnative/health-connect');
    let healthcheck = new health.HealthChecker();

Create some readiness checks:

//READINESS CHECK - MONGO
const dbConnection = new Promise(function(resolve, _reject) {
  var mongoose = require('mongoose');
  var mongoDB = 'mongodb://localhost:1234/db';
  mongoose.connect(mongoDB);
  mongoose.connect(mongoDB).then(
    () => {
      console.log('mongo connected');
      //resolve();
    },
    err => {
      //error
      console.log(err);
      _reject();
    }
  );
  // Get Mongoose to use the global promise library
  mongoose.Promise = global.Promise;

  //resolve();
});
let dbCheck = new health.ReadinessCheck('mongoCheck', dbConnection);
healthcheck.registerReadinessCheck(dbCheck);

//READINESS CHECK - REDIS
const redisConnection = new Promise(function(resolve, _reject) {

  var redis = require('./api/helpers/redisClient.js');

  redis.on('ready', function() {
    resolve();
    console.log('redis');
  });

  redis.on('error', function() {
    _reject();
  });

});
let redisCheck = new health.ReadinessCheck('redisCheck', redisConnection);
healthcheck.registerReadinessCheck(redisCheck);

And later on I do the following:

app.use('/health', health.LivenessEndpoint(healthcheck));
app.use('/ready', health.ReadinessEndpoint(healthcheck));

In summary my questions are:

  1. why is the status UP when the mongo check isn't calling resolve
  2. why are the returned checks an empty array?
  3. if i convert readinesscheck to livenesscheck, why do both health and ready routes show STARTING that contain both the mongo check and redis check?

Thanks,
Jas

@seabaylea
Copy link
Member

@gdams can you take a look?

gdams pushed a commit to gdams/cloud-health that referenced this issue Nov 30, 2018
Fixes an issue where you have two readiness checks (the first not ready and the
second being ready. This now keep the readiness set as `STARTING` rather than `UP`

Issue number: CloudNativeJS/cloud-health-connect#2
gdams pushed a commit to CloudNativeJS/cloud-health that referenced this issue Dec 3, 2018
* Fix issue with Two Readiness checks

Fixes an issue where you have two readiness checks (the first not ready and the
second being ready. This now keep the readiness set as `STARTING` rather than `UP`

Issue number: CloudNativeJS/cloud-health-connect#2

* add more coverage

* add coveralls as dev dep
gdams pushed a commit to gdams/cloud-health-connect that referenced this issue Dec 3, 2018
@gdams gdams closed this as completed in #3 Dec 3, 2018
@gdams
Copy link
Member

gdams commented Dec 3, 2018

fixed in 1.0.2

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants