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.10] fix flaky integration tests #586

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
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 @@ -292,24 +292,5 @@ public void onFailure(Exception e) {
log.warn("Failed to initialize LogType config index and builtin log types");
}
});
// Trigger initialization of prepackaged rules by calling SearchRule API
SearchRequest searchRequest = new SearchRequest(Rule.PRE_PACKAGED_RULES_INDEX);
searchRequest.source(new SearchSourceBuilder().query(QueryBuilders.matchAllQuery()).size(0));
searchRequest.preference(Preference.PRIMARY_FIRST.type());
client.execute(
SearchRuleAction.INSTANCE,
new SearchRuleRequest(true, searchRequest),
new ActionListener<>() {
@Override
public void onResponse(SearchResponse searchResponse) {
log.info("Successfully initialized prepackaged rules");
}

@Override
public void onFailure(Exception e) {
log.warn("Failed initializing prepackaged rules", e);
}
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public void initRuleIndex(ActionListener<CreateIndexResponse> actionListener, bo
if (!ruleIndexExists(isPrepackaged)) {
Settings indexSettings = Settings.builder()
.put("index.hidden", true)
.put("index.auto_expand_replicas", "0-all")
.build();
CreateIndexRequest indexRequest = new CreateIndexRequest(getRuleIndex(isPrepackaged))
.mapping(ruleMappings())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ protected List<Map<String, Object>> searchCorrelatedFindings(String findingId, S
}

@Before
void setDebugLogLevel() throws IOException {
void setDebugLogLevel() throws IOException, InterruptedException {
StringEntity se = new StringEntity("{\n" +
" \"transient\": {\n" +
" \"logger.org.opensearch.securityanalytics\":\"DEBUG\",\n" +
Expand Down Expand Up @@ -477,30 +477,13 @@ protected Response refreshIndex(String index) throws IOException {

@SuppressWarnings("unchecked")
protected List<String> getRandomPrePackagedRules() throws IOException {
String request = "{\n" +
" \"from\": 0\n," +
" \"size\": 2000\n," +
" \"query\": {\n" +
" \"nested\": {\n" +
" \"path\": \"rule\",\n" +
" \"query\": {\n" +
" \"bool\": {\n" +
" \"must\": [\n" +
" { \"match\": {\"rule.category\": \"" + TestHelpers.randomDetectorType().toLowerCase(Locale.ROOT) + "\"}}\n" +
" ]\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
"}";

Response searchResponse = makeRequest(client(), "POST", String.format(Locale.getDefault(), "%s/_search", SecurityAnalyticsPlugin.RULE_BASE_URI), Collections.singletonMap("pre_packaged", "true"),
new StringEntity(request), new BasicHeader("Content-Type", "application/json"));
Assert.assertEquals("Searching rules failed", RestStatus.OK, restStatus(searchResponse));

Map<String, Object> responseBody = asMap(searchResponse);
List<Map<String, Object>> hits = ((List<Map<String, Object>>) ((Map<String, Object>) responseBody.get("hits")).get("hits"));
return hits.stream().map(hit -> hit.get("_id").toString()).collect(Collectors.toList());
return List.of(
"36a037c4-c228-4866-b6a3-48eb292b9955",
"c6e91a02-d771-4a6d-a700-42587e0b1095",
"5a919691-7302-437f-8e10-1fe088afa145",
"e5a6b256-3e47-40fc-89d2-7a477edd6915",
"06724b9a-52fc-11ed-bdc3-0242ac120002"
);
}

protected List<String> createAggregationRules () throws IOException {
Expand Down
Loading