Skip to content

Instantly share code, notes, and snippets.

@mikaelhg
Created March 7, 2024 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikaelhg/cf5d080f625abb57cea1b7860acfdd8c to your computer and use it in GitHub Desktop.
Save mikaelhg/cf5d080f625abb57cea1b7860acfdd8c to your computer and use it in GitHub Desktop.
OpenSearch lib resource consumption testing

https://github.com/opensearch-project/opensearch-py/blob/main/guides/connection_classes.md

connection_class = Urllib3HttpConnection
pool_class: Any = urllib3.HTTPConnectionPool
self._urllib3_pool_factory = lambda: pool_class(
    self.hostname, port=self.port, timeout=self.timeout, **kw
)
self.pool = self._urllib3_pool_factory()
response = self.pool.urlopen(
  method, url, body, retries=Retry(False), headers=request_headers, **kw
)
raw_data = response.data.decode("utf-8", "surrogatepass")
return response.status, response.headers, raw_data

Selecting a Connection Class

Urllib3HttpConnection

from opensearchpy import OpenSearch, Urllib3HttpConnection

client = OpenSearch(
    hosts = [{'host': 'localhost', 'port': 9200}],
    http_auth = ('admin', 'admin'),
    use_ssl = True,
    verify_certs = False,
    ssl_show_warn = False,
    connection_class = Urllib3HttpConnection
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment