From da2da29b3999e215f98ff328ce0e6e73c776b860 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Thu, 2 May 2024 10:41:04 -0700 Subject: [PATCH] fix fieldLimit exception in docLevelMonitor (#1368) (#1541) * fix fieldLimit exception in docLevelMonitor * bug fixes from prev pr --------- (cherry picked from commit 77fc8b6ff845b99cc926bf8c324992495a109c37) Signed-off-by: Riya Saxena Signed-off-by: github-actions[bot] Co-authored-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 4005a8cc0..cc15ad71a 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/DocumentLevelMonitorRunner.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/DocumentLevelMonitorRunner.kt @@ -75,8 +75,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)