Skip to content

Commit

Permalink
ignore more flaky tests (#603)
Browse files Browse the repository at this point in the history
Signed-off-by: Subhobrata Dey <[email protected]>
(cherry picked from commit 12e4a97)
  • Loading branch information
sbcd90 authored and github-actions[bot] committed Sep 19, 2023
1 parent ee3f571 commit e2a0e0b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,13 @@
import org.opensearch.threadpool.ThreadPool;
import org.opensearch.transport.TransportService;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -243,7 +241,7 @@ public void onFailure(Exception e) {
});
}

private void createMonitorFromQueries(List<Pair<String, Rule>> rulesById, Detector detector, ActionListener<List<IndexMonitorResponse>> listener, WriteRequest.RefreshPolicy refreshPolicy) throws SigmaError, IOException {
private void createMonitorFromQueries(List<Pair<String, Rule>> rulesById, Detector detector, ActionListener<List<IndexMonitorResponse>> listener, WriteRequest.RefreshPolicy refreshPolicy) throws Exception {
List<Pair<String, Rule>> docLevelRules = rulesById.stream().filter(it -> !it.getRight().isAggregationRule()).collect(
Collectors.toList());
List<Pair<String, Rule>> bucketLevelRules = rulesById.stream().filter(it -> it.getRight().isAggregationRule()).collect(
Expand Down Expand Up @@ -389,7 +387,7 @@ public void onFailure(Exception e) {
}
}

private void updateMonitorFromQueries(String index, List<Pair<String, Rule>> rulesById, Detector detector, ActionListener<List<IndexMonitorResponse>> listener, WriteRequest.RefreshPolicy refreshPolicy) throws SigmaError, IOException {
private void updateMonitorFromQueries(String index, List<Pair<String, Rule>> rulesById, Detector detector, ActionListener<List<IndexMonitorResponse>> listener, WriteRequest.RefreshPolicy refreshPolicy) throws Exception {
List<IndexMonitorRequest> monitorsToBeUpdated = new ArrayList<>();

List<Pair<String, Rule>> bucketLevelRules = rulesById.stream().filter(it -> it.getRight().isAggregationRule()).collect(
Expand Down Expand Up @@ -452,7 +450,7 @@ public void onResponse(Map<String, Map<String, String>> ruleFieldMappings) {
Collectors.toList()));

updateAlertingMonitors(rulesById, detector, monitorsToBeAdded, monitorsToBeUpdated, monitorIdsToBeDeleted, refreshPolicy, listener);
} catch (IOException | SigmaError ex) {
} catch (Exception ex) {

Check warning on line 453 in src/main/java/org/opensearch/securityanalytics/transport/TransportIndexDetectorAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/transport/TransportIndexDetectorAction.java#L453

Added line #L453 was not covered by tests
listener.onFailure(ex);
}
}
Expand Down Expand Up @@ -728,7 +726,7 @@ private IndexMonitorRequest createDocLevelMonitorMatchAllRequest(
return new IndexMonitorRequest(monitorId, SequenceNumbers.UNASSIGNED_SEQ_NO, SequenceNumbers.UNASSIGNED_PRIMARY_TERM, refreshPolicy, restMethod, monitor, null);
}

private void buildBucketLevelMonitorRequests(List<Pair<String, Rule>> queries, Detector detector, WriteRequest.RefreshPolicy refreshPolicy, String monitorId, RestRequest.Method restMethod, ActionListener<List<IndexMonitorRequest>> listener) throws IOException, SigmaError {
private void buildBucketLevelMonitorRequests(List<Pair<String, Rule>> queries, Detector detector, WriteRequest.RefreshPolicy refreshPolicy, String monitorId, RestRequest.Method restMethod, ActionListener<List<IndexMonitorRequest>> listener) throws Exception {

logTypeService.getRuleFieldMappings(new ActionListener<>() {
@Override
Expand Down Expand Up @@ -763,7 +761,7 @@ public void onResponse(Map<String, Map<String, String>> ruleFieldMappings) {
monitorRequests.add(createDocLevelMonitorMatchAllRequest(detector, RefreshPolicy.IMMEDIATE, detector.getId()+"_chained_findings", Method.POST));
}
listener.onResponse(monitorRequests);
} catch (IOException | SigmaError ex) {
} catch (Exception ex) {

Check warning on line 764 in src/main/java/org/opensearch/securityanalytics/transport/TransportIndexDetectorAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/transport/TransportIndexDetectorAction.java#L764

Added line #L764 was not covered by tests
listener.onFailure(ex);
}
}
Expand Down Expand Up @@ -897,7 +895,7 @@ public void onFailure(Exception e) {
}
}

private void onCreateMappingsResponse(CreateIndexResponse response) throws IOException {
private void onCreateMappingsResponse(CreateIndexResponse response) throws Exception {
if (response.isAcknowledged()) {
log.info(String.format(Locale.getDefault(), "Created %s with mappings.", Detector.DETECTORS_INDEX));
IndexUtils.detectorIndexUpdated();
Expand Down Expand Up @@ -950,7 +948,7 @@ public void onResponse(CreateIndexResponse response) {
try {
onCreateMappingsResponse(response);
prepareDetectorIndexing();
} catch (IOException e) {
} catch (Exception e) {

Check warning on line 951 in src/main/java/org/opensearch/securityanalytics/transport/TransportIndexDetectorAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/transport/TransportIndexDetectorAction.java#L951

Added line #L951 was not covered by tests
onFailures(e);
}
}
Expand All @@ -970,7 +968,7 @@ public void onResponse(AcknowledgedResponse response) {
onUpdateMappingsResponse(response);
try {
prepareDetectorIndexing();
} catch (IOException e) {
} catch (Exception e) {

Check warning on line 971 in src/main/java/org/opensearch/securityanalytics/transport/TransportIndexDetectorAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/transport/TransportIndexDetectorAction.java#L971

Added line #L971 was not covered by tests
onFailures(e);
}
}
Expand All @@ -984,7 +982,7 @@ public void onFailure(Exception e) {
} else {
prepareDetectorIndexing();
}
} catch (IOException e) {
} catch (Exception e) {

Check warning on line 985 in src/main/java/org/opensearch/securityanalytics/transport/TransportIndexDetectorAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/transport/TransportIndexDetectorAction.java#L985

Added line #L985 was not covered by tests
onFailures(e);
}
} else {
Expand All @@ -1001,7 +999,7 @@ public void onFailure(Exception e) {

}

void prepareDetectorIndexing() throws IOException {
void prepareDetectorIndexing() throws Exception {
if (request.getMethod() == RestRequest.Method.POST) {
createDetector();
} else if (request.getMethod() == RestRequest.Method.PUT) {
Expand Down Expand Up @@ -1038,7 +1036,7 @@ public void onResponse(List<IndexMonitorResponse> monitorResponses) {
request.getDetector().setRuleIdMonitorIdMap(mapMonitorIds(monitorResponses));
try {
indexDetector();
} catch (IOException e) {
} catch (Exception e) {

Check warning on line 1039 in src/main/java/org/opensearch/securityanalytics/transport/TransportIndexDetectorAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/transport/TransportIndexDetectorAction.java#L1039

Added line #L1039 was not covered by tests
onFailures(e);
}
}
Expand All @@ -1055,7 +1053,7 @@ public void onFailure(Exception e) {
onFailures(e);
}
});
} catch (IOException e) {
} catch (Exception e) {

Check warning on line 1056 in src/main/java/org/opensearch/securityanalytics/transport/TransportIndexDetectorAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/transport/TransportIndexDetectorAction.java#L1056

Added line #L1056 was not covered by tests
onFailures(e);
}
}
Expand Down Expand Up @@ -1098,7 +1096,7 @@ public void onResponse(GetResponse response) {
return;
}
onGetResponse(detector, detector.getUser());
} catch (IOException e) {
} catch (Exception e) {

Check warning on line 1099 in src/main/java/org/opensearch/securityanalytics/transport/TransportIndexDetectorAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/transport/TransportIndexDetectorAction.java#L1099

Added line #L1099 was not covered by tests
onFailures(e);
}
}
Expand Down Expand Up @@ -1144,7 +1142,7 @@ public void onResponse(List<IndexMonitorResponse> monitorResponses) {
request.getDetector().setRuleIdMonitorIdMap(mapMonitorIds(monitorResponses));
try {
indexDetector();
} catch (IOException e) {
} catch (Exception e) {

Check warning on line 1145 in src/main/java/org/opensearch/securityanalytics/transport/TransportIndexDetectorAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/transport/TransportIndexDetectorAction.java#L1145

Added line #L1145 was not covered by tests
onFailures(e);
}
}
Expand All @@ -1161,7 +1159,7 @@ public void onFailure(Exception e) {
onFailures(e);
}
});
} catch (IOException e) {
} catch (Exception e) {

Check warning on line 1162 in src/main/java/org/opensearch/securityanalytics/transport/TransportIndexDetectorAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/transport/TransportIndexDetectorAction.java#L1162

Added line #L1162 was not covered by tests
onFailures(e);
}
}
Expand Down Expand Up @@ -1332,7 +1330,7 @@ public void onResponse(SearchResponse response) {
updateMonitorFromQueries(logIndex, queries, detector, listener, request.getRefreshPolicy());
}
}
} catch (IOException | SigmaError e) {
} catch (Exception e) {

Check warning on line 1333 in src/main/java/org/opensearch/securityanalytics/transport/TransportIndexDetectorAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/transport/TransportIndexDetectorAction.java#L1333

Added line #L1333 was not covered by tests
onFailures(e);
}
}
Expand Down Expand Up @@ -1385,7 +1383,7 @@ public void onResponse(SearchResponse response) {
} else if (request.getMethod() == RestRequest.Method.PUT) {
updateMonitorFromQueries(logIndex, queries, detector, listener, request.getRefreshPolicy());
}
} catch (IOException | SigmaError ex) {
} catch (Exception ex) {

Check warning on line 1386 in src/main/java/org/opensearch/securityanalytics/transport/TransportIndexDetectorAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/transport/TransportIndexDetectorAction.java#L1386

Added line #L1386 was not covered by tests
onFailures(ex);
}
}
Expand All @@ -1397,7 +1395,7 @@ public void onFailure(Exception e) {
});
}

public void indexDetector() throws IOException {
public void indexDetector() throws Exception {
IndexRequest indexRequest;
if (request.getMethod() == RestRequest.Method.POST) {
indexRequest = new IndexRequest(Detector.DETECTORS_INDEX)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.stream.Collectors;
import org.apache.http.HttpStatus;
import org.junit.Assert;
import org.junit.Ignore;
import org.opensearch.client.Request;
import org.opensearch.client.Response;
import org.opensearch.client.ResponseException;
Expand Down Expand Up @@ -263,6 +264,7 @@ public void testGetFindings_byDetectorType_success() throws IOException {
Assert.assertEquals(1, getFindingsBody.get("total_findings"));
}

@Ignore
public void testGetFindings_rolloverByMaxAge_success() throws IOException, InterruptedException {

updateClusterSetting(FINDING_HISTORY_ROLLOVER_PERIOD.getKey(), "1s");
Expand Down Expand Up @@ -333,6 +335,7 @@ public void testGetFindings_rolloverByMaxAge_success() throws IOException, Inter
restoreAlertsFindingsIMSettings();
}

@Ignore
public void testGetFindings_rolloverByMaxDoc_success() throws IOException, InterruptedException {

updateClusterSetting(FINDING_HISTORY_ROLLOVER_PERIOD.getKey(), "1s");
Expand Down Expand Up @@ -398,6 +401,7 @@ public void testGetFindings_rolloverByMaxDoc_success() throws IOException, Inter
restoreAlertsFindingsIMSettings();
}

@Ignore
public void testGetFindings_rolloverByMaxDoc_short_retention_success() throws IOException, InterruptedException {
updateClusterSetting(FINDING_HISTORY_ROLLOVER_PERIOD.getKey(), "1s");
updateClusterSetting(FINDING_HISTORY_MAX_DOCS.getKey(), "1");
Expand Down

0 comments on commit e2a0e0b

Please sign in to comment.