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

Remove HEAD-handling hack. #794

Merged
merged 3 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Added
### Changed
- Removed deprecated `numpy.float_` and update NumPy/Pandas imports ([#762](https://github.com/opensearch-project/opensearch-py/pull/762))
- Removed workaround for [aiohttp#1769](https://github.com/aio-libs/aiohttp/issues/1769) ([#794](https://github.com/opensearch-project/opensearch-py/pull/794))
### Deprecated
### Removed
- Removed redundant dependency on six ([#781](https://github.com/opensearch-project/opensearch-py/pull/781))
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/bench_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# GitHub history for details.

import asyncio
import os
import uuid
from typing import Any

Expand Down Expand Up @@ -42,7 +43,7 @@ async def test_async(client_count: int = 1, item_count: int = 1) -> None:
"""
host = "localhost"
port = 9200
auth = ("admin", "admin")
auth = ("admin", os.getenv("OPENSEARCH_PASSWORD", "admin"))
index_name = "test-index-async"

clients = []
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/bench_info_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@


import logging
import os
import sys
import time
from typing import Any
Expand All @@ -34,7 +35,7 @@ def test(thread_count: int = 1, request_count: int = 1, client_count: int = 1) -
"""test to index with thread_count threads, item_count records and run client_count clients"""
host = "localhost"
port = 9200
auth = ("admin", "admin")
auth = ("admin", os.getenv("OPENSEARCH_PASSWORD", "admin"))

root = logging.getLogger()
# root.setLevel(logging.DEBUG)
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/bench_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import json
import logging
import os
import sys
import time
import uuid
Expand Down Expand Up @@ -52,7 +53,7 @@ def test(thread_count: int = 1, item_count: int = 1, client_count: int = 1) -> N
"""test to index with thread_count threads, item_count records and run client_count clients"""
host = "localhost"
port = 9200
auth = ("admin", "admin")
auth = ("admin", os.getenv("OPENSEARCH_PASSWORD", "admin"))
index_name = "test-index-sync"

root = logging.getLogger()
Expand Down
2 changes: 1 addition & 1 deletion opensearchpy/_async/helpers/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from opensearchpy import AsyncOpenSearch
from opensearchpy.exceptions import ConnectionError

OPENSEARCH_URL = os.environ.get("OPENSEARCH_URL", "https://admin:admin@localhost:9200")
OPENSEARCH_URL = os.environ.get("OPENSEARCH_URL", "https://localhost:9200")

Check warning on line 18 in opensearchpy/_async/helpers/test.py

View check run for this annotation

Codecov / codecov/patch

opensearchpy/_async/helpers/test.py#L18

Added line #L18 was not covered by tests


async def get_test_client(nowait: bool = False, **kwargs: Any) -> Any:
Expand Down
14 changes: 1 addition & 13 deletions opensearchpy/_async/http_aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,6 @@ async def perform_request(
else:
query_string = ""

# There is a bug in aiohttp that disables the re-use
# of the connection in the pool when method=HEAD.
# See: aio-libs/aiohttp#1769
is_head = False
if method == "HEAD":
method = "GET"
is_head = True

# Top-tier tip-toeing happening here. Basically
# because Pip's old resolver is bad and wipes out
# strict pins in favor of non-strict pins of extras
Expand Down Expand Up @@ -301,11 +293,7 @@ async def perform_request(
timeout=timeout,
fingerprint=self.ssl_assert_fingerprint,
) as response:
if is_head: # We actually called 'GET' so throw away the data.
await response.release()
raw_data = ""
else:
raw_data = await response.text()
raw_data = await response.text()
duration = self.loop.time() - start

# We want to reraise a cancellation or recursion error.
Expand Down
14 changes: 1 addition & 13 deletions opensearchpy/connection/http_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,6 @@ async def perform_request(
else:
query_string = ""

# There is a bug in aiohttp that disables the re-use
# of the connection in the pool when method=HEAD.
# See: https://github.com/aio-libs/aiohttp/issues/1769
is_head = False
if method == "HEAD":
method = "GET"
is_head = True

# Top-tier tip-toeing happening here. Basically
# because Pip's old resolver is bad and wipes out
# strict pins in favor of non-strict pins of extras
Expand Down Expand Up @@ -221,11 +213,7 @@ async def perform_request(
timeout=timeout,
fingerprint=self.ssl_assert_fingerprint,
) as response:
if is_head: # We actually called 'GET' so throw away the data.
await response.release()
raw_data = ""
else:
raw_data = await response.text()
raw_data = await response.text()
duration = self.loop.time() - start

# We want to reraise a cancellation or recursion error.
Expand Down
11 changes: 6 additions & 5 deletions opensearchpy/helpers/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from opensearchpy import OpenSearch
from opensearchpy.exceptions import ConnectionError

OPENSEARCH_URL = os.environ.get("OPENSEARCH_URL", "https://admin:admin@localhost:9200")
OPENSEARCH_URL = os.environ.get("OPENSEARCH_URL", "https://localhost:9200")

Check warning on line 37 in opensearchpy/helpers/test.py

View check run for this annotation

Codecov / codecov/patch

opensearchpy/helpers/test.py#L37

Added line #L37 was not covered by tests


def get_test_client(nowait: bool = False, **kwargs: Any) -> OpenSearch:
Expand Down Expand Up @@ -105,10 +105,11 @@
if "OPENSEARCH_VERSION" in os.environ:
OPENSEARCH_VERSION = _get_version(os.environ["OPENSEARCH_VERSION"])
else:
client = OpenSearch(
OPENSEARCH_URL,
verify_certs=False,
OPENSEARCH_VERSION = opensearch_version(

Check warning on line 108 in opensearchpy/helpers/test.py

View check run for this annotation

Codecov / codecov/patch

opensearchpy/helpers/test.py#L108

Added line #L108 was not covered by tests
get_test_client(
verify_certs=False,
http_auth=("admin", os.getenv("OPENSEARCH_PASSWORD", "admin")),
)
)
OPENSEARCH_VERSION = opensearch_version(client)

__all__ = ["OpenSearchTestCase"]
2 changes: 1 addition & 1 deletion samples/logging/log_collection_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def main() -> None:
# Setup connection with the OpenSearch cluster
print("Setting up connection with OpenSearch cluster...")
opensearch_client: Any = OpenSearch(
"https://admin:admin@localhost:9200",
"https://localhost:9200",
use_ssl=True,
verify_certs=False,
ssl_show_warn=False,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# Modifications Copyright OpenSearch Contributors. See
# GitHub history for details.

import os
import re
from datetime import datetime
from typing import Any
Expand Down Expand Up @@ -36,7 +37,10 @@

@fixture(scope="function") # type: ignore
async def client() -> Any:
client = await get_test_client(verify_certs=False, http_auth=("admin", "admin"))
client = await get_test_client(
verify_certs=False,
http_auth=("admin", os.getenv("OPENSEARCH_PASSWORD", "admin")),
)
await add_connection("default", client)
return client

Expand Down
6 changes: 5 additions & 1 deletion test_opensearchpy/test_server/test_helpers/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# specific language governing permissions and limitations
# under the License.

import os
import re
from datetime import datetime
from typing import Any
Expand All @@ -46,7 +47,10 @@

@fixture(scope="session") # type: ignore
def client() -> Any:
client = get_test_client(verify_certs=False, http_auth=("admin", "admin"))
client = get_test_client(
verify_certs=False,
http_auth=("admin", os.getenv("OPENSEARCH_PASSWORD", "admin")),
)
add_connection("default", client)
return client

Expand Down
Loading