Skip to content

Commit

Permalink
update IT
Browse files Browse the repository at this point in the history
Signed-off-by: Jackie Han <[email protected]>
  • Loading branch information
jackiehanyang committed Jan 27, 2025
1 parent fb715c3 commit 499e7ea
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ private AnomalyDetectorSettings() {}
);

public static final String ANOMALY_RESULTS_INDEX_MAPPING_FILE = "mappings/anomaly-results.json";
public static final String FLATTENED_ANOMALY_RESULTS_INDEX_MAPPING_FILE = "mappings/anomaly-results-flattened.json";
public static final String ANOMALY_DETECTION_STATE_INDEX_MAPPING_FILE = "mappings/anomaly-detection-state.json";
public static final String CHECKPOINT_INDEX_MAPPING_FILE = "mappings/anomaly-checkpoint.json";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,11 @@ private void handlePostRequest(boolean indexingDryRun, ActionListener<T> listene
}

private boolean shouldHandleFlattening(boolean indexingDryRun, Object createConfigResponse) {
Boolean flattenResultIndexMapping = config.getFlattenResultIndexMapping();

return !indexingDryRun
&& config.getCustomResultIndexOrAlias() != null
&& config.getFlattenResultIndexMapping()
&& Boolean.TRUE.equals(flattenResultIndexMapping)
&& createConfigResponse instanceof IndexAnomalyDetectorResponse;
}

Expand Down
173 changes: 0 additions & 173 deletions src/main/resources/mappings/anomaly-results-flattened.json

This file was deleted.

21 changes: 16 additions & 5 deletions src/test/java/org/opensearch/ad/rest/AnomalyDetectorRestApiIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.stream.Collectors;

import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.io.entity.StringEntity;
import org.hamcrest.CoreMatchers;
import org.junit.Assert;
Expand Down Expand Up @@ -235,16 +236,26 @@ public void testCreateAnomalyDetectorWithFlattenedResultIndex() throws Exception
// ensure that the flattened field "feature_data_feature_bytes" exists in the mappings
String startDetectorEndpoint = String.format(Locale.ROOT, TestHelpers.AD_BASE_START_DETECTOR_URL, id);
Response startDetectorResponse = TestHelpers
.makeRequest(client(), "POST", startDetectorEndpoint, ImmutableMap.of(), TestHelpers.toHttpEntity(detector), null);
.makeRequest(client(), "POST", startDetectorEndpoint, ImmutableMap.of(), (HttpEntity) null, null);
String getFlattenedResultIndexEndpoint = String
.format(Locale.ROOT, "/opensearch-ad-plugin-result-test_flattened_%s", id.toLowerCase(Locale.ROOT));
// wait for the detector starts writing result
try {
Thread.sleep(60 * 1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException("Thread was interrupted while waiting", e);
}
Response getIndexResponse = TestHelpers.makeRequest(client(), "GET", getFlattenedResultIndexEndpoint, ImmutableMap.of(), "", null);
Map<String, Object> flattenedResultIndex = entityAsMap(getIndexResponse);
Map<String, Object> mappings = (Map<String, Object>) flattenedResultIndex
.get("opensearch-ad-plugin-result-test_flattened_" + id.toLowerCase(Locale.ROOT));
Map<String, Object> properties = (Map<String, Object>) ((Map<String, Object>) mappings.get("mappings")).get("properties");
assertTrue("Flattened field 'feature_data_feature_bytes' does not exist", properties.containsKey("feature_data_feature_bytes"));

String indexKey = flattenedResultIndex.keySet().stream().findFirst().orElse(null);
Map<String, Object> indexDetails = (Map<String, Object>) flattenedResultIndex.get(indexKey);
Map<String, Object> mappings = (Map<String, Object>) indexDetails.get("mappings");
Object dynamicValue = mappings.get("dynamic");
assertEquals("Dynamic field is not set to true", "true", dynamicValue.toString());
Map<String, Object> properties = (Map<String, Object>) mappings.get("properties");
assertTrue("Flattened field 'feature_data_feature_bytes' does not exist", properties.containsKey("feature_data_feature_bytes"));
}

public void testCreateAnomalyDetector() throws Exception {
Expand Down

0 comments on commit 499e7ea

Please sign in to comment.