Skip to content

Commit

Permalink
removed grouped listener when fetching findings (opensearch-project#124)
Browse files Browse the repository at this point in the history
Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>
  • Loading branch information
petardz committed Nov 9, 2022
1 parent db97ea9 commit bb7ffb5
Showing 1 changed file with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package org.opensearch.securityanalytics.findings;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -14,7 +13,6 @@
import org.apache.logging.log4j.Logger;
import org.opensearch.OpenSearchStatusException;
import org.opensearch.action.ActionListener;
import org.opensearch.action.support.GroupedActionListener;
import org.opensearch.client.Client;
import org.opensearch.client.node.NodeClient;
import org.opensearch.commons.alerting.AlertingPluginInterface;
Expand Down Expand Up @@ -60,17 +58,15 @@ public void onResponse(GetDetectorResponse getDetectorResponse) {
// Get all monitor ids from detector
Detector detector = getDetectorResponse.getDetector();
List<String> monitorIds = detector.getMonitorIds();
// Using GroupedActionListener here as we're going to issue one GetFindingsActions for each monitorId
ActionListener<GetFindingsResponse> multiGetFindingsListener = new GroupedActionListener<>(new ActionListener<>() {
ActionListener<GetFindingsResponse> getFindingsResponseListener = new ActionListener<>() {
@Override
public void onResponse(Collection<GetFindingsResponse> responses) {
public void onResponse(GetFindingsResponse resp) {
Integer totalFindings = 0;
List<FindingDto> findings = new ArrayList<>();
// Merge all findings into one response
for(GetFindingsResponse resp : responses) {
totalFindings += resp.getTotalFindings();
findings.addAll(resp.getFindings());
}
totalFindings += resp.getTotalFindings();
findings.addAll(resp.getFindings());

GetFindingsResponse masterResponse = new GetFindingsResponse(
totalFindings,
findings
Expand All @@ -84,7 +80,7 @@ public void onFailure(Exception e) {
log.error("Failed to fetch findings for detector " + detectorId, e);
listener.onFailure(SecurityAnalyticsException.wrap(e));
}
}, monitorIds.size());
};

// monitor --> detectorId mapping
Map<String, String> monitorToDetectorMapping = new HashMap<>();
Expand All @@ -97,7 +93,7 @@ public void onFailure(Exception e) {
monitorIds,
DetectorMonitorConfig.getFindingsIndex(detector.getDetectorType()),
table,
multiGetFindingsListener
getFindingsResponseListener
);
}

Expand Down

0 comments on commit bb7ffb5

Please sign in to comment.