Skip to content

Commit

Permalink
Fix: backwards compatible parameter order in cluster stats.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Nov 25, 2024
1 parent ba444be commit 5fcb4e5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
8 changes: 5 additions & 3 deletions opensearchpy/_async/client/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,11 @@ async def state(
)
async def stats(
self,
metric: Any = None,
index_metric: Any = None,
node_id: Any = None,
params: Any = None,
headers: Any = None,
metric: Any = None,
index_metric: Any = None,
) -> Any:
"""
Returns high-level overview of cluster statistics.
Expand Down Expand Up @@ -308,7 +308,9 @@ async def stats(
(
"/_cluster/stats"
if node_id in SKIP_IN_PATH
else _make_path("_cluster", "stats", "nodes", node_id)
else _make_path(
"_cluster", "stats", metric, index_metric, "nodes", node_id
)
),
params=params,
headers=headers,
Expand Down
8 changes: 5 additions & 3 deletions opensearchpy/client/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,11 @@ def state(
)
def stats(
self,
metric: Any = None,
index_metric: Any = None,
node_id: Any = None,
params: Any = None,
headers: Any = None,
metric: Any = None,
index_metric: Any = None,
) -> Any:
"""
Returns high-level overview of cluster statistics.
Expand Down Expand Up @@ -308,7 +308,9 @@ def stats(
(
"/_cluster/stats"
if node_id in SKIP_IN_PATH
else _make_path("_cluster", "stats", "nodes", node_id)
else _make_path(
"_cluster", "stats", metric, index_metric, "nodes", node_id
)
),
params=params,
headers=headers,
Expand Down
10 changes: 10 additions & 0 deletions test_opensearchpy/test_client/test_overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ def test_cluster_stats(self) -> None:
self.client.cluster.stats(node_id="test-node")
self.assert_url_called("GET", "/_cluster/stats/nodes/test-node")

self.client.cluster.stats(node_id="test-node", metric="indices")
self.assert_url_called("GET", "/_cluster/stats/indices/nodes/test-node")

self.client.cluster.stats(
node_id="test-node", metric="indices", index_metric="analysis"
)
self.assert_url_called(
"GET", "/_cluster/stats/indices/analysis/nodes/test-node"
)

def test_indices_put_mapping(self) -> None:
self.client.indices.put_mapping(body={})
self.assert_url_called("PUT", "/_all/_mapping")
Expand Down
9 changes: 8 additions & 1 deletion utils/templates/overrides/cluster/stats
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{% extends "base" %}
{% block func_params %}
node_id: Any = None,
params: Any = None,
headers: Any = None,
metric: Any = None,
index_metric: Any = None,
{% endblock %}
{% block request %}
return await self.transport.perform_request("{{ api.method }}", "/_cluster/stats" if node_id in SKIP_IN_PATH else _make_path("_cluster", "stats", "nodes", node_id), params=params, headers=headers)
return await self.transport.perform_request("{{ api.method }}", "/_cluster/stats" if node_id in SKIP_IN_PATH else _make_path("_cluster", "stats", metric, index_metric, "nodes", node_id), params=params, headers=headers)
{% endblock%}

0 comments on commit 5fcb4e5

Please sign in to comment.