Skip to content

Commit 6de644f

Browse files
petardzlezzago
authored andcommitted
Added unwrapping exception from core; added more debug logs (opensearch-project#728)
Signed-off-by: Petar Dzepina <[email protected]>
1 parent d5a51e6 commit 6de644f

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

alerting/src/main/kotlin/org/opensearch/alerting/util/DocLevelMonitorQueries.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package org.opensearch.alerting.util
77

88
import org.apache.logging.log4j.LogManager
9+
import org.opensearch.ExceptionsHelper
910
import org.opensearch.OpenSearchStatusException
1011
import org.opensearch.ResourceAlreadyExistsException
1112
import org.opensearch.action.admin.indices.alias.Alias
@@ -272,10 +273,12 @@ class DocLevelMonitorQueries(private val client: Client, private val clusterServ
272273
}
273274
return Pair(updateMappingResponse, targetQueryIndex)
274275
} catch (e: Exception) {
276+
val unwrappedException = ExceptionsHelper.unwrapCause(e) as Exception
277+
log.debug("exception after rollover queryIndex index: $targetQueryIndex exception: ${unwrappedException.message}")
275278
// If we reached limit for total number of fields in mappings, do a rollover here
276-
if (e.message?.contains("Limit of total fields") == true) {
277-
targetQueryIndex = rolloverQueryIndex(monitor)
279+
if (unwrappedException.message?.contains("Limit of total fields") == true) {
278280
try {
281+
targetQueryIndex = rolloverQueryIndex(monitor)
279282
// PUT mappings to newly created index
280283
val updateMappingRequestRetry = PutMappingRequest(targetQueryIndex)
281284
updateMappingRequestRetry.source(mapOf<String, Any>("properties" to updatedProperties))
@@ -286,7 +289,9 @@ class DocLevelMonitorQueries(private val client: Client, private val clusterServ
286289
// If we reached limit for total number of fields in mappings after rollover
287290
// it means that source index has more then (FIELD_LIMIT - 3) fields (every query index has 3 fields defined)
288291
// TODO maybe split queries/mappings between multiple query indices?
289-
if (e.message?.contains("Limit of total fields") == true) {
292+
val unwrappedException = ExceptionsHelper.unwrapCause(e) as Exception
293+
log.debug("exception after rollover queryIndex index: $targetQueryIndex exception: ${unwrappedException.message}")
294+
if (unwrappedException.message?.contains("Limit of total fields") == true) {
290295
val errorMessage =
291296
"Monitor [${monitorMetadata.monitorId}] can't process index [$sourceIndex] due to field mapping limit"
292297
log.error(errorMessage)
@@ -296,7 +301,9 @@ class DocLevelMonitorQueries(private val client: Client, private val clusterServ
296301
}
297302
}
298303
} else {
299-
throw AlertingException.wrap(e)
304+
log.debug("unknown exception during PUT mapping on queryIndex: $targetQueryIndex")
305+
val unwrappedException = ExceptionsHelper.unwrapCause(e) as Exception
306+
throw AlertingException.wrap(unwrappedException)
300307
}
301308
}
302309
// We did rollover, so try to apply mappings again on new targetQueryIndex

0 commit comments

Comments
 (0)