Skip to content

Commit

Permalink
Added unwrapping exception from core; added more debug logs (#728)
Browse files Browse the repository at this point in the history
Signed-off-by: Petar Dzepina <[email protected]>
  • Loading branch information
petardz authored Jan 6, 2023
1 parent 6f48746 commit 19d4a41
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package org.opensearch.alerting.util

import org.apache.logging.log4j.LogManager
import org.opensearch.ExceptionsHelper
import org.opensearch.OpenSearchStatusException
import org.opensearch.ResourceAlreadyExistsException
import org.opensearch.action.admin.indices.alias.Alias
Expand Down Expand Up @@ -325,10 +326,12 @@ class DocLevelMonitorQueries(private val client: Client, private val clusterServ
}
return Pair(updateMappingResponse, targetQueryIndex)
} catch (e: Exception) {
val unwrappedException = ExceptionsHelper.unwrapCause(e) as Exception
log.debug("exception after rollover queryIndex index: $targetQueryIndex exception: ${unwrappedException.message}")
// If we reached limit for total number of fields in mappings, do a rollover here
if (e.message?.contains("Limit of total fields") == true) {
targetQueryIndex = rolloverQueryIndex(monitor)
if (unwrappedException.message?.contains("Limit of total fields") == true) {
try {
targetQueryIndex = rolloverQueryIndex(monitor)
// PUT mappings to newly created index
val updateMappingRequest = PutMappingRequest(targetQueryIndex)
updateMappingRequest.source(mapOf<String, Any>("properties" to updatedProperties))
Expand All @@ -339,7 +342,9 @@ class DocLevelMonitorQueries(private val client: Client, private val clusterServ
// If we reached limit for total number of fields in mappings after rollover
// it means that source index has more then (FIELD_LIMIT - 3) fields (every query index has 3 fields defined)
// TODO maybe split queries/mappings between multiple query indices?
if (e.message?.contains("Limit of total fields") == true) {
val unwrappedException = ExceptionsHelper.unwrapCause(e) as Exception
log.debug("exception after rollover queryIndex index: $targetQueryIndex exception: ${unwrappedException.message}")
if (unwrappedException.message?.contains("Limit of total fields") == true) {
val errorMessage =
"Monitor [${monitorMetadata.monitorId}] can't process index [$sourceIndex] due to field mapping limit"
log.error(errorMessage)
Expand All @@ -349,7 +354,9 @@ class DocLevelMonitorQueries(private val client: Client, private val clusterServ
}
}
} else {
throw AlertingException.wrap(e)
log.debug("unknown exception during PUT mapping on queryIndex: $targetQueryIndex")
val unwrappedException = ExceptionsHelper.unwrapCause(e) as Exception
throw AlertingException.wrap(unwrappedException)
}
}
// We did rollover, so try to apply mappings again on new targetQueryIndex
Expand Down

0 comments on commit 19d4a41

Please sign in to comment.