Skip to content

Commit

Permalink
small fix
Browse files Browse the repository at this point in the history
Signed-off-by: bowenlan-amzn <[email protected]>
  • Loading branch information
bowenlan-amzn committed Oct 12, 2023
1 parent dbd9b0f commit 43a2c50
Showing 1 changed file with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -809,19 +809,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 816 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#L814-L816

Added lines #L814 - L816 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 823 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#L820-L823

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

Check warning on line 828 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#L827-L828

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

Check warning on line 831 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#L830-L831

Added lines #L830 - L831 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 836 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#L835-L836

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

0 comments on commit 43a2c50

Please sign in to comment.