-
Notifications
You must be signed in to change notification settings - Fork 220
RFC: Implement support for connecting to consul via unix socket #217
base: master
Are you sure you want to change the base?
Conversation
It looks like those test failures are just flake8 errors with python3. This looks great. Do you have time to research adding tornado + twisted support? It'd be good to keep things consistent. If not we could try and recruit someone to help out. If you can fix the test suite, and add Tornado + Twisted, I'd love to merge and push this to PyPI. |
@cablehead re Twisted I can have a look. I used that like 10 years ago and the implementation will probably be pretty similar to aio. I have never used Tornado in any way, so if you know someone who does a contribution would be great. |
Status update on this PR. I plan to add some tests that actually start a consul agent bound to a unix socket and a client connecting to that socket. Something simple like connect && call agent.self(). I want to add these tests for all the different client implementations. Initially this would mean that tests for std and aio would succeed, but tests for twisted and tornado would fail until someone has implemented unix socket support. @cablehead what do you think? Anything else that could or should be tested? |
@cablehead: The introduction of the IMHO the current behaviour is broken, so by changing this I actually fix a problem. |
@asteven I think that test plan is great, and sufficient. |
@asteven I think our two choices are:
I can't think of another option? If you're ok with delaying this PR for a short bit, the latter would be safer for the community... \cc @matusvalo @abn for input.. |
consul/base.py
Outdated
kwargs = { | ||
'consistency': consistency, | ||
'dc': dc, | ||
'addr': oe.get('CONSUL_HTTP_ADDR', None), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In consul docs [1] CONSUL_HTTP_ADDR
specified as follows:
CONSUL_HTTP_ADDR=127.0.0.1:8500
But proposed environment variable requires also protocol embedded in CONSUL_HTTP_ADDR
:
CONSUL_HTTP_ADDR=http://127.0.0.1:8500
Moreover in [1] CONSUL_HTTP_SSL
is present which is not in current PR. I don't think that the form of env. variables of consul is the best but I think that we should copy it as much as possible and mainly when we are reffering in docs to it.
[1] https://www.consul.io/docs/commands/index.html#environment-variables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!
Updated PR to handle CONSUL_HTTP_ADDR with and without scheme as well as taking CONSUL_HTTP_SSL as a hint to prefix with either https or just http.
I prefer option with one additional release with warnings. I have quickly reviewed the proposed PR and see my comments. Regarding tornado implementation, here should be code snippet for support of unix sockets: https://gist.github.com/bdarnell/8641880 I will have a look on it when I will have more time. |
Latest checks have failed for reasons that seem unrelated to my changes. |
@matusvalo thanks for #220. Have rebased this PR on current master. |
Thank you @asteven. Now the PR has green unittests. Currently the PR is missing implementation of unix sockets in Twisted and Tornado backends. Could you finish Twisted backend? I hope I will soon have a look in Tornado. |
Will do asap, ETA ~2 weeks. |
Signed-off-by: Steven Armstrong <steven.armstrong@id.ethz.ch>
Signed-off-by: Steven Armstrong <steven.armstrong@id.ethz.ch>
Signed-off-by: Steven Armstrong <steven.armstrong@id.ethz.ch>
Signed-off-by: Steven Armstrong <steven.armstrong@id.ethz.ch>
Signed-off-by: Steven Armstrong <steven.armstrong@id.ethz.ch>
Signed-off-by: Steven Armstrong <steven.armstrong@id.ethz.ch>
Signed-off-by: Steven Armstrong <steven.armstrong@id.ethz.ch>
Signed-off-by: Steven Armstrong <steven.armstrong@id.ethz.ch>
Replaced most of the boilerplate code that creates a consul client to run tests with fixtures. Prepare for testing with consul clients that can not work with the consul_port fixture, e.g. when using a unix socket. Signed-off-by: Steven Armstrong <steven.armstrong@id.ethz.ch>
Signed-off-by: Steven Armstrong <steven.armstrong@id.ethz.ch>
Signed-off-by: Steven Armstrong <steven.armstrong@id.ethz.ch>
Signed-off-by: Steven Armstrong <steven.armstrong@id.ethz.ch>
…P_SSL Signed-off-by: Steven Armstrong <steven.armstrong@id.ethz.ch>
… CONSUL_HTTP_SSL is set Signed-off-by: Steven Armstrong <steven.armstrong@id.ethz.ch>
Signed-off-by: Steven Armstrong <steven.armstrong@id.ethz.ch>
a7b66ff
to
a23c4d8
Compare
636f367
to
a91daae
Compare
Basically I need python-consul to work with this:
# env | grep CONSUL_HTTP_ADDR CONSUL_HTTP_ADDR=unix:///var/run/consul/http.sock
Just like the consul cli does.
Unfortunately I had to change a lot of code to make this work :-(
Basically the uri (unix:///var/run/consul/http.sock) has to be passed to all the different implementations like std, aio, tornado as they all handle this type of connection differently.
I implemented the feature for all the backends I'm familiar with std and aio but not tornado and twisted.
I also removed the default environment variables support in base.py for 2 reasons:
To fully support configuring a client through environment variables I added a explicit helper function similar to how the docker-py project implements it.