Skip to content

Commit

Permalink
small fix
Browse files Browse the repository at this point in the history
Signed-off-by: bowenlan-amzn <bowenlan23@gmail.com>
  • Loading branch information
bowenlan-amzn committed Oct 12, 2023
1 parent 4ccc54b commit bff61ba
Showing 1 changed file with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -758,19 +758,29 @@ object ManagedIndexRunner :

private suspend fun publishErrorNotification(policy: Policy, metadata: ManagedIndexMetaData): ManagedIndexMetaData {
return try {
// if the policy has no error_notification this will do nothing otherwise it will try to send the configured error message
policy.errorNotification?.run {
errorNotificationRetryPolicy.retry(logger) {
val compiledMessage = compileTemplate(messageTemplate, metadata)
destination?.buildLegacyBaseMessage(null, compiledMessage)?.publishLegacyNotification(client)
channel?.sendNotification(client, ErrorNotification.CHANNEL_TITLE, metadata, compiledMessage, policy.user)
val errorNotification = policy.errorNotification
if (errorNotification != null) {
policy.errorNotification.run {
errorNotificationRetryPolicy.retry(logger) {
val compiledMessage = compileTemplate(messageTemplate, metadata)

Check warning on line 765 in src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexRunner.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexRunner.kt#L763-L765

Added lines #L763 - L765 were not covered by tests
destination?.buildLegacyBaseMessage(null, compiledMessage)?.publishLegacyNotification(client)
channel?.sendNotification(
client,
ErrorNotification.CHANNEL_TITLE,
metadata,
compiledMessage,
policy.user

Check warning on line 772 in src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexRunner.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexRunner.kt#L769-L772

Added lines #L769 - L772 were not covered by tests
)
}
}
val message = "Successfully published error notification [index = ${metadata.index}]"
logger.info(message)

Check warning on line 777 in src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexRunner.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexRunner.kt#L776-L777

Added lines #L776 - L777 were not covered by tests
val mutableInfo = metadata.info?.toMutableMap() ?: mutableMapOf()
mutableInfo["error_notification"] = message
metadata.copy(info = mutableInfo.toMap())

Check warning on line 780 in src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexRunner.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexRunner.kt#L779-L780

Added lines #L779 - L780 were not covered by tests
} else {
return metadata
}
val message = "Successfully published error notification [index = ${metadata.index}]"
logger.info(message)
val mutableInfo = metadata.info?.toMutableMap() ?: mutableMapOf()
mutableInfo["error_notification"] = message
metadata.copy(info = mutableInfo.toMap())
} catch (e: Exception) {
logger.error("Failed to publish error notification", e)

Check warning on line 785 in src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexRunner.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexRunner.kt#L784-L785

Added lines #L784 - L785 were not covered by tests
val errorMessage = e.message ?: "Failed to publish error notification"
Expand Down

0 comments on commit bff61ba

Please sign in to comment.