GithubHelp home page GithubHelp logo

gdams / cloud-health Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cloudnativejs/cloud-health

1.0 2.0 0.0 21 KB

A core Health Check module for use in building a health endpoint for Kubernetes

License: Apache License 2.0

TypeScript 100.00%

cloud-health's Introduction

Cloud Health

Build status Coverage Status Module LTS Adopted IBM Support

A core library to provide application lifecycle handling and liveness checks for Node.js applications.

Cloud Health is used by Cloud Health Connect to provide a Connect Middleware for use in Express.js, Loopback and other frameworks that provides:

  • Readiness checks
  • Liveness checks
  • Shutdown handling

for use with Kubernetes and Cloud Foundry based clouds.

Using Cloud Health

Cloud Health allows you to register promises which are executed during the three phases of your application, and allows you to call getStatus() to return a promise which resolves to whether the application is STARTING, UP, DOWN, STOPPING or STOPPED.

  1. At startup for "readiness"
    Promises that are created as part of a ReadinessCheck and registered using registerReadinessCheck are executed at startup and can be used to execute any code that must complete before your application is ready. If the startup promises are still running, calls to getStatus() return STARTING. Once the promises complete, DOWN is reported if there were any failures, or the "liveness" promises are then executed.

  2. At runtimes for "liveness"
    Promises that are created as part of a LivenessCheck and registered using registerReadinessCheck are executed on calls to getStatus(). These can be used to ensure that the application is still running correctly. If no promises are registered, or the complete successfully, UP is reported. If there are any failures, DOWN is reported.

  3. On a SIGTERM signal for shutdown
    Promises that are created as part of a ShutdownCheck and registered using registerShutdownCheck are executed when the process receives a SIGTERM making it possible to clean up any resources used by the application. If the shutdown promises are still running, calls to getStatus() return STOPPING. Once the promises complete, STOPPED is reported.

Using Cloud Health with Node.js

  1. Set up a HealthChecker:
const health = require('@cloudnative/health');
let healthcheck = new health.HealthChecker();
  1. Register a readinessCheck promise:
const readyPromise = new Promise(function (resolve, _reject) {
  setTimeout(function () {
    console.log('READY!');
    resolve();
  }, 10);
});
let readyCheck = new health.ReadinessCheck("readyCheck", readyPromise);
healthcheck.registerReadinessCheck(readyCheck);

Note that registerReadinessCheck() also returns a promise which can be used to wait until the promise is resolved.

  1. Register a livenessCheck promise:
const livePromise = new Promise(function (resolve, _reject) {
  setTimeout(function () {
    console.log('ALIVE!');
    resolve();
  }, 10);
});
let liveCheck = new health.LivenessCheck("liveCheck", livePromise);
healthcheck.registerLivenessCheck(liveCheck);
  1. Register a shutdownCheck promise:
const shutdownPromise = new Promise(function (resolve, _reject) {
  setTimeout(function () {
    console.log('DONE!');
    resolve();
  }, 10);
});
let shutdownCheck = new health.ShutdownCheck("shutdownCheck", shutdownPromise);
healthcheck.registerShutdownCheck(shutdownCheck);
  1. Check the applications status:
healthcheck.getStatus()
.then((result) => console.log('STATUS: ' + JSON.stringify(result)));

Note that Cloud Health Connect provides a Connect Middleware for use in Express.js, Loopback and other frameworks that exposes the results as an endpoint for us in Cloud Foundry and Kubernetes based clouds.

Using Cloud Health with Typescript

The Cloud Health module is created in TypeScript and as such provides out of the box TypeScript support.

Module Long Term Support Policy

This module adopts the Module Long Term Support (LTS) policy, with the following End Of Life (EOL) dates:

Module Version Release Date Minimum EOL EOL With Status
1.x.x July 2018 Dec 2019 Current

License

Apache-2.0

cloud-health's People

Contributors

seabaylea avatar

Stargazers

ramdhanfamilysr@gmail.com avatar

Watchers

George Adams avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.