6
6
package org.opensearch.alerting.util
7
7
8
8
import org.apache.logging.log4j.LogManager
9
+ import org.opensearch.ExceptionsHelper
9
10
import org.opensearch.OpenSearchStatusException
10
11
import org.opensearch.ResourceAlreadyExistsException
11
12
import org.opensearch.action.admin.indices.alias.Alias
@@ -272,10 +273,12 @@ class DocLevelMonitorQueries(private val client: Client, private val clusterServ
272
273
}
273
274
return Pair (updateMappingResponse, targetQueryIndex)
274
275
} catch (e: Exception ) {
276
+ val unwrappedException = ExceptionsHelper .unwrapCause(e) as Exception
277
+ log.debug(" exception after rollover queryIndex index: $targetQueryIndex exception: ${unwrappedException.message} " )
275
278
// 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 ) {
278
280
try {
281
+ targetQueryIndex = rolloverQueryIndex(monitor)
279
282
// PUT mappings to newly created index
280
283
val updateMappingRequestRetry = PutMappingRequest (targetQueryIndex)
281
284
updateMappingRequestRetry.source(mapOf<String , Any >(" properties" to updatedProperties))
@@ -286,7 +289,9 @@ class DocLevelMonitorQueries(private val client: Client, private val clusterServ
286
289
// If we reached limit for total number of fields in mappings after rollover
287
290
// it means that source index has more then (FIELD_LIMIT - 3) fields (every query index has 3 fields defined)
288
291
// 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 ) {
290
295
val errorMessage =
291
296
" Monitor [${monitorMetadata.monitorId} ] can't process index [$sourceIndex ] due to field mapping limit"
292
297
log.error(errorMessage)
@@ -296,7 +301,9 @@ class DocLevelMonitorQueries(private val client: Client, private val clusterServ
296
301
}
297
302
}
298
303
} 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)
300
307
}
301
308
}
302
309
// We did rollover, so try to apply mappings again on new targetQueryIndex
0 commit comments