-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Pagination #17638
Open
Lindsay-00
wants to merge
10
commits into
opensearch-project:main
Choose a base branch
from
Lindsay-00:pagination
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Pagination #17638
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f7b9243
tabular format
cc05920
pagination
bfc90b7
tests unfinished
44f5e10
unit tests
0f4cf5b
fixed apply pagination
58ceeb1
deleting
ed4336b
deleting files
ad612da
more
baa30b0
yaml tests
0dd053d
changed based on comments except for testing
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
35 changes: 35 additions & 0 deletions
35
rest-api-spec/src/main/resources/rest-api-spec/api/wlm_stats_list.json
This file contains 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,35 @@ | ||
{ | ||
"wlm_stats_list": { | ||
"stability": "experimental", | ||
"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)" | ||
} | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
rest-api-spec/src/main/resources/rest-api-spec/test/wlm_stats/10_basic.yml
This file contains 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,55 @@ | ||
--- | ||
"Basic usage returns expected table header": | ||
- do: | ||
wlm_stats_list: {} | ||
- is_true: $body | ||
- match: | ||
$body: /(?s).*NODE_ID\s+\|\s+QUERY_GROUP_ID\s+\|\s+TOTAL_COMPLETIONS\s+\|\s+TOTAL_REJECTIONS\s+\|\s+TOTAL_CANCELLATIONS\s+\|\s+CPU_USAGE\s+\|\s+MEMORY_USAGE.*/ | ||
|
||
--- | ||
"Custom size param still returns headers": | ||
- do: | ||
wlm_stats_list: | ||
size: 1 | ||
- 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: /NODE_ID/ | ||
|
||
--- | ||
"Sort by query_group_id desc does not error": | ||
- do: | ||
wlm_stats_list: | ||
sort: query_group_id | ||
order: desc | ||
- is_true: $body | ||
- match: | ||
$body: /QUERY_GROUP_ID/ | ||
|
||
--- | ||
"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', 'query_group_id'." | ||
|
||
--- | ||
"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 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
52 changes: 52 additions & 0 deletions
52
server/src/main/java/org/opensearch/action/pagination/SortBy.java
This file contains 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,52 @@ | ||
/* | ||
* 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; | ||
|
||
public enum SortBy { | ||
QUERY_GROUP { | ||
@Override | ||
public Comparator<WlmStats> getComparator() { | ||
return Comparator.comparing( | ||
(WlmStats wlmStats) -> wlmStats.getQueryGroupStats().getStats().isEmpty() | ||
? "" | ||
: wlmStats.getQueryGroupStats().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.getQueryGroupStats().getStats().isEmpty() | ||
? "" | ||
: wlmStats.getQueryGroupStats().getStats().keySet().iterator().next() | ||
); | ||
} | ||
}; | ||
|
||
public abstract Comparator<WlmStats> getComparator(); | ||
|
||
public static SortBy fromString(String input) { | ||
switch (input.toLowerCase()) { | ||
case "query_group": | ||
return QUERY_GROUP; | ||
case "node_id": | ||
return NODE_ID; | ||
default: | ||
throw new IllegalArgumentException("Invalid sort field: " + input); | ||
} | ||
} | ||
} | ||
|
41 changes: 41 additions & 0 deletions
41
server/src/main/java/org/opensearch/action/pagination/SortOrder.java
This file contains 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,41 @@ | ||
/* | ||
* 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; | ||
|
||
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) { | ||
switch (input.toLowerCase()) { | ||
case "asc": | ||
return ASC; | ||
case "desc": | ||
return DESC; | ||
default: | ||
throw new IllegalArgumentException("Invalid sort order: " + input); | ||
} | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use this to avoid using switch? Same for
SortOrder