Skip to content

Commit

Permalink
Fix build error due to upstream change (#316)
Browse files Browse the repository at this point in the history
* fix build error due to upstream change

Signed-off-by: Hailong Cui <[email protected]>

* failed unit test

Signed-off-by: Hailong Cui <[email protected]>

* fix compile error

Signed-off-by: Hailong Cui <[email protected]>

* fix flaky test for locale mr

Signed-off-by: Hailong Cui <[email protected]>

* force to use x86_64 for macos

Signed-off-by: Hailong Cui <[email protected]>

---------

Signed-off-by: Hailong Cui <[email protected]>
(cherry picked from commit 62ac87f)
  • Loading branch information
Hailong-am committed Jun 6, 2024
1 parent e2da02d commit d4e9994
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public <T> void run(Map<String, String> parameters, ActionListener<T> listener)
alertIndex,
monitorIds,
workflowIds,
alertIds
alertIds,
null
);

// create response listener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -164,7 +164,7 @@ public <T> void run(Map<String, String> parameters, ActionListener<T> listener)
listener.onFailure(e);
});

GetAnomalyDetectorRequest profileRequest = new GetAnomalyDetectorRequest(
GetConfigRequest profileRequest = new GetConfigRequest(
hit.getId(),
Versions.MATCH_ANY,
false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -85,6 +85,14 @@ public void setup() {
Instant.now(),
Collections.emptyList(),
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
);
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d4e9994

Please sign in to comment.