From bb32961afecd90a0bdfea0d13bc4d9b7a3218ed1 Mon Sep 17 00:00:00 2001 From: Hailong Cui Date: Thu, 6 Jun 2024 16:13:26 +0800 Subject: [PATCH] Fix build error due to upstream change (#316) (#317) * fix build error due to upstream change Signed-off-by: Hailong Cui * failed unit test Signed-off-by: Hailong Cui * fix compile error Signed-off-by: Hailong Cui * fix flaky test for locale mr Signed-off-by: Hailong Cui * force to use x86_64 for macos Signed-off-by: Hailong Cui --------- Signed-off-by: Hailong Cui (cherry picked from commit 62ac87fa63a41fa460ae3795cdeaf1db927d1588) --- .github/workflows/ci.yml | 2 +- .../agent/tools/SearchAlertsTool.java | 3 +- .../tools/SearchAnomalyDetectorsTool.java | 4 +- .../SearchAnomalyDetectorsToolTests.java | 14 ++++-- .../SearchAnomalyDetectorsToolIT.java | 43 ++++++++++--------- 5 files changed, 38 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aa65ae37..c5ba123a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -87,7 +87,7 @@ jobs: export FC=/usr/local/Cellar/gcc/12.2.0/bin/gfortran - name: Run build run: | - ./gradlew build + ./gradlew build -Dos.arch=x86_64 build-windows: strategy: diff --git a/src/main/java/org/opensearch/agent/tools/SearchAlertsTool.java b/src/main/java/org/opensearch/agent/tools/SearchAlertsTool.java index 5abd6121..7be36955 100644 --- a/src/main/java/org/opensearch/agent/tools/SearchAlertsTool.java +++ b/src/main/java/org/opensearch/agent/tools/SearchAlertsTool.java @@ -104,7 +104,8 @@ public void run(Map parameters, ActionListener listener) alertIndex, monitorIds, workflowIds, - alertIds + alertIds, + null ); // create response listener diff --git a/src/main/java/org/opensearch/agent/tools/SearchAnomalyDetectorsTool.java b/src/main/java/org/opensearch/agent/tools/SearchAnomalyDetectorsTool.java index e4a8e89d..c8e4ab8a 100644 --- a/src/main/java/org/opensearch/agent/tools/SearchAnomalyDetectorsTool.java +++ b/src/main/java/org/opensearch/agent/tools/SearchAnomalyDetectorsTool.java @@ -20,7 +20,6 @@ import org.opensearch.action.search.SearchResponse; import org.opensearch.ad.client.AnomalyDetectionNodeClient; import org.opensearch.ad.model.ADTask; -import org.opensearch.ad.transport.GetAnomalyDetectorRequest; import org.opensearch.ad.transport.GetAnomalyDetectorResponse; import org.opensearch.agent.tools.utils.ToolConstants; import org.opensearch.agent.tools.utils.ToolConstants.DetectorStateString; @@ -41,6 +40,7 @@ import org.opensearch.search.SearchHit; import org.opensearch.search.builder.SearchSourceBuilder; import org.opensearch.search.sort.SortOrder; +import org.opensearch.timeseries.transport.GetConfigRequest; import lombok.Getter; import lombok.Setter; @@ -164,7 +164,7 @@ public void run(Map parameters, ActionListener listener) listener.onFailure(e); }); - GetAnomalyDetectorRequest profileRequest = new GetAnomalyDetectorRequest( + GetConfigRequest profileRequest = new GetConfigRequest( hit.getId(), Versions.MATCH_ANY, false, diff --git a/src/test/java/org/opensearch/agent/tools/SearchAnomalyDetectorsToolTests.java b/src/test/java/org/opensearch/agent/tools/SearchAnomalyDetectorsToolTests.java index 8bf4de56..407690f6 100644 --- a/src/test/java/org/opensearch/agent/tools/SearchAnomalyDetectorsToolTests.java +++ b/src/test/java/org/opensearch/agent/tools/SearchAnomalyDetectorsToolTests.java @@ -32,7 +32,6 @@ import org.opensearch.action.ActionType; import org.opensearch.action.search.SearchResponse; import org.opensearch.ad.model.AnomalyDetector; -import org.opensearch.ad.model.IntervalTimeConfiguration; import org.opensearch.ad.transport.GetAnomalyDetectorAction; import org.opensearch.ad.transport.GetAnomalyDetectorResponse; import org.opensearch.ad.transport.SearchAnomalyDetectorAction; @@ -46,6 +45,7 @@ import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.ml.common.spi.tools.Tool; import org.opensearch.search.SearchHit; +import org.opensearch.timeseries.model.IntervalTimeConfiguration; public class SearchAnomalyDetectorsToolTests { @Mock @@ -85,6 +85,14 @@ public void setup() { Instant.now(), Collections.emptyList(), null, + null, + null, + null, + null, + null, + null, + null, + null, null ); } @@ -125,7 +133,7 @@ public void testRunWithSingleAnomalyDetector() throws Exception { content.field("last_update_time", testDetector.getLastUpdateTime().toEpochMilli()); content.endObject(); SearchHit[] hits = new SearchHit[1]; - hits[0] = new SearchHit(0, testDetector.getDetectorId(), null, null).sourceRef(BytesReference.bytes(content)); + hits[0] = new SearchHit(0, testDetector.getId(), null, null).sourceRef(BytesReference.bytes(content)); SearchResponse getDetectorsResponse = TestHelpers.generateSearchResponse(hits); String expectedResponseStr = getExpectedResponseString(testDetector); @@ -460,7 +468,7 @@ private String getExpectedResponseString(AnomalyDetector testDetector) { return String .format( "AnomalyDetectors=[{id=%s,name=%s,type=%s,description=%s,index=%s,lastUpdateTime=%d}]TotalAnomalyDetectors=%d", - testDetector.getDetectorId(), + testDetector.getId(), testDetector.getName(), testDetector.getDetectorType(), testDetector.getDescription(), diff --git a/src/test/java/org/opensearch/integTest/SearchAnomalyDetectorsToolIT.java b/src/test/java/org/opensearch/integTest/SearchAnomalyDetectorsToolIT.java index 7fdc593c..eb0c529d 100644 --- a/src/test/java/org/opensearch/integTest/SearchAnomalyDetectorsToolIT.java +++ b/src/test/java/org/opensearch/integTest/SearchAnomalyDetectorsToolIT.java @@ -8,6 +8,7 @@ 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; @@ -71,9 +72,9 @@ public void testSearchAnomalyDetectorsToolInFlowAgent_detectorNameParam() { String agentInput2 = "{\"parameters\":{\"detectorName\": \"" + detectorName + "\"}}"; String result2 = executeAgent(agentId, agentInput2); - assertTrue(result2.contains(String.format("id=%s", detectorId))); - assertTrue(result2.contains(String.format("name=%s", detectorName))); - assertTrue(result2.contains(String.format("TotalAnomalyDetectors=%d", 1))); + assertTrue(result2.contains(String.format(Locale.ROOT, "id=%s", detectorId))); + assertTrue(result2.contains(String.format(Locale.ROOT, "name=%s", detectorName))); + assertTrue(result2.contains(String.format(Locale.ROOT, "TotalAnomalyDetectors=%d", 1))); } finally { if (detectorId != null) { deleteDetector(detectorId); @@ -95,9 +96,9 @@ public void testSearchAnomalyDetectorsToolInFlowAgent_detectorNamePatternParam() String agentInput2 = "{\"parameters\":{\"detectorNamePattern\": \"" + detectorName + "*" + "\"}}"; String result2 = executeAgent(agentId, agentInput2); - assertTrue(result2.contains(String.format("id=%s", detectorId))); - assertTrue(result2.contains(String.format("name=%s", detectorName))); - assertTrue(result2.contains(String.format("TotalAnomalyDetectors=%d", 1))); + assertTrue(result2.contains(String.format(Locale.ROOT, "id=%s", detectorId))); + assertTrue(result2.contains(String.format(Locale.ROOT, "name=%s", detectorName))); + assertTrue(result2.contains(String.format(Locale.ROOT, "TotalAnomalyDetectors=%d", 1))); } finally { if (detectorId != null) { deleteDetector(detectorId); @@ -120,7 +121,7 @@ public void testSearchAnomalyDetectorsToolInFlowAgent_indicesParam() { String agentInput2 = "{\"parameters\":{\"indices\": \"test-index\"}}"; String result2 = executeAgent(agentId, agentInput2); - assertTrue(result2.contains(String.format("TotalAnomalyDetectors=%d", 1))); + assertTrue(result2.contains(String.format(Locale.ROOT, "TotalAnomalyDetectors=%d", 1))); } finally { if (detectorId != null) { deleteDetector(detectorId); @@ -143,9 +144,9 @@ public void testSearchAnomalyDetectorsToolInFlowAgent_highCardinalityParam() { String agentInput2 = "{\"parameters\":{\"highCardinality\": \"false\"}}"; String result2 = executeAgent(agentId, agentInput2); - assertTrue(result2.contains(String.format("id=%s", detectorId))); - assertTrue(result2.contains(String.format("name=%s", detectorName))); - assertTrue(result2.contains(String.format("TotalAnomalyDetectors=%d", 1))); + assertTrue(result2.contains(String.format(Locale.ROOT, "id=%s", detectorId))); + assertTrue(result2.contains(String.format(Locale.ROOT, "name=%s", detectorName))); + assertTrue(result2.contains(String.format(Locale.ROOT, "TotalAnomalyDetectors=%d", 1))); } finally { if (detectorId != null) { deleteDetector(detectorId); @@ -172,45 +173,45 @@ public void testSearchAnomalyDetectorsToolInFlowAgent_detectorStateParams() { String agentId = createAgent(registerAgentRequestBody); String agentInput = "{\"parameters\":{\"running\": \"true\"}}"; String result = executeAgent(agentId, agentInput); - assertTrue(result.contains(String.format("TotalAnomalyDetectors=%d", 1))); + assertTrue(result.contains(String.format(Locale.ROOT, "TotalAnomalyDetectors=%d", 1))); assertTrue(result.contains(detectorIdRunning)); String agentInput2 = "{\"parameters\":{\"running\": \"false\"}}"; String result2 = executeAgent(agentId, agentInput2); - assertTrue(result2.contains(String.format("TotalAnomalyDetectors=%d", 2))); + assertTrue(result2.contains(String.format(Locale.ROOT, "TotalAnomalyDetectors=%d", 2))); assertTrue(result2.contains(detectorIdDisabled1)); assertTrue(result2.contains(detectorIdDisabled2)); String agentInput3 = "{\"parameters\":{\"failed\": \"true\"}}"; String result3 = executeAgent(agentId, agentInput3); - assertTrue(result3.contains(String.format("TotalAnomalyDetectors=%d", 0))); + assertTrue(result3.contains(String.format(Locale.ROOT, "TotalAnomalyDetectors=%d", 0))); String agentInput4 = "{\"parameters\":{\"failed\": \"false\"}}"; String result4 = executeAgent(agentId, agentInput4); - assertTrue(result4.contains(String.format("TotalAnomalyDetectors=%d", 3))); + assertTrue(result4.contains(String.format(Locale.ROOT, "TotalAnomalyDetectors=%d", 3))); assertTrue(result4.contains(detectorIdRunning)); assertTrue(result4.contains(detectorIdDisabled1)); assertTrue(result4.contains(detectorIdDisabled2)); String agentInput5 = "{\"parameters\":{\"running\": \"true\", \"failed\": \"true\"}}"; String result5 = executeAgent(agentId, agentInput5); - assertTrue(result5.contains(String.format("TotalAnomalyDetectors=%d", 1))); + assertTrue(result5.contains(String.format(Locale.ROOT, "TotalAnomalyDetectors=%d", 1))); assertTrue(result5.contains(detectorIdRunning)); String agentInput6 = "{\"parameters\":{\"running\": \"true\", \"failed\": \"false\"}}"; String result6 = executeAgent(agentId, agentInput6); - assertTrue(result6.contains(String.format("TotalAnomalyDetectors=%d", 1))); + assertTrue(result6.contains(String.format(Locale.ROOT, "TotalAnomalyDetectors=%d", 1))); assertTrue(result6.contains(detectorIdRunning)); String agentInput7 = "{\"parameters\":{\"running\": \"false\", \"failed\": \"true\"}}"; String result7 = executeAgent(agentId, agentInput7); - assertTrue(result7.contains(String.format("TotalAnomalyDetectors=%d", 2))); + assertTrue(result7.contains(String.format(Locale.ROOT, "TotalAnomalyDetectors=%d", 2))); assertTrue(result7.contains(detectorIdDisabled1)); assertTrue(result7.contains(detectorIdDisabled2)); String agentInput8 = "{\"parameters\":{\"running\": \"false\", \"failed\": \"false\"}}"; String result8 = executeAgent(agentId, agentInput8); - assertTrue(result8.contains(String.format("TotalAnomalyDetectors=%d", 2))); + assertTrue(result8.contains(String.format(Locale.ROOT, "TotalAnomalyDetectors=%d", 2))); assertTrue(result8.contains(detectorIdDisabled1)); assertTrue(result8.contains(detectorIdDisabled2)); } finally { @@ -243,9 +244,9 @@ public void testSearchAnomalyDetectorsToolInFlowAgent_complexParams() { + detectorName + "\", \"highCardinality\": false, \"sortOrder\": \"asc\", \"sortString\": \"name.keyword\", \"size\": 10, \"startIndex\": 0 }}"; String result = executeAgent(agentId, agentInput); - assertTrue(result.contains(String.format("id=%s", detectorId))); - assertTrue(result.contains(String.format("name=%s", detectorName))); - assertTrue(result.contains(String.format("TotalAnomalyDetectors=%d", 1))); + assertTrue(result.contains(String.format(Locale.ROOT, "id=%s", detectorId))); + assertTrue(result.contains(String.format(Locale.ROOT, "name=%s", detectorName))); + assertTrue(result.contains(String.format(Locale.ROOT, "TotalAnomalyDetectors=%d", 1))); } finally { if (detectorId != null) { deleteDetector(detectorId);