-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Siddhant Deshmukh <deshsid@amazon.com>
- Loading branch information
Showing
4 changed files
with
372 additions
and
14 deletions.
There are no files selected for viewing
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
75 changes: 75 additions & 0 deletions
75
.../java/org/opensearch/plugin/insights/core/service/grouper/MinMaxQueryGrouperByNoneIT.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,75 @@ | ||
/* | ||
* 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.plugin.insights.core.service.grouper; | ||
|
||
import org.junit.Assert; | ||
import org.opensearch.client.Request; | ||
import org.opensearch.client.Response; | ||
import org.opensearch.plugin.insights.QueryInsightsRestTestCase; | ||
import org.opensearch.plugin.insights.settings.QueryInsightsSettings; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
/** | ||
* ITs for Grouping Top Queries by none | ||
*/ | ||
public class MinMaxQueryGrouperByNoneIT extends QueryInsightsRestTestCase { | ||
|
||
/** | ||
* Grouping by none should not group queries | ||
* @throws IOException | ||
* @throws InterruptedException | ||
*/ | ||
public void testGroupingByNone() throws IOException, InterruptedException { | ||
|
||
waitForEmptyTopQueriesResponse(); | ||
|
||
// Enable top N feature and grouping by none | ||
Request request = new Request("PUT", "/_cluster/settings"); | ||
request.setJsonEntity(groupByNoneSettings()); | ||
Response response = client().performRequest(request); | ||
Assert.assertEquals(200, response.getStatusLine().getStatusCode()); | ||
|
||
// Search | ||
doSearch("range", 2); | ||
doSearch("match", 6); | ||
doSearch("term", 4); | ||
|
||
// Ensure records are drained to the top queries service | ||
Thread.sleep(QueryInsightsSettings.QUERY_RECORD_QUEUE_DRAIN_INTERVAL.millis()); | ||
|
||
// run five times to make sure the records are drained to the top queries services | ||
for (int i = 0; i < 5; i++) { | ||
// Get Top Queries and validate | ||
request = new Request("GET", "/_insights/top_queries?pretty"); | ||
response = client().performRequest(request); | ||
Assert.assertEquals(200, response.getStatusLine().getStatusCode()); | ||
String top_requests = new String(response.getEntity().getContent().readAllBytes(), StandardCharsets.UTF_8); | ||
|
||
int top_n_array_size = countTopQueries(top_requests); | ||
|
||
// Validate that all queries are listed separately (no grouping) | ||
Assert.assertEquals(12, top_n_array_size); | ||
} | ||
} | ||
|
||
private String groupByNoneSettings() { | ||
return "{\n" + | ||
" \"persistent\" : {\n" + | ||
" \"search.insights.top_queries.latency.enabled\" : \"true\",\n" + | ||
" \"search.insights.top_queries.latency.window_size\" : \"1m\",\n" + | ||
" \"search.insights.top_queries.latency.top_n_size\" : 100,\n" + | ||
" \"search.insights.top_queries.group_by\" : \"none\",\n" + | ||
" \"search.insights.top_queries.max_groups\" : 5\n" + | ||
" }\n" + | ||
"}"; | ||
} | ||
} | ||
|
||
|
160 changes: 160 additions & 0 deletions
160
...org/opensearch/plugin/insights/core/service/grouper/MinMaxQueryGrouperBySimilarityIT.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,160 @@ | ||
/* | ||
* 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.plugin.insights.core.service.grouper; | ||
|
||
import org.junit.Assert; | ||
import org.opensearch.client.Request; | ||
import org.opensearch.client.Response; | ||
import org.opensearch.client.ResponseException; | ||
import org.opensearch.plugin.insights.QueryInsightsRestTestCase; | ||
import org.opensearch.plugin.insights.settings.QueryInsightsSettings; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
/** | ||
* ITs for Grouping Top Queries by similarity | ||
*/ | ||
public class MinMaxQueryGrouperBySimilarityIT extends QueryInsightsRestTestCase { | ||
|
||
/** | ||
* test grouping top queries | ||
* | ||
* @throws IOException IOException | ||
*/ | ||
public void testGroupingBySimilarity() throws IOException, InterruptedException { | ||
|
||
waitForEmptyTopQueriesResponse(); | ||
|
||
// Enable top N feature and grouping feature | ||
Request request = new Request("PUT", "/_cluster/settings"); | ||
request.setJsonEntity(defaultTopQueryGroupingSettings()); | ||
Response response = client().performRequest(request); | ||
Assert.assertEquals(200, response.getStatusLine().getStatusCode()); | ||
|
||
// Search | ||
doSearch("range", 2); | ||
doSearch("match", 6); | ||
doSearch("term", 4); | ||
|
||
// run five times to make sure the records are drained to the top queries services | ||
for (int i = 0; i < 5; i++) { | ||
// Get Top Queries | ||
request = new Request("GET", "/_insights/top_queries?pretty"); | ||
response = client().performRequest(request); | ||
Assert.assertEquals(200, response.getStatusLine().getStatusCode()); | ||
|
||
String responseBody = new String(response.getEntity().getContent().readAllBytes(), StandardCharsets.UTF_8); | ||
|
||
// Extract and count top_queries | ||
int topNArraySize = countTopQueries(responseBody); | ||
|
||
if (topNArraySize == 0) { | ||
Thread.sleep(QueryInsightsSettings.QUERY_RECORD_QUEUE_DRAIN_INTERVAL.millis()); | ||
continue; | ||
} | ||
|
||
Assert.assertEquals(3, topNArraySize); | ||
} | ||
} | ||
|
||
/** | ||
* Test invalid query grouping settings | ||
* | ||
* @throws IOException IOException | ||
*/ | ||
public void testInvalidQueryGroupingSettings() throws IOException { | ||
for (String setting : invalidQueryGroupingSettings()) { | ||
Request request = new Request("PUT", "/_cluster/settings"); | ||
request.setJsonEntity(setting); | ||
try { | ||
client().performRequest(request); | ||
fail("Should not succeed with invalid query grouping settings"); | ||
} catch (ResponseException e) { | ||
assertEquals(400, e.getResponse().getStatusLine().getStatusCode()); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Test valid query grouping settings | ||
* | ||
* @throws IOException IOException | ||
*/ | ||
public void testValidQueryGroupingSettings() throws IOException { | ||
for (String setting : validQueryGroupingSettings()) { | ||
Request request = new Request("PUT", "/_cluster/settings"); | ||
request.setJsonEntity(setting); | ||
Response response = client().performRequest(request); | ||
assertEquals(200, response.getStatusLine().getStatusCode()); | ||
} | ||
} | ||
|
||
private String[] invalidQueryGroupingSettings() { | ||
return new String[] { | ||
// Invalid max_groups: below minimum (0) | ||
"{\n" + | ||
" \"persistent\" : {\n" + | ||
" \"search.insights.top_queries.max_groups\" : 0\n" + | ||
" }\n" + | ||
"}", | ||
|
||
// Invalid max_groups: above maximum (10001) | ||
"{\n" + | ||
" \"persistent\" : {\n" + | ||
" \"search.insights.top_queries.max_groups\" : 10001\n" + | ||
" }\n" + | ||
"}", | ||
|
||
// Invalid group_by: unsupported value | ||
"{\n" + | ||
" \"persistent\" : {\n" + | ||
" \"search.insights.top_queries.group_by\" : \"unsupported_value\"\n" + | ||
" }\n" + | ||
"}" | ||
}; | ||
} | ||
|
||
private String[] validQueryGroupingSettings() { | ||
return new String[]{ | ||
// Valid max_groups: minimum value (1) | ||
"{\n" + | ||
" \"persistent\" : {\n" + | ||
" \"search.insights.top_queries.max_groups\" : 1\n" + | ||
" }\n" + | ||
"}", | ||
|
||
// Valid max_groups: maximum value (10000) | ||
"{\n" + | ||
" \"persistent\" : {\n" + | ||
" \"search.insights.top_queries.max_groups\" : 10000\n" + | ||
" }\n" + | ||
"}", | ||
|
||
// Valid group_by: supported value (SIMILARITY) | ||
"{\n" + | ||
" \"persistent\" : {\n" + | ||
" \"search.insights.top_queries.group_by\" : \"SIMILARITY\"\n" + | ||
" }\n" + | ||
"}" | ||
}; | ||
} | ||
|
||
private String groupByNoneSettings() { | ||
return "{\n" + | ||
" \"persistent\" : {\n" + | ||
" \"search.insights.top_queries.latency.enabled\" : \"true\",\n" + | ||
" \"search.insights.top_queries.latency.window_size\" : \"1m\",\n" + | ||
" \"search.insights.top_queries.latency.top_n_size\" : 100,\n" + | ||
" \"search.insights.top_queries.group_by\" : \"none\",\n" + | ||
" \"search.insights.top_queries.max_groups\" : 5\n" + | ||
" }\n" + | ||
"}"; | ||
} | ||
} | ||
|
Oops, something went wrong.