Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a feature that flattens custom result index when enabled #1401

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update IT
Signed-off-by: Jackie Han <hnyng@amazon.com>
  • Loading branch information
jackiehanyang committed Jan 27, 2025
commit fb715c37ebd8b765e82993749c1ada3033b48c5a
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public void testCreateAnomalyDetectorWithDuplicateName() throws Exception {
public void testCreateAnomalyDetectorWithFlattenedResultIndex() throws Exception {
AnomalyDetector detector = createIndexAndGetAnomalyDetector(
INDEX_NAME,
ImmutableList.of(TestHelpers.randomFeature(true)),
ImmutableList.of(TestHelpers.randomFeature("feature_bytes", "agg", true)),
false,
true
);
Expand Down Expand Up @@ -230,8 +230,21 @@ public void testCreateAnomalyDetectorWithFlattenedResultIndex() throws Exception
// ensure the flattened result index was created
String expectedFlattenedIndex = String
.format(Locale.ROOT, "opensearch-ad-plugin-result-test_flattened_%s", id.toLowerCase(Locale.ROOT));
boolean indexExists = indexExists(expectedFlattenedIndex);
assertTrue(indexExists);
boolean aliasExists = aliasExists(expectedFlattenedIndex);
assertTrue(aliasExists);
// 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);
String getFlattenedResultIndexEndpoint = String
.format(Locale.ROOT, "/opensearch-ad-plugin-result-test_flattened_%s", id.toLowerCase(Locale.ROOT));
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"));

}

public void testCreateAnomalyDetector() throws Exception {
Expand Down
1 change: 1 addition & 0 deletions src/test/java/org/opensearch/timeseries/TestHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public class TestHelpers {
public static final String AD_BASE_RESULT_URI = AD_BASE_DETECTORS_URI + "/results";
public static final String AD_BASE_PREVIEW_URI = AD_BASE_DETECTORS_URI + "/%s/_preview";
public static final String AD_BASE_STATS_URI = "/_plugins/_anomaly_detection/stats";
public static final String AD_BASE_START_DETECTOR_URL = AD_BASE_DETECTORS_URI + "/%s/_start";
public static ImmutableSet<String> HISTORICAL_ANALYSIS_RUNNING_STATS = ImmutableSet
.of(TaskState.CREATED.name(), TaskState.INIT.name(), TaskState.RUNNING.name());
// Task may fail if memory circuit breaker triggered.
Expand Down
Loading