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

Create a ok route #580

Closed
benoitvidis opened this issue Dec 15, 2016 · 3 comments
Closed

Create a ok route #580

benoitvidis opened this issue Dec 15, 2016 · 3 comments
Assignees

Comments

@benoitvidis
Copy link
Contributor

We need a basic healthcheck route to monitor a kuzzle node.

@jenow
Copy link
Contributor

jenow commented Apr 19, 2017

Can't we use the "now" route for this? If yes we should modify the route for it to be called without any rights

@AnthonySendra
Copy link
Contributor

@benoitvidis ?

@ballinette ballinette self-assigned this May 10, 2017
@ballinette
Copy link

Sample code:

 healthCheckAction (request) {
    const
      kuzzle = this.context.accessors.kuzzle;

    return kuzzle.services.list.memoryStorage.info()
      .then(() => kuzzle.services.list.storageEngine.client.cluster.health())
      .then(response => {
        if (['yellow', 'green'].indexOf(response.status) < 0) {
          return Promise.reject(new Error('es is down: ' + JSON.stringify(response)));
        }
        return response;
      })
      .then(() => {
        request.setResult('ok', {
          status: 200,
          headers: {
            'Cache-control': 'no-cache',
            Pragma: 'no-cache'
          },
          raw: request.context.protocol === 'http'
        });

        return 'ok';
      })
      .catch(err => {
        this.context.log.error('[health check] ' + err.stack);

        request.setResult('ko', {
          status: 503,
          headers: {
            'Cache-control': 'no-cache',
            Pragma: 'no-cache'
          },
          raw: request.context.protocol === 'http'
        });

        return 'ko';
      });

  }

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

No branches or pull requests

6 participants