Skip to content

[Backport 8.13] Pass endpoint_id and path_parts to transport (#2457) #2468

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

Merged
merged 2 commits into from
Mar 11, 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
5 changes: 3 additions & 2 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
elastic-transport>=8.0.0b1, <9
# TODO switch back to elastic-transport>=8,<9 between elastic-transport release and elasticsearch-py release
elastic-transport @ git+https://github.com/elastic/elastic-transport-python
requests>=2, <3
aiohttp
pytest
Expand Down Expand Up @@ -28,4 +29,4 @@ protobuf<4; python_version<="3.7"
# Override Read the Docs default (sphinx<2 and sphinx-rtd-theme<0.5)
sphinx>2
sphinx-rtd-theme>0.5
sphinx-autodoc-typehints
sphinx-autodoc-typehints
485 changes: 404 additions & 81 deletions elasticsearch/_async/client/__init__.py

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion elasticsearch/_async/client/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ async def perform_request(
params: Optional[Mapping[str, Any]] = None,
headers: Optional[Mapping[str, str]] = None,
body: Optional[Any] = None,
endpoint_id: Union[DefaultType, str] = DEFAULT,
path_parts: Union[DefaultType, Mapping[str, Any]] = DEFAULT,
) -> ApiResponse[Any]:
if headers:
request_headers = self._headers.copy()
Expand Down Expand Up @@ -292,6 +294,8 @@ def mimetype_header_to_compat(header: str) -> None:
retry_on_status=self._retry_on_status,
retry_on_timeout=self._retry_on_timeout,
client_meta=self._client_meta,
endpoint_id=endpoint_id,
path_parts=path_parts,
)

# HEAD with a 404 is returned as a normal response
Expand Down Expand Up @@ -383,9 +387,17 @@ async def perform_request(
params: Optional[Mapping[str, Any]] = None,
headers: Optional[Mapping[str, str]] = None,
body: Optional[Any] = None,
endpoint_id: Union[DefaultType, str] = DEFAULT,
path_parts: Union[DefaultType, Mapping[str, Any]] = DEFAULT,
) -> ApiResponse[Any]:
# Use the internal clients .perform_request() implementation
# so we take advantage of their transport options.
return await self._client.perform_request(
method, path, params=params, headers=headers, body=body
method,
path,
params=params,
headers=headers,
body=body,
endpoint_id=endpoint_id,
path_parts=path_parts,
)
43 changes: 35 additions & 8 deletions elasticsearch/_async/client/async_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ async def delete(
"""
if id in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'id'")
__path = f"/_async_search/{_quote(id)}"
__path_parts: t.Dict[str, str] = {"id": _quote(id)}
__path = f'/_async_search/{__path_parts["id"]}'
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
Expand All @@ -57,7 +58,12 @@ async def delete(
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return await self.perform_request( # type: ignore[return-value]
"DELETE", __path, params=__query, headers=__headers
"DELETE",
__path,
params=__query,
headers=__headers,
endpoint_id="async_search.delete",
path_parts=__path_parts,
)

@_rewrite_parameters()
Expand Down Expand Up @@ -99,7 +105,8 @@ async def get(
"""
if id in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'id'")
__path = f"/_async_search/{_quote(id)}"
__path_parts: t.Dict[str, str] = {"id": _quote(id)}
__path = f'/_async_search/{__path_parts["id"]}'
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
Expand All @@ -117,7 +124,12 @@ async def get(
__query["wait_for_completion_timeout"] = wait_for_completion_timeout
__headers = {"accept": "application/json"}
return await self.perform_request( # type: ignore[return-value]
"GET", __path, params=__query, headers=__headers
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="async_search.get",
path_parts=__path_parts,
)

@_rewrite_parameters()
Expand All @@ -140,7 +152,8 @@ async def status(
"""
if id in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'id'")
__path = f"/_async_search/status/{_quote(id)}"
__path_parts: t.Dict[str, str] = {"id": _quote(id)}
__path = f'/_async_search/status/{__path_parts["id"]}'
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
Expand All @@ -152,7 +165,12 @@ async def status(
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return await self.perform_request( # type: ignore[return-value]
"GET", __path, params=__query, headers=__headers
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="async_search.status",
path_parts=__path_parts,
)

@_rewrite_parameters(
Expand Down Expand Up @@ -428,9 +446,12 @@ async def submit(
up to a certain timeout. When the async search completes within the timeout,
the response won’t include the ID as the results are not stored in the cluster.
"""
__path_parts: t.Dict[str, str]
if index not in SKIP_IN_PATH:
__path = f"/{_quote(index)}/_async_search"
__path_parts = {"index": _quote(index)}
__path = f'/{__path_parts["index"]}/_async_search'
else:
__path_parts = {}
__path = "/_async_search"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
Expand Down Expand Up @@ -590,5 +611,11 @@ async def submit(
if __body is not None:
__headers["content-type"] = "application/json"
return await self.perform_request( # type: ignore[return-value]
"POST", __path, params=__query, headers=__headers, body=__body
"POST",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="async_search.submit",
path_parts=__path_parts,
)
39 changes: 32 additions & 7 deletions elasticsearch/_async/client/autoscaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ async def delete_autoscaling_policy(
"""
if name in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'name'")
__path = f"/_autoscaling/policy/{_quote(name)}"
__path_parts: t.Dict[str, str] = {"name": _quote(name)}
__path = f'/_autoscaling/policy/{__path_parts["name"]}'
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
Expand All @@ -57,7 +58,12 @@ async def delete_autoscaling_policy(
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return await self.perform_request( # type: ignore[return-value]
"DELETE", __path, params=__query, headers=__headers
"DELETE",
__path,
params=__query,
headers=__headers,
endpoint_id="autoscaling.delete_autoscaling_policy",
path_parts=__path_parts,
)

@_rewrite_parameters()
Expand All @@ -75,6 +81,7 @@ async def get_autoscaling_capacity(

`<https://www.elastic.co/guide/en/elasticsearch/reference/8.13/autoscaling-get-autoscaling-capacity.html>`_
"""
__path_parts: t.Dict[str, str] = {}
__path = "/_autoscaling/capacity"
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
Expand All @@ -87,7 +94,12 @@ async def get_autoscaling_capacity(
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return await self.perform_request( # type: ignore[return-value]
"GET", __path, params=__query, headers=__headers
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="autoscaling.get_autoscaling_capacity",
path_parts=__path_parts,
)

@_rewrite_parameters()
Expand All @@ -110,7 +122,8 @@ async def get_autoscaling_policy(
"""
if name in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'name'")
__path = f"/_autoscaling/policy/{_quote(name)}"
__path_parts: t.Dict[str, str] = {"name": _quote(name)}
__path = f'/_autoscaling/policy/{__path_parts["name"]}'
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
Expand All @@ -122,7 +135,12 @@ async def get_autoscaling_policy(
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return await self.perform_request( # type: ignore[return-value]
"GET", __path, params=__query, headers=__headers
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="autoscaling.get_autoscaling_policy",
path_parts=__path_parts,
)

@_rewrite_parameters(
Expand Down Expand Up @@ -156,7 +174,8 @@ async def put_autoscaling_policy(
)
elif policy is not None and body is not None:
raise ValueError("Cannot set both 'policy' and 'body'")
__path = f"/_autoscaling/policy/{_quote(name)}"
__path_parts: t.Dict[str, str] = {"name": _quote(name)}
__path = f'/_autoscaling/policy/{__path_parts["name"]}'
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
Expand All @@ -169,5 +188,11 @@ async def put_autoscaling_policy(
__body = policy if policy is not None else body
__headers = {"accept": "application/json", "content-type": "application/json"}
return await self.perform_request( # type: ignore[return-value]
"PUT", __path, params=__query, headers=__headers, body=__body
"PUT",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="autoscaling.put_autoscaling_policy",
path_parts=__path_parts,
)
Loading