diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/DocumentLevelMonitorRunner.kt b/alerting/src/main/kotlin/org/opensearch/alerting/DocumentLevelMonitorRunner.kt index c5c68c4b0..887ec6e9e 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/DocumentLevelMonitorRunner.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/DocumentLevelMonitorRunner.kt @@ -13,11 +13,7 @@ import org.opensearch.action.support.GroupedActionListener import org.opensearch.alerting.action.DocLevelMonitorFanOutAction import org.opensearch.alerting.action.DocLevelMonitorFanOutRequest import org.opensearch.alerting.action.DocLevelMonitorFanOutResponse -import org.opensearch.alerting.model.ActionRunResult -import org.opensearch.alerting.model.DocumentLevelTriggerRunResult -import org.opensearch.alerting.model.IndexExecutionContext -import org.opensearch.alerting.model.InputRunResults -import org.opensearch.alerting.model.MonitorRunResult +import org.opensearch.alerting.model.* import org.opensearch.alerting.util.AlertingException import org.opensearch.alerting.util.IndexUtils import org.opensearch.alerting.workflow.WorkflowRunContext @@ -36,12 +32,7 @@ import org.opensearch.core.rest.RestStatus import org.opensearch.index.IndexNotFoundException import org.opensearch.index.seqno.SequenceNumbers import org.opensearch.node.NodeClosedException -import org.opensearch.transport.ActionNotFoundTransportException -import org.opensearch.transport.ConnectTransportException -import org.opensearch.transport.RemoteTransportException -import org.opensearch.transport.TransportException -import org.opensearch.transport.TransportRequestOptions -import org.opensearch.transport.TransportService +import org.opensearch.transport.* import java.io.IOException import java.time.Instant import kotlin.coroutines.resume @@ -307,14 +298,18 @@ class DocumentLevelMonitorRunner : MonitorRunner() { responseReader ) { override fun handleException(e: TransportException) { - logger.error("Fan out retry failed in node ${localNode.id}") + logger.error("Fan out retry failed in node ${localNode.id}", e) listener.onResponse( DocLevelMonitorFanOutResponse( "", "", "", mutableMapOf(), - exception = AlertingException.wrap(e) as AlertingException + exception = if (e.cause is AlertingException) { + e.cause as AlertingException + } else { + AlertingException.wrap(e) as AlertingException + } ) ) } @@ -332,7 +327,11 @@ class DocumentLevelMonitorRunner : MonitorRunner() { "", "", mutableMapOf(), - exception = AlertingException.wrap(e) as AlertingException + exception = if (e.cause is AlertingException) { + e.cause as AlertingException + } else { + AlertingException.wrap(e) as AlertingException + } ) ) } diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/util/AlertingException.kt b/alerting/src/main/kotlin/org/opensearch/alerting/util/AlertingException.kt index 5bc86d962..3ed7a8674 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/util/AlertingException.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/util/AlertingException.kt @@ -20,7 +20,7 @@ private val log = LogManager.getLogger(AlertingException::class.java) /** * Converts into a user friendly message. */ -class AlertingException(message: String, val status: RestStatus, ex: Exception) : OpenSearchException(message, ex) { +class AlertingException(message: String, val status: RestStatus, val ex: Exception) : OpenSearchException(message, ex) { override fun status(): RestStatus { return status @@ -73,14 +73,17 @@ class AlertingException(message: String, val status: RestStatus, ex: Exception) @JvmStatic fun merge(vararg ex: AlertingException): AlertingException { var friendlyMsg = "" + var unwrappedExceptionMsg = "" ex.forEach { if (friendlyMsg != "") { friendlyMsg += ", ${it.message}" + unwrappedExceptionMsg += ", ${it.ex.message}" } else { friendlyMsg = it.message.orEmpty() + unwrappedExceptionMsg = "${it.ex.message}" } } - return AlertingException(friendlyMsg, ex.first().status, Exception(ex.javaClass.name)) + return AlertingException(friendlyMsg, ex.first().status, Exception(unwrappedExceptionMsg)) } } }