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

Support blocking queries to /health #3

Closed
wants to merge 3 commits into from
Closed

Support blocking queries to /health #3

wants to merge 3 commits into from

Conversation

chrisDeFouRire
Copy link

Here's a very modest proposal for enhancement, to make it possible to use blocking queries with consul.health.* endpoints... It's backwards compatible...

To use blocking queries, you must provide the ?index= param which you obtained in the response headers of the previous call. health HTTP responses do not include a ModifyIndex field like the kvones. Instead, you must use the X-Consul-Index HTTP header... But in consul.health, only the res.body is returned.

This modification adds an optional headers parameter to the callback so the caller can get the X-Consul-Index or other consul specific headers (do we have a leader ? time of last contact) as per the consul.io docs...

If the caller implements a classic 2 params callback, the headers are silently discarded.
If he implements the 3 params callback, he'll receive the headers.

What do you think ?

Example headers:

X-Consul-Index: 235237
X-Consul-Knownleader: true
X-Consul-Lastcontact: 0

@silas
Copy link
Owner

silas commented Jul 24, 2014

I was thinking about exposing res as the second parameter for all callbacks (including errors), that way you can easily get access to the raw response if you want it.

That seem like an acceptable solution to you?

@chrisDeFouRire
Copy link
Author

Hi ! Do you mean having (err, res) as a callback for all calls ? or (err, data, res) ? The first option would break all existing code... the latter sounds good to me...

@silas
Copy link
Owner

silas commented Jul 25, 2014

Woops, I mean't the third parameter. So the callback signature would be function(err, data, res) where data is whatever currently exists (or undefined). But there would always be three values, regardless if data is defined or not.

@chrisDeFouRire
Copy link
Author

it sounds like a good option...

@chrisDeFouRire
Copy link
Author

as for testing, it would be cool if you could tell me about your test configuration: maybe I could build a Vagrant file for easy setup of the 3 nodes...

@silas
Copy link
Owner

silas commented Jul 25, 2014

So you should just need consul in your PATH and a couple of extra local IP's attached to your loopback address (see the development section if you haven't already seen it). Note that assumes a *nix environment. The loopback interface lo0 might be named something else, see ifconfig | grep -C 5 127.0.0.1.

Basically the helper.js script spawns a mini-cluster and waits for it to boot up.

I'm going to spend some time this weekend integrating your changes and writing some nock stubs for the current tests so it's easy to run the tests even without the above setup.

@silas silas closed this in 5822426 Jul 27, 2014
@silas
Copy link
Owner

silas commented Jul 27, 2014

Let me know if you run into issues, thanks for reporting!

@chrisDeFouRire
Copy link
Author

Nice use of middlewares in rapi :-)
Thanks !

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

Successfully merging this pull request may close these issues.

2 participants