Skip to content

Commit d2b3ba0

Browse files
authored
Pagination for wlm/stats api (#17638)
--------- Signed-off-by: Lingxi Chen <[email protected]>
1 parent e1826c2 commit d2b3ba0

File tree

13 files changed

+1377
-3
lines changed

13 files changed

+1377
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
88
- Add support for linux riscv64 platform ([#18156](https://github.com/opensearch-project/OpenSearch/pull/18156))
99
- [Rule based auto-tagging] Add get rule API ([#17336](https://github.com/opensearch-project/OpenSearch/pull/17336))
1010
- [Rule based auto-tagging] Add Delete Rule API ([#18184](https://github.com/opensearch-project/OpenSearch/pull/18184))
11+
- Add paginated wlm/stats API ([#17638](https://github.com/opensearch-project/OpenSearch/pull/17638))
1112
- Implement parallel shard refresh behind cluster settings ([#17782](https://github.com/opensearch-project/OpenSearch/pull/17782))
1213
- Bump OpenSearch Core main branch to 3.0.0 ([#18039](https://github.com/opensearch-project/OpenSearch/pull/18039))
1314
- [Rule based Auto-tagging] Add wlm `ActionFilter` ([#17791](https://github.com/opensearch-project/OpenSearch/pull/17791))

client/rest-high-level/src/test/java/org/opensearch/client/RestHighLevelClientTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,8 @@ public void testApiNamingConventions() throws Exception {
882882
"cluster.delete_weighted_routing",
883883
"cluster.put_decommission_awareness",
884884
"cluster.get_decommission_awareness",
885-
"cluster.delete_decommission_awareness", };
885+
"cluster.delete_decommission_awareness",
886+
"wlm_stats_list" };
886887
List<String> booleanReturnMethods = Arrays.asList("security.enable_user", "security.disable_user", "security.change_password");
887888
Set<String> deprecatedMethods = new HashSet<>();
888889
deprecatedMethods.add("indices.force_merge");
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"wlm_stats_list": {
3+
"stability": "experimental",
4+
"documentation": {
5+
"url": "https://docs.opensearch.org/docs/latest/tuning-your-cluster/availability-and-recovery/workload-management/wlm-feature-overview/",
6+
"description": "This API endpoint returns a list of WLM stats with pagination support."
7+
},
8+
"url": {
9+
"paths": [
10+
{
11+
"path": "/_list/wlm_stats",
12+
"methods": ["GET"]
13+
}
14+
]
15+
},
16+
"params": {
17+
"size": {
18+
"type": "int",
19+
"required": false,
20+
"description": "Number of results per page"
21+
},
22+
"next_token": {
23+
"type": "string",
24+
"required": false,
25+
"description": "Pagination token for next page"
26+
},
27+
"sort": {
28+
"type": "string",
29+
"required": false,
30+
"description": "Sort field"
31+
},
32+
"order": {
33+
"type": "string",
34+
"required": false,
35+
"description": "Sort order (asc or desc)"
36+
},
37+
"v": {
38+
"type": "boolean",
39+
"required": false,
40+
"description": "Whether to include headers"
41+
}
42+
}
43+
}
44+
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
---
2+
"Custom size param still returns headers":
3+
- skip:
4+
version: " - 3.0.0"
5+
reason: "wlm_stats_list API added after 3.0.0"
6+
- do:
7+
wlm_stats_list:
8+
size: 1
9+
v: true
10+
- is_true: $body
11+
- match:
12+
$body: /TOTAL_REJECTIONS/
13+
14+
---
15+
"Sort by node_id asc does not error":
16+
- skip:
17+
version: " - 3.0.0"
18+
reason: "wlm_stats_list API added after 3.0.0"
19+
- do:
20+
wlm_stats_list:
21+
sort: node_id
22+
order: asc
23+
- is_true: $body
24+
- match:
25+
$body: /DEFAULT_WORKLOAD_GROUP/
26+
27+
---
28+
"Sort by workload_group_id desc does not error":
29+
- skip:
30+
version: " - 3.0.0"
31+
reason: "wlm_stats_list API added after 3.0.0"
32+
- do:
33+
wlm_stats_list:
34+
sort: workload_group
35+
order: desc
36+
- is_true: $body
37+
- match:
38+
$body: /DEFAULT_WORKLOAD_GROUP/
39+
40+
---
41+
"Invalid sort field returns error":
42+
- skip:
43+
version: " - 3.0.0"
44+
reason: "wlm_stats_list API added after 3.0.0"
45+
- do:
46+
catch: bad_request
47+
wlm_stats_list:
48+
sort: memory_usage
49+
order: desc
50+
- match:
51+
error.reason: "Invalid value for 'sort'. Allowed: 'node_id', 'workload_group'"
52+
53+
---
54+
"Invalid sort order returns error":
55+
- skip:
56+
version: " - 3.0.0"
57+
reason: "wlm_stats_list API added after 3.0.0"
58+
- do:
59+
catch: bad_request
60+
wlm_stats_list:
61+
order: upside_down
62+
- match:
63+
error.reason: "Invalid value for 'order'. Allowed: 'asc', 'desc'"
64+
65+
---
66+
"Invalid token returns 400":
67+
- skip:
68+
version: " - 3.0.0"
69+
reason: "wlm_stats_list API added after 3.0.0"
70+
- do:
71+
catch: bad_request
72+
wlm_stats_list:
73+
next_token: "abcdef123456"
74+
75+
- match: { error: "Pagination state has changed (e.g., new workload groups added or removed). Please restart pagination from the beginning by omitting the 'next_token' parameter." }
76+
77+
---
78+
"Default request returns 200 and contains expected keys":
79+
- skip:
80+
version: " - 3.0.0"
81+
reason: "wlm_stats_list API added after 3.0.0"
82+
- do:
83+
wlm_stats_list:
84+
v: true
85+
- is_true: $body
86+
- match:
87+
$body: /WORKLOAD_GROUP_ID/
88+
89+
---
90+
"Max allowed size param returns success":
91+
- skip:
92+
version: " - 3.0.0"
93+
reason: "wlm_stats_list API added after 3.0.0"
94+
- do:
95+
wlm_stats_list:
96+
size: 100
97+
- is_true: $body
98+
99+
---
100+
"Too large page size returns error":
101+
- skip:
102+
version: " - 3.0.0"
103+
reason: "wlm_stats_list API added after 3.0.0"
104+
- do:
105+
catch: bad_request
106+
wlm_stats_list:
107+
size: 1000
108+
- match:
109+
error.reason: "Invalid value for 'size'. Allowed range: 1 to 100"
110+
111+
---
112+
"Negative page size returns error":
113+
- skip:
114+
version: " - 3.0.0"
115+
reason: "wlm_stats_list API added after 3.0.0"
116+
- do:
117+
catch: bad_request
118+
wlm_stats_list:
119+
size: -1
120+
- match:
121+
error.reason: "Invalid value for 'size'. Allowed range: 1 to 100"
122+
123+
124+
---
125+
"Sort param omitted uses default 'node_id'":
126+
- skip:
127+
version: " - 3.0.0"
128+
reason: "wlm_stats_list API added after 3.0.0"
129+
- do:
130+
wlm_stats_list:
131+
size: 1
132+
v: true
133+
- is_true: $body
134+
- match:
135+
$body: /NODE_ID/

server/src/main/java/org/opensearch/action/admin/cluster/wlm/WlmStatsResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class WlmStatsResponse extends BaseNodesResponse<WlmStats> implements ToX
3333
super(in);
3434
}
3535

36-
WlmStatsResponse(ClusterName clusterName, List<WlmStats> nodes, List<FailedNodeException> failures) {
36+
public WlmStatsResponse(ClusterName clusterName, List<WlmStats> nodes, List<FailedNodeException> failures) {
3737
super(clusterName, nodes, failures);
3838
}
3939

0 commit comments

Comments
 (0)