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

Address search request timeouts as transient error #561

Merged
merged 3 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -228,7 +228,7 @@
@Override
public void onResponse(SearchResponse response) {
if (response.isTimedOut()) {
correlateFindingAction.onFailures(new OpenSearchStatusException(response.toString(), RestStatus.REQUEST_TIMEOUT));
correlateFindingAction.onFailures(new OpenSearchStatusException("Search request timed out", RestStatus.REQUEST_TIMEOUT));

Check warning on line 231 in src/main/java/org/opensearch/securityanalytics/correlation/JoinEngine.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/correlation/JoinEngine.java#L231

Added line #L231 was not covered by tests
}

Iterator<SearchHit> hits = response.getHits().iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
@Override
public void onResponse(SearchResponse response) {
if (response.isTimedOut()) {
correlateFindingAction.onFailures(new OpenSearchStatusException(response.toString(), RestStatus.REQUEST_TIMEOUT));
correlateFindingAction.onFailures(new OpenSearchStatusException("Search request timed out", RestStatus.REQUEST_TIMEOUT));

Check warning on line 84 in src/main/java/org/opensearch/securityanalytics/correlation/VectorEmbeddingsEngine.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/correlation/VectorEmbeddingsEngine.java#L84

Added line #L84 was not covered by tests
}

Map<String, Object> hitSource = response.getHits().getHits()[0].getSourceAsMap();
Expand Down Expand Up @@ -249,7 +249,7 @@
@Override
public void onResponse(SearchResponse response) {
if (response.isTimedOut()) {
correlateFindingAction.onFailures(new OpenSearchStatusException(response.toString(), RestStatus.REQUEST_TIMEOUT));
correlateFindingAction.onFailures(new OpenSearchStatusException("Search request timed out", RestStatus.REQUEST_TIMEOUT));

Check warning on line 252 in src/main/java/org/opensearch/securityanalytics/correlation/VectorEmbeddingsEngine.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/correlation/VectorEmbeddingsEngine.java#L252

Added line #L252 was not covered by tests
}

try {
Expand Down Expand Up @@ -425,7 +425,7 @@
@Override
public void onResponse(SearchResponse response) {
if (response.isTimedOut()) {
correlateFindingAction.onFailures(new OpenSearchStatusException(response.toString(), RestStatus.REQUEST_TIMEOUT));
correlateFindingAction.onFailures(new OpenSearchStatusException("Search request timed out", RestStatus.REQUEST_TIMEOUT));

Check warning on line 428 in src/main/java/org/opensearch/securityanalytics/correlation/VectorEmbeddingsEngine.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/correlation/VectorEmbeddingsEngine.java#L428

Added line #L428 was not covered by tests
}

long totalHits = response.getHits().getTotalHits().value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
@Override
public void onResponse(SearchResponse response) {
if (response.isTimedOut()) {
listener.onFailure(new OpenSearchStatusException("Unknown error", RestStatus.INTERNAL_SERVER_ERROR));
listener.onFailure(new OpenSearchStatusException("Search request timed out", RestStatus.REQUEST_TIMEOUT));

Check warning on line 279 in src/main/java/org/opensearch/securityanalytics/logtype/LogTypeService.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/logtype/LogTypeService.java#L279

Added line #L279 was not covered by tests
}
if (response.getHits().getTotalHits().value > 0) {
listener.onResponse(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
@Override
public RestResponse buildResponse(SearchResponse response) throws Exception {
if (response.isTimedOut()) {
return new BytesRestResponse(RestStatus.REQUEST_TIMEOUT, response.toString());
return new BytesRestResponse(RestStatus.REQUEST_TIMEOUT, "Search request timed out");

Check warning on line 84 in src/main/java/org/opensearch/securityanalytics/resthandler/RestSearchRuleAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/resthandler/RestSearchRuleAction.java#L84

Added line #L84 was not covered by tests
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
@Override
public void onResponse(SearchResponse response) {
if (response.isTimedOut()) {
onFailures(new OpenSearchStatusException(response.toString(), RestStatus.REQUEST_TIMEOUT));
onFailures(new OpenSearchStatusException("Search request timed out", RestStatus.REQUEST_TIMEOUT));

Check warning on line 226 in src/main/java/org/opensearch/securityanalytics/transport/TransportCorrelateFindingAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/transport/TransportCorrelateFindingAction.java#L226

Added line #L226 was not covered by tests
}

SearchHits hits = response.getHits();
Expand Down Expand Up @@ -336,7 +336,7 @@
@Override
public void onResponse(SearchResponse response) {
if (response.isTimedOut()) {
onFailures(new OpenSearchStatusException(response.toString(), RestStatus.INTERNAL_SERVER_ERROR));
onFailures(new OpenSearchStatusException("Search request timed out", RestStatus.REQUEST_TIMEOUT));

Check warning on line 339 in src/main/java/org/opensearch/securityanalytics/transport/TransportCorrelateFindingAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/transport/TransportCorrelateFindingAction.java#L339

Added line #L339 was not covered by tests
}

SearchHit[] hits = response.getHits().getHits();
Expand Down Expand Up @@ -392,7 +392,7 @@
@Override
public void onResponse(SearchResponse response) {
if (response.isTimedOut()) {
onFailures(new OpenSearchStatusException(response.toString(), RestStatus.INTERNAL_SERVER_ERROR));
onFailures(new OpenSearchStatusException("Search request timed out", RestStatus.REQUEST_TIMEOUT));

Check warning on line 395 in src/main/java/org/opensearch/securityanalytics/transport/TransportCorrelateFindingAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/transport/TransportCorrelateFindingAction.java#L395

Added line #L395 was not covered by tests
}

SearchHit[] hits = response.getHits().getHits();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ public void onResponse(BulkByScrollResponse response) {
new OpenSearchStatusException(
String.format(
Locale.getDefault(),
"Correlation Rule with id %s cannot be deleted",
"Search request timed out. Correlation Rule with id %s cannot be deleted",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a search request?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to "request timed out"

correlationRuleId
),
RestStatus.INTERNAL_SERVER_ERROR)
RestStatus.REQUEST_TIMEOUT)
);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
@Override
public void onResponse(SearchResponse response) {
if (response.isTimedOut()) {
onFailures(new OpenSearchStatusException(String.format(Locale.getDefault(), "Log Type with id %s cannot be deleted", logType.getId()), RestStatus.INTERNAL_SERVER_ERROR));
onFailures(new OpenSearchStatusException(String.format(Locale.getDefault(), "Search request timed out. Log Type with id %s cannot be deleted", logType.getId()), RestStatus.REQUEST_TIMEOUT));

Check warning on line 177 in src/main/java/org/opensearch/securityanalytics/transport/TransportDeleteCustomLogTypeAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/transport/TransportDeleteCustomLogTypeAction.java#L177

Added line #L177 was not covered by tests
return;
}

Expand All @@ -187,7 +187,7 @@
@Override
public void onResponse(SearchResponse response) {
if (response.isTimedOut()) {
onFailures(new OpenSearchStatusException(String.format(Locale.getDefault(), "Log Type with id %s cannot be deleted", logType.getId()), RestStatus.INTERNAL_SERVER_ERROR));
onFailures(new OpenSearchStatusException(String.format(Locale.getDefault(), "Search request timed out. Log Type with id %s cannot be deleted", logType.getId()), RestStatus.REQUEST_TIMEOUT));

Check warning on line 190 in src/main/java/org/opensearch/securityanalytics/transport/TransportDeleteCustomLogTypeAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/transport/TransportDeleteCustomLogTypeAction.java#L190

Added line #L190 was not covered by tests
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
@Override
public void onResponse(SearchResponse response) {
if (response.isTimedOut()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be a generic utils method which is invoked mutliple times. else the error message and format wont be consistent

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a utils method called handleSearchResponseTimeOut() maybe?

onFailures(new OpenSearchStatusException(String.format(Locale.getDefault(), "Rule with id %s cannot be deleted", rule.getId()), RestStatus.INTERNAL_SERVER_ERROR));
onFailures(new OpenSearchStatusException(String.format(Locale.getDefault(), "Search request timed out. Rule with id %s cannot be deleted", rule.getId()), RestStatus.REQUEST_TIMEOUT));

Check warning on line 155 in src/main/java/org/opensearch/securityanalytics/transport/TransportDeleteRuleAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/transport/TransportDeleteRuleAction.java#L155

Added line #L155 was not covered by tests
return;
}

Expand Down Expand Up @@ -231,7 +231,7 @@
@Override
public void onResponse(BulkByScrollResponse response) {
if (response.isTimedOut()) {
onFailures(new OpenSearchStatusException(String.format(Locale.getDefault(), "Rule with id %s cannot be deleted", ruleId), RestStatus.INTERNAL_SERVER_ERROR));
onFailures(new OpenSearchStatusException(String.format(Locale.getDefault(), "Search request timed out. Rule with id %s cannot be deleted", ruleId), RestStatus.REQUEST_TIMEOUT));

Check warning on line 234 in src/main/java/org/opensearch/securityanalytics/transport/TransportDeleteRuleAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/transport/TransportDeleteRuleAction.java#L234

Added line #L234 was not covered by tests
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
@Override
public void onResponse(SearchResponse response) {
if (response.isTimedOut()) {
onFailures(new OpenSearchStatusException(String.format(Locale.getDefault(), "Log Type with id %s cannot be updated", logTypeId), RestStatus.INTERNAL_SERVER_ERROR));
onFailures(new OpenSearchStatusException(String.format(Locale.getDefault(), "Search request timed out. Log Type with id %s cannot be updated", logTypeId), RestStatus.REQUEST_TIMEOUT));

Check warning on line 221 in src/main/java/org/opensearch/securityanalytics/transport/TransportIndexCustomLogTypeAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/transport/TransportIndexCustomLogTypeAction.java#L221

Added line #L221 was not covered by tests
return;
}

Expand All @@ -243,7 +243,7 @@
@Override
public void onResponse(SearchResponse response) {
if (response.isTimedOut()) {
onFailures(new OpenSearchStatusException(String.format(Locale.getDefault(), "Log Type with id %s cannot be updated", logTypeId), RestStatus.INTERNAL_SERVER_ERROR));
onFailures(new OpenSearchStatusException(String.format(Locale.getDefault(), "Search request timed out. Log Type with id %s cannot be updated", logTypeId), RestStatus.REQUEST_TIMEOUT));

Check warning on line 246 in src/main/java/org/opensearch/securityanalytics/transport/TransportIndexCustomLogTypeAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/transport/TransportIndexCustomLogTypeAction.java#L246

Added line #L246 was not covered by tests
return;
}

Expand All @@ -256,7 +256,7 @@
@Override
public void onResponse(SearchResponse response) {
if (response.isTimedOut()) {
onFailures(new OpenSearchStatusException(String.format(Locale.getDefault(), "Log Type with id %s cannot be updated", logTypeId), RestStatus.INTERNAL_SERVER_ERROR));
onFailures(new OpenSearchStatusException(String.format(Locale.getDefault(), "Search request timed out. Log Type with id %s cannot be updated", logTypeId), RestStatus.REQUEST_TIMEOUT));

Check warning on line 259 in src/main/java/org/opensearch/securityanalytics/transport/TransportIndexCustomLogTypeAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/transport/TransportIndexCustomLogTypeAction.java#L259

Added line #L259 was not covered by tests
return;
}

Expand Down Expand Up @@ -379,7 +379,7 @@
@Override
public void onResponse(SearchResponse response) {
if (response.isTimedOut()) {
onFailures(new OpenSearchStatusException(response.toString(), RestStatus.INTERNAL_SERVER_ERROR));
onFailures(new OpenSearchStatusException("Search request timed out", RestStatus.REQUEST_TIMEOUT));

Check warning on line 382 in src/main/java/org/opensearch/securityanalytics/transport/TransportIndexCustomLogTypeAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/transport/TransportIndexCustomLogTypeAction.java#L382

Added line #L382 was not covered by tests
return;
}

Expand All @@ -399,7 +399,7 @@
@Override
public void onResponse(SearchResponse response) {
if (response.isTimedOut()) {
onFailures(new OpenSearchStatusException(response.toString(), RestStatus.INTERNAL_SERVER_ERROR));
onFailures(new OpenSearchStatusException("Search request timed out", RestStatus.REQUEST_TIMEOUT));

Check warning on line 402 in src/main/java/org/opensearch/securityanalytics/transport/TransportIndexCustomLogTypeAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/transport/TransportIndexCustomLogTypeAction.java#L402

Added line #L402 was not covered by tests
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@
@Override
public void onResponse(SearchResponse response) {
if (response.isTimedOut()) {
onFailures(new OpenSearchStatusException(response.toString(), RestStatus.REQUEST_TIMEOUT));
onFailures(new OpenSearchStatusException("Search request timed out", RestStatus.REQUEST_TIMEOUT));

Check warning on line 1240 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#L1240

Added line #L1240 was not covered by tests
}

long count = response.getHits().getTotalHits().value;
Expand Down Expand Up @@ -1302,7 +1302,7 @@
@Override
public void onResponse(SearchResponse response) {
if (response.isTimedOut()) {
onFailures(new OpenSearchStatusException(response.toString(), RestStatus.REQUEST_TIMEOUT));
onFailures(new OpenSearchStatusException("Search request timed out", RestStatus.REQUEST_TIMEOUT));

Check warning on line 1305 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#L1305

Added line #L1305 was not covered by tests
}

SearchHits hits = response.getHits();
Expand Down Expand Up @@ -1362,7 +1362,7 @@
@Override
public void onResponse(SearchResponse response) {
if (response.isTimedOut()) {
onFailures(new OpenSearchStatusException(response.toString(), RestStatus.REQUEST_TIMEOUT));
onFailures(new OpenSearchStatusException("Search request timed out", RestStatus.REQUEST_TIMEOUT));

Check warning on line 1365 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#L1365

Added line #L1365 was not covered by tests
}

SearchHits hits = response.getHits();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
@Override
public void onResponse(SearchResponse response) {
if (response.isTimedOut()) {
onFailures(new OpenSearchStatusException(String.format(Locale.getDefault(), "Rule with id %s cannot be updated", rule.getId()), RestStatus.INTERNAL_SERVER_ERROR));
onFailures(new OpenSearchStatusException(String.format(Locale.getDefault(), "Search request timed out. Rule with id %s cannot be updated", rule.getId()), RestStatus.REQUEST_TIMEOUT));

Check warning on line 240 in src/main/java/org/opensearch/securityanalytics/transport/TransportIndexRuleAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/transport/TransportIndexRuleAction.java#L240

Added line #L240 was not covered by tests
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
@Override
public void onResponse(SearchResponse response) {
if (response.isTimedOut()) {
onFailures(new OpenSearchStatusException(response.toString(), RestStatus.REQUEST_TIMEOUT));
onFailures(new OpenSearchStatusException("Search request timed out", RestStatus.REQUEST_TIMEOUT));

Check warning on line 122 in src/main/java/org/opensearch/securityanalytics/transport/TransportListCorrelationAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/transport/TransportListCorrelationAction.java#L122

Added line #L122 was not covered by tests
}

Map<String, CorrelatedFinding> correlatedFindings = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@
@Override
public void onResponse(SearchResponse response) {
if (response.isTimedOut()) {
listener.onFailure(new OpenSearchStatusException(response.toString(), RestStatus.INTERNAL_SERVER_ERROR));
listener.onFailure(new OpenSearchStatusException("Search request timed out", RestStatus.REQUEST_TIMEOUT));

Check warning on line 331 in src/main/java/org/opensearch/securityanalytics/util/RuleIndices.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/util/RuleIndices.java#L331

Added line #L331 was not covered by tests
}
try {
SearchHit[] hits = response.getHits().getHits();
Expand Down
Loading