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

Switching to the default connection class to address slower connection with RequestsHttpConnection #411

Merged
merged 3 commits into from
Nov 20, 2023

Conversation

beaioun
Copy link
Collaborator

@beaioun beaioun commented Nov 8, 2023

Description

This PR implements the default Urllib3HttpConnection to replace RequestsHttpConnection to address the slower connection issue, as recommended by the opensearch-py guide for connection classes. Upon checking the code, I discovered this was the only place RequestsHttpConnection was used. Please do point out if I was wrong here.

Issues Resolved

#408

Testing

  • New functionality includes testing

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Copy link
Collaborator

@IanHoang IanHoang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the new change, it's failing for a unittest that tests client creation with aws credentials. Seems like it's failing in the underlying packages. We'll need to see why this error only occurs when Urllib3HttpConnection is used and not when RequestsHttpConnection is used. Regardless of which connection class is included, AWSV4SignerAuth is used. Therefore, this has to be something related to the pathway that Urllib3HttpConnection invokes.

s = <opensearchpy.helpers.signer.AWSV4SignerAuth object at 0x10b73c940>

    def b(s):
>       return s.encode("latin-1")
E       AttributeError: 'AWSV4SignerAuth' object has no attribute 'encode'

.venv/lib/python3.8/site-packages/urllib3/packages/six.py:687: AttributeError

…lable and will be passed directly to the header without having the former issue.

Signed-off-by: Mingyang Shi <[email protected]>
@beaioun
Copy link
Collaborator Author

beaioun commented Nov 17, 2023

With the new change, it's failing for a unittest that tests client creation with aws credentials. Seems like it's failing in the underlying packages. We'll need to see why this error only occurs when Urllib3HttpConnection is used and not when RequestsHttpConnection is used. Regardless of which connection class is included, AWSV4SignerAuth is used. Therefore, this has to be something related to the pathway that Urllib3HttpConnection invokes.

s = <opensearchpy.helpers.signer.AWSV4SignerAuth object at 0x10b73c940>

    def b(s):
>       return s.encode("latin-1")
E       AttributeError: 'AWSV4SignerAuth' object has no attribute 'encode'

.venv/lib/python3.8/site-packages/urllib3/packages/six.py:687: AttributeError

Hey @IanHoang , I figured out where the issue was. The Urllib3HttpConnection has to pair with Urllib3AWSV4SignerAuth for http_auth because that is callable, whereas RequestsAWSV4SignerAuth is not and will try to call make_headers in the urllib3 and throws an error for the subsequent actions. Could you try to run the workflow again? Thanks.

@rishabh6788
Copy link
Collaborator

Also, I don't think opensearch-py-2.3.2 has support for the new methods you added.
Can you please update the opensearch-py version to 2.4.1 , test it locally and update the PR?
@beaioun

@beaioun
Copy link
Collaborator Author

beaioun commented Nov 17, 2023

Also, I don't think opensearch-py-2.3.2 has support for the new methods you added.
Can you please update the opensearch-py version to 2.4.1 , test it locally and update the PR?

@rishabh6788 I see, I'll update to 2.4.1 see if that works.

@rishabh6788
Copy link
Collaborator

FYI, there is bug in opensearch-py-2.4.1 where it is not working with OpenSearch Serverless.
opensearch-project/opensearch-py#600

self.aws_log_in_dict["service"])
return opensearchpy.OpenSearch(hosts=self.hosts, use_ssl=True, verify_certs=True, http_auth=aws_auth,
connection_class=opensearchpy.RequestsHttpConnection)
connection_class=opensearchpy.Urllib3HttpConnection)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI this is now the default and you could remove this option if you want to. Doesn't hurt to keep it either.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @dblock , so if we just use opensearch-py-2.4.1 then we don't need to explicitly specify connection_class parameter?

Copy link
Member

@dblock dblock Dec 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but specifying it explicitly doesn't hurt.

@dblock
Copy link
Member

dblock commented Nov 17, 2023

FYI, there is bug in opensearch-py-2.4.1 where it is not working with OpenSearch Serverless.
opensearch-project/opensearch-py#600

This is not the case, it works with AOSS well. The LangChain integration was failing because it checks for signer.service explicitly, and that field was removed.

…rt in os-py client in this version.

Signed-off-by: beaioun <[email protected]>
@beaioun
Copy link
Collaborator Author

beaioun commented Nov 18, 2023

Also, I don't think opensearch-py-2.3.2 has support for the new methods you added. Can you please update the opensearch-py version to 2.4.1 , test it locally and update the PR? @beaioun

@rishabh6788 I updated the opensearch-py version to 2.4.1 and fixed some other importing issues with this version. All tests passed on my end. 769ff90

@IanHoang IanHoang merged commit 0023e90 into opensearch-project:main Nov 20, 2023
8 checks passed
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.

4 participants