-
Notifications
You must be signed in to change notification settings - Fork 30
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
Add alerting tools IT; fix missing system index bug of SearchMonitorsTool #135
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
db01dda
Set up alerting tools IT
ohltyler dc4f1b3
Repro ser/deser issue
ohltyler 4de00d4
Add missing index check
ohltyler 58eadc5
revert build.gradle change
ohltyler 376c8de
Add base test for search alerts tool
ohltyler 82f0708
cleanup; add ziparchive back to integ test cluster
ohltyler 57c2f0e
Remove unused helper fn
ohltyler 2748b92
Remove fn call
ohltyler f5d056c
spotless
ohltyler 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 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
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
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
57 changes: 57 additions & 0 deletions
57
src/test/java/org/opensearch/integTest/SearchAlertsToolIT.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,57 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.integTest; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
|
||
import lombok.SneakyThrows; | ||
|
||
public class SearchAlertsToolIT extends BaseAgentToolsIT { | ||
private String registerAgentRequestBody; | ||
private static final String monitorId = "foo-id"; | ||
private static final String monitorName = "foo-name"; | ||
|
||
@Before | ||
@SneakyThrows | ||
public void setUp() { | ||
super.setUp(); | ||
registerAgentRequestBody = Files | ||
.readString( | ||
Path | ||
.of( | ||
this | ||
.getClass() | ||
.getClassLoader() | ||
.getResource("org/opensearch/agent/tools/register_flow_agent_of_search_alerts_tool_request_body.json") | ||
.toURI() | ||
) | ||
); | ||
} | ||
|
||
@After | ||
@SneakyThrows | ||
public void tearDown() { | ||
super.tearDown(); | ||
deleteExternalIndices(); | ||
deleteSystemIndices(); | ||
} | ||
|
||
@SneakyThrows | ||
public void testSearchAlertsToolInFlowAgent_withNoSystemIndex() { | ||
deleteSystemIndices(); | ||
String agentId = createAgent(registerAgentRequestBody); | ||
String agentInput = "{\"parameters\":{\"monitorId\": \"" + monitorId + "\"}}"; | ||
String result = executeAgent(agentId, agentInput); | ||
assertEquals("Alerts=[]TotalAlerts=0", result); | ||
} | ||
|
||
// TODO: Add IT to test against sample alerts data | ||
// https://github.com/opensearch-project/skills/issues/136 | ||
} |
79 changes: 79 additions & 0 deletions
79
src/test/java/org/opensearch/integTest/SearchMonitorsToolIT.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,79 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.integTest; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.opensearch.agent.tools.utils.ToolConstants; | ||
|
||
import lombok.SneakyThrows; | ||
|
||
public class SearchMonitorsToolIT extends BaseAgentToolsIT { | ||
private String registerAgentRequestBody; | ||
private static final String monitorId = "foo-id"; | ||
private static final String monitorName = "foo-name"; | ||
|
||
@Before | ||
@SneakyThrows | ||
public void setUp() { | ||
super.setUp(); | ||
registerAgentRequestBody = Files | ||
.readString( | ||
Path | ||
.of( | ||
this | ||
.getClass() | ||
.getClassLoader() | ||
.getResource("org/opensearch/agent/tools/register_flow_agent_of_search_monitors_tool_request_body.json") | ||
.toURI() | ||
) | ||
); | ||
createMonitorsSystemIndex(monitorId, monitorName); | ||
} | ||
|
||
@After | ||
@SneakyThrows | ||
public void tearDown() { | ||
super.tearDown(); | ||
deleteExternalIndices(); | ||
deleteSystemIndices(); | ||
} | ||
|
||
@SneakyThrows | ||
public void testSearchMonitorsToolInFlowAgent_withNoSystemIndex() { | ||
deleteSystemIndices(); | ||
String agentId = createAgent(registerAgentRequestBody); | ||
String agentInput = "{\"parameters\":{\"monitorName\": \"" + monitorName + "\"}}"; | ||
String result = executeAgent(agentId, agentInput); | ||
assertEquals("Monitors=[]TotalMonitors=0", result); | ||
} | ||
|
||
// TODO: Add IT to test against sample monitor data | ||
|
||
@SneakyThrows | ||
private void createMonitorsSystemIndex(String monitorId, String monitorName) { | ||
createIndexWithConfiguration( | ||
ToolConstants.ALERTING_CONFIG_INDEX, | ||
"{\n" | ||
+ " \"mappings\": {\n" | ||
+ " \"properties\": {\n" | ||
+ " \"name\": {\n" | ||
+ " \"type\": \"text\",\n" | ||
+ " \"fields\": { \"keyword\": { \"type\": \"keyword\", \"ignore_above\": 256 }}" | ||
+ " }\n" | ||
+ " }\n" | ||
+ " }\n" | ||
+ "}" | ||
); | ||
addDocToIndex(ToolConstants.ALERTING_CONFIG_INDEX, monitorId, List.of("name"), List.of(monitorName)); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...es/org/opensearch/agent/tools/register_flow_agent_of_search_alerts_tool_request_body.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,10 @@ | ||
{ | ||
"name": "Test_Search_Alerts_Agent", | ||
"type": "flow", | ||
"tools": [ | ||
{ | ||
"type": "SearchAlertsTool", | ||
"description": "Use this tool to search alerts." | ||
} | ||
] | ||
} |
10 changes: 10 additions & 0 deletions
10
.../org/opensearch/agent/tools/register_flow_agent_of_search_monitors_tool_request_body.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,10 @@ | ||
{ | ||
"name": "Test_Search_Monitors_Agent", | ||
"type": "flow", | ||
"tools": [ | ||
{ | ||
"type": "SearchMonitorsTool", | ||
"description": "Use this tool to search alerting monitors." | ||
} | ||
] | ||
} |
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.
We are trying to create the system index for alerting. The best way to do this is to create a dummy monitor, so that the schema mapping of the index is setup correctly and would be better to test for an integration test.
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.
Agreed - this was an interim test fn that is actually currently not used. I'll remove and leave the TODO, as this will be grouped with the added tests in the followup issue #136. Thanks for the suggestion, I will likely create dummy monitors and alerts for testing the populated results of the search monitors and search alerts tools respectively.