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

Python Sample unexpected output #33

Open
faizalrf opened this issue Oct 28, 2024 · 2 comments
Open

Python Sample unexpected output #33

faizalrf opened this issue Oct 28, 2024 · 2 comments

Comments

@faizalrf
Copy link

The try1.py and try2.py are supposed to display the output of different Alternator hosts, but the script only displays the dummy hostname values

root@pyhost:/scripts# python test.py
Load balancing test:
dog.scylla.com:8000
dog.scylla.com:8000
dog.scylla.com:8000
dog.scylla.com:8000
dog.scylla.com:8000

The line that does this is:
print(dynamodb.meta.client.describe_endpoints()['Endpoints'][0]['Address'])

As per the description in the README it should print out different alternator IP addresses every time

@nyh
Copy link
Contributor

nyh commented Oct 28, 2024

I think you're right. I'm not sure when, if ever, the test printed something else... The DescribeEndpoints request just echos the "Host:" header used in the request. A comment in boto3_alternator.py explains (in a different place, but the comment is still relevant), that when boto3 thinks the target of the request is "dog.scylla.com" it will use this name in preparing the request signature, and since Alternator uses the "Host:" header to calculate this signature, so we NEED the "Host:" HTTP header to also be "dog.scylla.com". So this fake domain is what DescribeEndpoints prints.

In the Go version of this wrapper, we actually documented that "the "fake domain" which doesn't really mean anything (except it will be used as the Host header, and be returned by the DescribeEndpoints request),"

So I think that this test should be modified to not bother printing the result of DescribeEndpoints every time. To check if we get a different or same Scylla node in every request, perhaps there's some way we can enquire which node actually sent us the response or maybe just add a trace-level logging or something in the boto3_alternator.py wrapper that will print out its decision on every request.

@nyh
Copy link
Contributor

nyh commented Oct 28, 2024

By the way note that if you use setup1() (as I think this test does by default) all the requests done by the same thread will go to the same node anyway.

Maybe in addition to the two methods we already have setup1() and setup2(), it might be possible to find a way that doesn't need to use a "fake domain". In the new Java version of our wrapper, we used a new feature of the AWS Java SDK, "DynamoDbEndpointProvider", which lets us return a different endpoint every time in a clean way, without some "fake domain" being involved. Maybe the Python SDK also could do something similar - I see it also has endpoint_provider.py but I don't know how to configure it or override it. But I also don't know if will be worth the work - this issue describes mostly a confusing test, not a problem that hurts a real application.

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

2 participants