From 904adc4e076ac21f481b4afb1d1dc1383fef14a6 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 9 Apr 2024 16:43:47 +0000 Subject: [PATCH] fix fieldLimit exception in docLevelMonitor (#1368) * fix fieldLimit exception in docLevelMonitor Signed-off-by: Riya Saxena * bug fixes from prev pr Signed-off-by: Riya Saxena --------- Signed-off-by: Riya Saxena (cherry picked from commit 77fc8b6ff845b99cc926bf8c324992495a109c37) Signed-off-by: github-actions[bot] --- .../alerting/DocumentLevelMonitorRunner.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/DocumentLevelMonitorRunner.kt b/alerting/src/main/kotlin/org/opensearch/alerting/DocumentLevelMonitorRunner.kt index 51a32b642..cc4b26a79 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/DocumentLevelMonitorRunner.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/DocumentLevelMonitorRunner.kt @@ -115,8 +115,16 @@ class DocumentLevelMonitorRunner : MonitorRunner() { monitorCtx.alertIndices!!.createOrUpdateInitialFindingHistoryIndex(monitor.dataSources) } catch (e: Exception) { val id = if (monitor.id.trim().isEmpty()) "_na_" else monitor.id - logger.error("Error setting up alerts and findings indices for monitor: $id", e) - monitorResult = monitorResult.copy(error = AlertingException.wrap(e)) + val unwrappedException = ExceptionsHelper.unwrapCause(e) + if (unwrappedException is IllegalArgumentException && unwrappedException.message?.contains("Limit of total fields") == true) { + val errorMessage = + "Monitor [$id] can't process index [$monitor.dataSources] due to field mapping limit" + logger.error("Exception: ${unwrappedException.message}") + monitorResult = monitorResult.copy(error = AlertingException(errorMessage, RestStatus.INTERNAL_SERVER_ERROR, e)) + } else { + logger.error("Error setting up alerts and findings indices for monitor: $id", e) + monitorResult = monitorResult.copy(error = AlertingException.wrap(e)) + } } try { validate(monitor)