Skip to content

Commit

Permalink
Repro ser/deser issue
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Ohlsen <[email protected]>
  • Loading branch information
ohltyler committed Jan 16, 2024
1 parent 146defd commit ffb35aa
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 91 deletions.
17 changes: 17 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ apply plugin: 'opensearch.pluginzip'
def sqlJarDirectory = "$buildDir/dependencies/opensearch-sql-plugin"
def jsJarDirectory = "$buildDir/dependencies/opensearch-job-scheduler"
def adJarDirectory = "$buildDir/dependencies/opensearch-time-series-analytics"
// def alertingJarDirectory = "$buildDir/dependencies/alerting"

configurations {
zipArchive
Expand Down Expand Up @@ -101,6 +102,11 @@ task addJarsToClasspath(type: Copy) {
include "opensearch-time-series-analytics-${version}.jar"
}
into("$buildDir/classes")

// from(fileTree(dir: alertingJarDirectory)) {
// include "alerting-${version}.jar"
// }
// into("$buildDir/classes")
}

dependencies {
Expand All @@ -116,10 +122,12 @@ dependencies {
compileOnly group: 'org.opensearch', name:'opensearch-ml-client', version: "${version}"
implementation fileTree(dir: jsJarDirectory, include: ["opensearch-job-scheduler-${version}.jar"])
implementation fileTree(dir: adJarDirectory, include: ["opensearch-time-series-analytics-${version}.jar"])
// implementation fileTree(dir: alertingJarDirectory, include: ["alerting-${version}.jar"])
implementation fileTree(dir: sqlJarDirectory, include: ["opensearch-sql-${version}.jar", "ppl-${version}.jar", "protocol-${version}.jar"])
compileOnly "org.opensearch:common-utils:${version}"
compileOnly "org.jetbrains.kotlin:kotlin-stdlib:${kotlin_version}"
compileOnly "org.opensearch:opensearch-job-scheduler-spi:${version}"
// compileOnly "org.opensearch.plugin:alerting:${version}"


// ZipArchive dependencies used for integration tests
Expand All @@ -129,6 +137,7 @@ dependencies {
zipArchive group: 'org.opensearch.plugin', name:'opensearch-sql-plugin', version: "${version}"
zipArchive group: 'org.opensearch.plugin', name:'opensearch-knn', version: "${version}"
zipArchive group: 'org.opensearch.plugin', name:'neural-search', version: "${version}"
zipArchive group: 'org.opensearch.plugin', name:'alerting', version: "${version}"

// Test dependencies
testImplementation "org.opensearch.test:framework:${opensearch_version}"
Expand Down Expand Up @@ -164,9 +173,16 @@ task extractAdJar(type: Copy) {
into adJarDirectory
}

// task extractAlertingJar(type: Copy) {
// mustRunAfter()
// from(zipTree(configurations.zipArchive.find { it.name.startsWith("alerting")}))
// into alertingJarDirectory
// }

tasks.addJarsToClasspath.dependsOn(extractSqlJar)
tasks.addJarsToClasspath.dependsOn(extractJsJar)
tasks.addJarsToClasspath.dependsOn(extractAdJar)
// tasks.addJarsToClasspath.dependsOn(extractAlertingJar)
project.tasks.delombok.dependsOn(addJarsToClasspath)
tasks.publishNebulaPublicationToMavenLocal.dependsOn ':generatePomFileForPluginZipPublication'
tasks.validateNebulaPom.dependsOn ':generatePomFileForPluginZipPublication'
Expand Down Expand Up @@ -212,6 +228,7 @@ compileJava {
dependsOn extractSqlJar
dependsOn extractJsJar
dependsOn extractAdJar
// dependsOn extractAlertingJar
dependsOn delombok
options.compilerArgs.addAll(["-processor", 'lombok.launch.AnnotationProcessorHider$AnnotationProcessor'])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.opensearch.commons.alerting.action.GetMonitorResponse;
import org.opensearch.commons.alerting.action.SearchMonitorRequest;
import org.opensearch.commons.alerting.model.Monitor;
import org.opensearch.commons.alerting.model.ScheduledJob;
import org.opensearch.core.action.ActionListener;
import org.opensearch.index.query.BoolQueryBuilder;
import org.opensearch.index.query.ExistsQueryBuilder;
Expand Down Expand Up @@ -167,7 +168,8 @@ public <T> void run(Map<String, String> parameters, ActionListener<T> listener)
.from(startIndex)
.sort(sortString, sortOrder);

SearchMonitorRequest searchMonitorRequest = new SearchMonitorRequest(new SearchRequest().source(searchSourceBuilder));
SearchRequest searchRequest = new SearchRequest().source(searchSourceBuilder).indices(ScheduledJob.SCHEDULED_JOBS_INDEX);
SearchMonitorRequest searchMonitorRequest = new SearchMonitorRequest(searchRequest);

ActionListener<SearchResponse> searchMonitorListener = ActionListener.<SearchResponse>wrap(response -> {
StringBuilder sb = new StringBuilder();
Expand Down
178 changes: 88 additions & 90 deletions src/test/java/org/opensearch/integTest/SearchMonitorsToolIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,94 +3,92 @@
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.integTest;
package org.opensearch.integTest;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Locale;

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);
}

// @SneakyThrows
// public void testSearchAnomalyDetectorsToolInFlowAgent_noMatching() {
// String agentId = createAgent(registerAgentRequestBody);
// String agentInput = "{\"parameters\":{\"detectorName\": \"" + detectorName + "foo" + "\"}}";
// String result = executeAgent(agentId, agentInput);
// assertEquals("AnomalyDetectors=[]TotalAnomalyDetectors=0", result);
// }

// @SneakyThrows
// public void testSearchAnomalyDetectorsToolInFlowAgent_matching() {
// String agentId = createAgent(registerAgentRequestBody);
// String agentInput = "{\"parameters\":{\"detectorName\": \"" + detectorName + "\"}}";
// String result = executeAgent(agentId, agentInput);
// assertEquals(
// String.format(Locale.ROOT, "AnomalyDetectors=[{id=%s,name=%s}]TotalAnomalyDetectors=%d", detectorId, detectorName, 1),
// result
// );
// }

@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));
}
}

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);
}

// @SneakyThrows
// public void testSearchAnomalyDetectorsToolInFlowAgent_noMatching() {
// String agentId = createAgent(registerAgentRequestBody);
// String agentInput = "{\"parameters\":{\"detectorName\": \"" + detectorName + "foo" + "\"}}";
// String result = executeAgent(agentId, agentInput);
// assertEquals("AnomalyDetectors=[]TotalAnomalyDetectors=0", result);
// }

// @SneakyThrows
// public void testSearchAnomalyDetectorsToolInFlowAgent_matching() {
// String agentId = createAgent(registerAgentRequestBody);
// String agentInput = "{\"parameters\":{\"detectorName\": \"" + detectorName + "\"}}";
// String result = executeAgent(agentId, agentInput);
// assertEquals(
// String.format(Locale.ROOT, "AnomalyDetectors=[{id=%s,name=%s}]TotalAnomalyDetectors=%d", detectorId, detectorName, 1),
// result
// );
// }

@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));
}
}

0 comments on commit ffb35aa

Please sign in to comment.