-
Notifications
You must be signed in to change notification settings - Fork 25
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
Multiple endpoints #55
base: master
Are you sure you want to change the base?
Conversation
this fixes the |
Codecov Report
@@ Coverage Diff @@
## master #55 +/- ##
=======================================
Coverage 90.41% 90.41%
=======================================
Files 52 52
Lines 2890 2890
Branches 324 324
=======================================
Hits 2613 2613
Misses 170 170
Partials 107 107 Continue to review full report at Codecov.
|
This commits adds a new `endpoints` parameter for the `BaseClient` class. This parameter, which must be used alternatively to `host` and `port`, can be set to a list of EtcdEndpoint, which is a simple data class with `address` and `port` attributes. A new decorator is present: `retry all hosts`. This decorator if applied to a function of a class descendant from `BaseClient` has the function calls retried against all the `endpoints` if an exception occours. If one of the tries returns with no errors the return value is propagated; if all the tries throws exceptions of the same type the first one is propagated; if they throw different exceptions an Etcd3Exception is thrown. All the failed tries are logged.
A new utility class `EtcdCluster` is added to manage the lifecycle of a etcd cluster run in containers. This class replaces the methods in `docker_cli` and `etcd_go_cli`. A set of fixtures(`etcd_cluster`, `etcd_cluster_ssl`, `client` and `io_client` manages the lifecycle of the test resources. All the tests are set to run using the `BaseClient`'s `endpoint` parameter, additional tests have been added to test `host` and `port`.
b2a30fc
to
7b33a71
Compare
This still needs works on the |
etcd3/baseclient.py
Outdated
ret = func(self, *args, **kwargs) | ||
got_result = True | ||
break | ||
except Exception as e: |
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.
only retry when connection fails
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.
just catch these errors aiohttp.ClientError
requests.RequestException
urllib3.exceptions.HTTPError
NO_DOCKER_SERVICE = True | ||
try: # pragma: no cover | ||
import docker # noqa | ||
NO_DOCKER_SERVICE = False |
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.
I was intended to mock all the api, so I added the NO_ETCD_SERVICE
to make test runnable when no etcd server avaliable.
you can just delete this since NO_DOCKER_SERVICE
always false now
@@ -382,3 +382,12 @@ def find_executable(executable, path=None): # pragma: no cover | |||
f = os.path.join(p, execname) | |||
if os.path.isfile(f): | |||
return f | |||
|
|||
|
|||
class EtcdEndpoint(): |
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.
this class contains only host and port but made creating a client less friendly
any further design on this?
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.
better put this into etcd3/__init__.py
…nge them in flight
@Revolution1 The constructor can still be called as before, the only change is that the the arguments needs to be named (
but I'm not so sure it's really better... maybe accept both of them? About the error detection, my idea was to have something like the code you linked from As per the interface, I was thinking about something on the lines of giving the user the ability to both completely disable request failover or to use a whitelist of safe methods (a |
this is needed to realistically test discovery
every call to a decorated function will now try the call againts the current in-use endpoint before trying to failover. failover will be tried only if the exception thrown is in failover_exceptions and the api method called is in failover_whitelist. the failover process is blocking: Client and AioClient defines their own Lock compatible object
@@ -62,5 +62,5 @@ def event_loop(): # pragma: no cover | |||
async def test_aio_client_host_port(etcd_cluster_ssl): | |||
endpoint = etcd_cluster_ssl.get_endpoints()[0] | |||
aio_client = AioClient(host=endpoint.host, port=endpoint.port, | |||
cert=(CERT_PATH, KEY_PATH), verify=CA_PATH) | |||
cert=(CERT_PATH, KEY_PATH), verify=False) |
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.
why?
I'm gonna reenable certificate validation if needed: I'll need to regenerate the certificates. I reworked the wrapper/endpoints logic. Now:
When calling a decorated function the call will be tried against self.current_endpoint. |
545cda5
to
8206a66
Compare
BTW: you can add your name in |
This commits adds a new
endpoints
parameter for theBaseClient
class.This parameter, which must be used alternatively to
host
andport
,can be set to a list of EtcdEndpoint, which is a simple data class with
address
andport
attributes.A new decorator is present:
retry all hosts
. This decorator ifapplied to a function of a class descendant from
BaseClient
has thefunction calls retried against all the
endpoints
if an exceptionoccours.
If one of the tries returns with no errors the return value is propagated;
if all the tries throws exceptions of the same type the first one is
propagated; if they throw different exceptions an Etcd3Exception is
thrown. All the failed tries are logged.
A new utility class
EtcdCluster
is added to manage the lifecycle ofa etcd cluster run in containers. This semplifies the testing code and
lays the groundwork for testing requests failovers.
This class replaces the methods in
docker_cli
andetcd_go_cli
.A set of fixtures(
etcd_cluster
,etcd_cluster_ssl
,client
andio_client
manages the lifecycle of the test resources.All the tests are set to run using the
BaseClient
'sendpoint
parameter,additional tests have been added to test
host
andport
.A fix for the aiter methods in python 3.7 is included.
TODO: docs, failover testing