diff --git a/src/main/java/org/opensearch/securityanalytics/mapper/MapperService.java b/src/main/java/org/opensearch/securityanalytics/mapper/MapperService.java index a17583df7..89e90cbba 100644 --- a/src/main/java/org/opensearch/securityanalytics/mapper/MapperService.java +++ b/src/main/java/org/opensearch/securityanalytics/mapper/MapperService.java @@ -78,8 +78,10 @@ public void createMappingAction(String indexName, String logType, String aliasMa String index = indexName; boolean shouldUpsertIndexTemplate = IndexUtils.isConcreteIndex(indexName, this.clusterService.state()) == false; if (IndexUtils.isDataStream(indexName, this.clusterService.state()) || IndexUtils.isAlias(indexName, this.clusterService.state())) { + log.debug("PERF_DEBUG_SAP: {} is an alias or datastream. Fetching write index.", indexName); String writeIndex = IndexUtils.getWriteIndex(indexName, this.clusterService.state()); if (writeIndex != null) { + log.debug("PERF_DEBUG_SAP: Write index for {} is {}",indexName, writeIndex ); index = writeIndex; } } @@ -91,6 +93,7 @@ public void onResponse(GetMappingsResponse getMappingsResponse) { applyAliasMappings(getMappingsResponse.getMappings(), logType, aliasMappings, partial, new ActionListener<>() { @Override public void onResponse(Collection createMappingResponse) { + log.debug("PERF_DEBUG_SAP: Completed create mappings for {}", indexName); // We will return ack==false if one of the requests returned that // else return ack==true Optional notAckd = createMappingResponse.stream() @@ -109,6 +112,7 @@ public void onResponse(Collection createMappingResponse) { @Override public void onFailure(Exception e) { + log.debug("PERF_DEBUG_SAP: Failed to create mappings for {}", indexName ); actionListener.onFailure(e); } }); diff --git a/src/main/java/org/opensearch/securityanalytics/transport/TransportIndexDetectorAction.java b/src/main/java/org/opensearch/securityanalytics/transport/TransportIndexDetectorAction.java index bb869932d..bd8a806b1 100644 --- a/src/main/java/org/opensearch/securityanalytics/transport/TransportIndexDetectorAction.java +++ b/src/main/java/org/opensearch/securityanalytics/transport/TransportIndexDetectorAction.java @@ -117,7 +117,6 @@ import java.util.Locale; import java.util.Map; import java.util.Set; -import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; @@ -1361,16 +1360,14 @@ public void onFailure(Exception e) { }); } - private void upsertMonitorFromQueries(List> queries, Detector detector, String logIndex, ActionListener> listener) throws Exception { - logger.error("PERF_DEBUG: Fetching alias path pairs to construct rule_field_names"); + private void upsertMonitorFromQueries(List> queries, Detector detector, String logIndex, ActionListener> listener) { + logger.error("PERF_DEBUG_SAP: Fetching alias path pairs to construct rule_field_names"); long start = System.currentTimeMillis(); Set ruleFieldNames = new HashSet<>(); for (Pair query : queries) { List queryFieldNames = query.getValue().getQueryFieldNames().stream().map(Value::getValue).collect(Collectors.toList()); ruleFieldNames.addAll(queryFieldNames); } - - CountDownLatch indexMappingsLatch = new CountDownLatch(1); client.execute(GetIndexMappingsAction.INSTANCE, new GetIndexMappingsRequest(logIndex), new ActionListener<>() { @Override public void onResponse(GetIndexMappingsResponse getMappingsViewResponse) { @@ -1384,13 +1381,18 @@ public void onResponse(GetIndexMappingsResponse getMappingsViewResponse) { ruleFieldNames.add(aliasPathPair.getRight()); } } + long took = System.currentTimeMillis() - start; + log.error("PERF_DEBUG_SAP: completed collecting rule_field_names in {} millis", took); + if (request.getMethod() == Method.POST) { + createMonitorFromQueries(queries, detector, listener, request.getRefreshPolicy(), new ArrayList<>(ruleFieldNames)); + } else if (request.getMethod() == Method.PUT) { + updateMonitorFromQueries(logIndex, queries, detector, listener, request.getRefreshPolicy(), new ArrayList<>(ruleFieldNames)); + } } catch (Exception e) { - logger.error("Failure in parsing rule field names/aliases while " + + logger.error("PERF_DEBUG_SAP: Failure in parsing rule field names/aliases while " + detector.getId() == null ? "creating" : "updating" + " detector. Not optimizing detector queries with relevant fields", e); ruleFieldNames.clear(); - } finally { - indexMappingsLatch.countDown(); } } @@ -1399,17 +1401,8 @@ public void onResponse(GetIndexMappingsResponse getMappingsViewResponse) { public void onFailure(Exception e) { log.error("Failed to fetch mappings view response for log index " + logIndex, e); listener.onFailure(e); - indexMappingsLatch.countDown(); } }); - indexMappingsLatch.await(); - long took = System.currentTimeMillis() - start; - log.error("PERF_DEBUG: completed collecting rule_field_names in {} millis", took); - if (request.getMethod() == Method.POST) { - createMonitorFromQueries(queries, detector, listener, request.getRefreshPolicy(), new ArrayList<>(ruleFieldNames)); - } else if (request.getMethod() == Method.PUT) { - updateMonitorFromQueries(logIndex, queries, detector, listener, request.getRefreshPolicy(), new ArrayList<>(ruleFieldNames)); - } } @SuppressWarnings("unchecked")