-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Pagination for wlm/stats api #17638
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
Pagination for wlm/stats api #17638
Changes from 20 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
071a07d
rebase
464bdc8
ewq
2e2cb8c
tests unfinished
8e06df4
unit tests
5f88b09
fixed apply pagination
5866fbb
rebase
433ac7f
deleting files
17fc7c7
more
ea72eb3
yaml tests
28fb0dc
rebase
fe1c64d
modified based on pr comments
a9aa0d3
revised based on comments
2b3a21f
fixing naming related issues
7b0c8cf
updated unit tests
05b372e
revised based on comments
182ca6c
fixing errors
ea455e5
fixing header display
c4775b6
fixing yaml tests
29e4b33
Merge branch 'opensearch-project:main' into pagination
Lindsay-00 736b077
Merge branch 'opensearch-project:main' into pagination
Lindsay-00 ecb86ef
revised based on comments
c6b513f
updated changelog
c214c16
fix failed yaml tests
a4bb913
Add pagination support for filtered WLM stats routes
2639e20
fix precommit error
29ec21f
delete dublicate
35a391b
removed checking if data is changed
97d6868
fix for failed yaml tests
f7b1003
adding more tests
e48e03a
more yaml tests
bbad32e
fix failed test
0330990
fix yaml
c808b69
added uts for restWlmStatsAction
d2e01fb
fix failed test
4dbd9e4
added more uts
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
rest-api-spec/src/main/resources/rest-api-spec/api/wlm_stats_list.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| { | ||
| "wlm_stats_list": { | ||
| "stability": "experimental", | ||
| "documentation": { | ||
| "url": "https://docs.opensearch.org/docs/latest/tuning-your-cluster/availability-and-recovery/workload-management/wlm-feature-overview/", | ||
| "description": "This API endpoint returns a list of WLM stats with pagination support." | ||
| }, | ||
| "url": { | ||
| "paths": [ | ||
| { | ||
| "path": "/_list/wlm_stats", | ||
| "methods": ["GET"] | ||
| } | ||
| ] | ||
| }, | ||
| "params": { | ||
| "size": { | ||
| "type": "int", | ||
| "required": false, | ||
| "description": "Number of results per page" | ||
| }, | ||
| "next_token": { | ||
| "type": "string", | ||
| "required": false, | ||
| "description": "Pagination token for next page" | ||
| }, | ||
| "sort": { | ||
| "type": "string", | ||
| "required": false, | ||
| "description": "Sort field" | ||
| }, | ||
| "order": { | ||
| "type": "string", | ||
| "required": false, | ||
| "description": "Sort order (asc or desc)" | ||
| }, | ||
| "v": { | ||
| "type": "boolean", | ||
| "required": false, | ||
| "description": "Whether to include headers" | ||
| } | ||
| } | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
rest-api-spec/src/main/resources/rest-api-spec/test/wlm_stats/10_basic.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| --- | ||
| "Custom size param still returns headers": | ||
| - do: | ||
| wlm_stats_list: | ||
| size: 1 | ||
| v: true | ||
| - is_true: $body | ||
| - match: | ||
| $body: /TOTAL_REJECTIONS/ | ||
|
|
||
| --- | ||
| "Sort by node_id asc does not error": | ||
| - do: | ||
| wlm_stats_list: | ||
| sort: node_id | ||
| order: asc | ||
| - is_true: $body | ||
| - match: | ||
| $body: /DEFAULT_WORKLOAD_GROUP/ | ||
|
|
||
| --- | ||
| "Sort by workload_group_id desc does not error": | ||
| - do: | ||
| wlm_stats_list: | ||
| sort: workload_group | ||
| order: desc | ||
| - is_true: $body | ||
| - match: | ||
| $body: /DEFAULT_WORKLOAD_GROUP/ | ||
|
|
||
| --- | ||
| "Invalid sort field returns error": | ||
| - do: | ||
| catch: bad_request | ||
| wlm_stats_list: | ||
| sort: memory_usage | ||
| order: desc | ||
| - match: | ||
| error.reason: "Invalid value for 'sort'. Allowed: 'node_id', 'workload_group'" | ||
|
|
||
| --- | ||
| "Invalid sort order returns error": | ||
| - do: | ||
| catch: bad_request | ||
| wlm_stats_list: | ||
| order: upside_down | ||
| - match: | ||
| error.reason: "Invalid value for 'order'. Allowed: 'asc', 'desc'" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
server/src/main/java/org/opensearch/action/pagination/SortBy.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.action.pagination; | ||
|
|
||
| import org.opensearch.wlm.stats.WlmStats; | ||
|
|
||
| import java.util.Comparator; | ||
| import java.util.Locale; | ||
|
|
||
| /** | ||
| * Represents the different fields by which WLM statistics can be sorted. | ||
| */ | ||
| public enum SortBy { | ||
| WORKLOAD_GROUP { | ||
| @Override | ||
| public Comparator<WlmStats> getComparator() { | ||
| return Comparator.comparing( | ||
| (WlmStats wlmStats) -> wlmStats.getWorkloadGroupStats().getStats().isEmpty() | ||
Lindsay-00 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ? "" | ||
| : wlmStats.getWorkloadGroupStats().getStats().keySet().iterator().next() | ||
| ).thenComparing(wlmStats -> wlmStats.getNode().getId()); | ||
| } | ||
| }, | ||
| NODE_ID { | ||
| @Override | ||
| public Comparator<WlmStats> getComparator() { | ||
| return Comparator.comparing((WlmStats wlmStats) -> wlmStats.getNode().getId()) | ||
| .thenComparing( | ||
| wlmStats -> wlmStats.getWorkloadGroupStats().getStats().isEmpty() | ||
| ? "" | ||
| : wlmStats.getWorkloadGroupStats().getStats().keySet().iterator().next() | ||
| ); | ||
| } | ||
| }; | ||
|
|
||
| public abstract Comparator<WlmStats> getComparator(); | ||
|
|
||
| public static SortBy fromString(String input) { | ||
| try { | ||
| return SortBy.valueOf(input.toUpperCase(Locale.ROOT)); | ||
| } catch (IllegalArgumentException e) { | ||
| throw new IllegalArgumentException("Invalid sort field: " + input + ". Allowed values: workload_group, node_id"); | ||
| } | ||
| } | ||
| } | ||
43 changes: 43 additions & 0 deletions
43
server/src/main/java/org/opensearch/action/pagination/SortOrder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.action.pagination; | ||
|
|
||
| import org.opensearch.wlm.stats.WlmStats; | ||
|
|
||
| import java.util.Comparator; | ||
| import java.util.Locale; | ||
|
|
||
| /** | ||
| * Represents the sort order for WLM statistics. | ||
| * The sort order can be either ascending or descending. | ||
| */ | ||
| public enum SortOrder { | ||
| ASC { | ||
| @Override | ||
| public Comparator<WlmStats> apply(Comparator<WlmStats> baseComparator) { | ||
| return baseComparator; | ||
| } | ||
| }, | ||
| DESC { | ||
| @Override | ||
| public Comparator<WlmStats> apply(Comparator<WlmStats> baseComparator) { | ||
| return baseComparator.reversed(); | ||
| } | ||
| }; | ||
|
|
||
| public abstract Comparator<WlmStats> apply(Comparator<WlmStats> baseComparator); | ||
|
|
||
| public static SortOrder fromString(String input) { | ||
| try { | ||
| return SortOrder.valueOf(input.toUpperCase(Locale.ROOT)); | ||
| } catch (IllegalArgumentException e) { | ||
| throw new IllegalArgumentException("Invalid sort order: " + input + ". Allowed values: asc, desc"); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.