From 1e63f1513bdd80e603c6b846947a6645c76df8dc Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Thu, 9 Jan 2025 18:46:20 -0500 Subject: [PATCH] refactor: modifying log levels and adding more logs to display error details (#3337) (#3359) Signed-off-by: Pavan Yekbote (cherry picked from commit 441af6ef532752e3c5842338d0281a729123968a) Co-authored-by: Pavan Yekbote --- .../algorithms/remote/MLSdkAsyncHttpResponseHandler.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/remote/MLSdkAsyncHttpResponseHandler.java b/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/remote/MLSdkAsyncHttpResponseHandler.java index fdb686dacc..647c257659 100644 --- a/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/remote/MLSdkAsyncHttpResponseHandler.java +++ b/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/remote/MLSdkAsyncHttpResponseHandler.java @@ -89,6 +89,7 @@ public void onHeaders(SdkHttpResponse response) { log.debug("received response headers: " + sdkResponse.headers()); this.statusCode = sdkResponse.statusCode(); if (statusCode < HttpStatus.SC_OK || statusCode > HttpStatus.SC_MULTIPLE_CHOICES) { + log.error("Received error from remote service with status code {}, response headers: {}", statusCode, sdkResponse.headers()); handleThrottlingInHeader(sdkResponse); // add more handling here for other exceptions in headers } @@ -101,7 +102,7 @@ public void onStream(Publisher stream) { @Override public void onError(Throwable error) { - log.error(error.getMessage(), error); + log.error("Received error from remote service: {}", error.getMessage(), error); RestStatus status = (statusCode == null) ? RestStatus.INTERNAL_SERVER_ERROR : RestStatus.fromCode(statusCode); String errorMessage = "Error communicating with remote model: " + error.getMessage(); actionListener.onFailure(new OpenSearchStatusException(errorMessage, status)); @@ -173,6 +174,7 @@ private void response() { String body = responseBody.toString(); if (exceptionHolder.get() != null) { + log.error("Remote server returned exception with status code: {} and body: {}", statusCode, body); actionListener.onFailure(exceptionHolder.get()); return; } @@ -184,7 +186,7 @@ private void response() { } if (statusCode < HttpStatus.SC_OK || statusCode > HttpStatus.SC_MULTIPLE_CHOICES) { - log.error("Remote server returned error code: {}", statusCode); + log.error("Remote service returned error code: {} with body: {}", statusCode, body); actionListener.onFailure(new OpenSearchStatusException(REMOTE_SERVICE_ERROR + body, RestStatus.fromCode(statusCode))); return; }