Skip to content

Commit

Permalink
Upgrade Elasticsearch client to 8.6.1 (elastic#722)
Browse files Browse the repository at this point in the history
Upgrades the `elasticsearch-py` client to 8.6.1,
as well as installs the `elastic-transport` 8.4.0.
  • Loading branch information
b-deam committed Mar 15, 2023
1 parent 04ab3ac commit d9b0efd
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
55 changes: 53 additions & 2 deletions night_rally/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ def create_client(configuration_name):
import certifi
import pathlib

def host_string(host):
# protocol can be set at either host or client opts level
protocol = "https" if host.get("use_ssl") else "http"
return f"{protocol}://{host['host']}:{host['port']}"

def load():
config = configparser.ConfigParser(interpolation=configparser.ExtendedInterpolation())
config_file = pathlib.Path.home()/".rally"/"rally-{}.ini".format(configuration_name)
Expand All @@ -27,7 +32,53 @@ def load():
"use_ssl": secure
}
]
http_auth = (cfg["datastore.user"], cfg["datastore.password"]) if secure else None
basic_auth = (cfg["datastore.user"], cfg["datastore.password"]) if secure else None
hosts = [host_string(h) for h in hosts]
certs = certifi.where() if secure else None

return elasticsearch.Elasticsearch(hosts=hosts, http_auth=http_auth, ca_certs=certs, timeout=60)
return elasticsearch.Elasticsearch(hosts=hosts, basic_auth=basic_auth, ca_certs=certs, timeout=60)


def normalize_hosts(hosts):
# pylint: disable=import-outside-toplevel
from urllib.parse import unquote, urlparse

string_types = str, bytes
# if hosts are empty, just defer to defaults down the line
if hosts is None:
return [{}]

# passed in just one string
if isinstance(hosts, string_types):
hosts = [hosts]

out = []
# normalize hosts to dicts
for host in hosts:
if isinstance(host, string_types):
if "://" not in host:
host = "//%s" % host

parsed_url = urlparse(host)
h = {"host": parsed_url.hostname}

if parsed_url.port:
h["port"] = parsed_url.port

if parsed_url.scheme == "https":
h["port"] = parsed_url.port or 443
h["use_ssl"] = True

if parsed_url.username or parsed_url.password:
h["http_auth"] = "%s:%s" % (
unquote(parsed_url.username),
unquote(parsed_url.password),
)

if parsed_url.path and parsed_url.path != "/":
h["url_prefix"] = parsed_url.path

out.append(h)
else:
out.append(host)
return out
4 changes: 2 additions & 2 deletions night_rally/night_rally.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def wait_until_port_is_free(target_hosts, connector=socket, wait_time=5):
port_free = True
connect_result = None

from elasticsearch.client import _normalize_hosts
for node in _normalize_hosts(target_hosts):
from night_rally.client import normalize_hosts
for node in normalize_hosts(target_hosts):
if "port" not in node:
raise RemotePortNotDefined(
message="No port specified for target host: [{}]. Please check your target-host parameter.".format(node["host"]),
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def str_from_file(name):
"ansible==2.10.7",
# License: Apache 2.0
# transitive dependency urllib3: MIT
"elasticsearch==7.14.0",
"elasticsearch==8.6.1",
"elastic-transport==8.4.0",
# required by hashi_vault ansible plugin
"hvac==0.9.1",
# License: MIT
Expand Down

0 comments on commit d9b0efd

Please sign in to comment.