Skip to content

Commit

Permalink
clean up
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 499e7ea commit f079baf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,14 @@ public void initFlattenedResultIndex(String flattenedResultIndexAlias, ActionLis
}));
}

public String getFlattenedResultIndexAlias(String indexOrAliasName, String configId) {
return indexOrAliasName + "_flattened_" + configId.toLowerCase(Locale.ROOT);
}

public String getFlattenResultIndexIngestPipelineId(String configId) {
return "flatten_result_index_ingest_pipeline" + configId.toLowerCase(Locale.ROOT);
}

public <T> void validateCustomIndexForBackendJob(
String resultIndexOrAlias,
String securityLogId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,14 +454,6 @@ protected void prepareConfigIndexing(boolean indexingDryRun, ActionListener<T> l
}
}

private String getFlattenedResultIndexAlias(String configId) {
return config.getCustomResultIndexOrAlias() + "_flattened_" + configId.toLowerCase(Locale.ROOT);
}

private String getFlattenResultIndexIngestPipelineId(String configId) {
return "flatten_result_index_ingest_pipeline" + configId.toLowerCase(Locale.ROOT);
}

private void handlePutRequest(boolean indexingDryRun, ActionListener<T> listener) {
handler.confirmJobRunning(clusterService, client, id, listener, () -> {
handleFlattenResultIndexMappingUpdate(listener);
Expand All @@ -474,8 +466,9 @@ private void handlePostRequest(boolean indexingDryRun, ActionListener<T> listene
if (shouldHandleFlattening(indexingDryRun, createConfigResponse)) {
IndexAnomalyDetectorResponse response = (IndexAnomalyDetectorResponse) createConfigResponse;
String configId = response.getId();
String flattenedResultIndexAlias = getFlattenedResultIndexAlias(configId);
String pipelineId = getFlattenResultIndexIngestPipelineId(configId);
String flattenedResultIndexAlias = timeSeriesIndices
.getFlattenedResultIndexAlias(config.getCustomResultIndexOrAlias(), configId);
String pipelineId = timeSeriesIndices.getFlattenResultIndexIngestPipelineId(configId);

timeSeriesIndices
.initFlattenedResultIndex(
Expand Down Expand Up @@ -504,8 +497,8 @@ private boolean shouldHandleFlattening(boolean indexingDryRun, Object createConf
}

protected void setupIngestPipeline(String configId, ActionListener<T> listener) {
String flattenedResultIndexAlias = getFlattenedResultIndexAlias(configId);
String pipelineId = getFlattenResultIndexIngestPipelineId(configId);
String flattenedResultIndexAlias = timeSeriesIndices.getFlattenedResultIndexAlias(config.getCustomResultIndexOrAlias(), configId);
String pipelineId = timeSeriesIndices.getFlattenResultIndexIngestPipelineId(configId);

try {
BytesReference pipelineSource = createPipelineDefinition(flattenedResultIndexAlias);
Expand Down Expand Up @@ -588,7 +581,7 @@ private void handleFlattenResultIndexMappingUpdate(ActionListener<T> listener) {
if (config.getFlattenResultIndexMapping() != null && config.getFlattenResultIndexMapping()) {
setupIngestPipeline(id, listener);
} else {
String pipelineId = getFlattenResultIndexIngestPipelineId(config.getId());
String pipelineId = timeSeriesIndices.getFlattenResultIndexIngestPipelineId(config.getId());
client.admin().cluster().deletePipeline(new DeletePipelineRequest(pipelineId), new ActionListener<AcknowledgedResponse>() {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ public void testParseAnomalyDetector_withCustomIndex_withFlattenResultIndexMappi
+ "\"aggregation_query\":{\"XzewX\":{\"value_count\":{\"field\":\"ok\"}}}}],\"recency_emphasis\":3342,"
+ "\"history\":62,\"last_update_time\":1717192049845,\"category_field\":[\"Tcqcb\"],\"result_index\":"
+ "\"opensearch-ad-plugin-result-test\",\"imputation_option\":{\"method\":\"ZERO\"},\"suggested_seasonality\":64,\"detection_interval\":{\"period\":"
+ "{\"interval\":5,\"unit\":\"Minutes\"}},\"detector_type\":\"MULTI_ENTITY\",\"rules\":[],\"flatten_result_index_mapping\":true}";
+ "{\"interval\":5,\"unit\":\"Minutes\"}},\"detector_type\":\"MULTI_ENTITY\",\"rules\":[],\"flatten_custom_result_index\":true}";
AnomalyDetector parsedDetector = AnomalyDetector.parse(TestHelpers.parser(detectorString), "id", 1L, null, null);
assertEquals(true, (boolean) parsedDetector.getFlattenResultIndexMapping());
}
Expand Down

0 comments on commit f079baf

Please sign in to comment.