Skip to content

Commit acc4631

Browse files
authored
[bug fix] validate lower bound for top n size (opensearch-project#14587)
Signed-off-by: Chenyang Ji <[email protected]>
1 parent 6d0484a commit acc4631

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

plugins/query-insights/src/main/java/org/opensearch/plugin/insights/core/service/TopQueriesService.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,15 @@ public int getTopNSize() {
138138
* @param size the wanted top N size
139139
*/
140140
public void validateTopNSize(final int size) {
141-
if (size > QueryInsightsSettings.MAX_N_SIZE) {
141+
if (size < 1 || size > QueryInsightsSettings.MAX_N_SIZE) {
142142
throw new IllegalArgumentException(
143143
"Top N size setting for ["
144144
+ metricType
145145
+ "]"
146-
+ " should be smaller than max top N size ["
146+
+ " should be between 1 and "
147147
+ QueryInsightsSettings.MAX_N_SIZE
148-
+ "was ("
148+
+ ", was ("
149149
+ size
150-
+ " > "
151-
+ QueryInsightsSettings.MAX_N_SIZE
152150
+ ")"
153151
);
154152
}

plugins/query-insights/src/test/java/org/opensearch/plugin/insights/core/service/TopQueriesServiceTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ public void testValidateTopNSize() {
7878
assertThrows(IllegalArgumentException.class, () -> { topQueriesService.validateTopNSize(QueryInsightsSettings.MAX_N_SIZE + 1); });
7979
}
8080

81+
public void testValidateNegativeTopNSize() {
82+
assertThrows(IllegalArgumentException.class, () -> { topQueriesService.validateTopNSize(-1); });
83+
}
84+
8185
public void testGetTopQueriesWhenNotEnabled() {
8286
topQueriesService.setEnabled(false);
8387
assertThrows(IllegalArgumentException.class, () -> { topQueriesService.getTopQueriesRecords(false); });

0 commit comments

Comments
 (0)