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

[Backport 2.4] removed grouped listener when fetching findings #127

Merged
merged 1 commit into from
Nov 9, 2022
Merged
Changes from all commits
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
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