Skip to content

Commit 499e7ea

Browse files
committed
update IT
Signed-off-by: Jackie Han <hnyng@amazon.com>
1 parent fb715c3 commit 499e7ea

File tree

4 files changed

+19
-180
lines changed

4 files changed

+19
-180
lines changed

src/main/java/org/opensearch/ad/settings/AnomalyDetectorSettings.java

-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ private AnomalyDetectorSettings() {}
190190
);
191191

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

src/main/java/org/opensearch/timeseries/rest/handler/AbstractTimeSeriesActionHandler.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,11 @@ private void handlePostRequest(boolean indexingDryRun, ActionListener<T> listene
495495
}
496496

497497
private boolean shouldHandleFlattening(boolean indexingDryRun, Object createConfigResponse) {
498+
Boolean flattenResultIndexMapping = config.getFlattenResultIndexMapping();
499+
498500
return !indexingDryRun
499501
&& config.getCustomResultIndexOrAlias() != null
500-
&& config.getFlattenResultIndexMapping()
502+
&& Boolean.TRUE.equals(flattenResultIndexMapping)
501503
&& createConfigResponse instanceof IndexAnomalyDetectorResponse;
502504
}
503505

src/main/resources/mappings/anomaly-results-flattened.json

-173
This file was deleted.

src/test/java/org/opensearch/ad/rest/AnomalyDetectorRestApiIT.java

+16-5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.stream.Collectors;
2828

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

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

250261
public void testCreateAnomalyDetector() throws Exception {

0 commit comments

Comments
 (0)