Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more error notification at fail points #1000

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@
return
}

val policy = managedIndexConfig.policy
if (managedIndexMetaData.hasDifferentPolicyVersion(managedIndexConfig)) {
val info = mapOf("message" to "There is a version conflict between your previous execution and your managed index")
val result = updateManagedIndexMetaData(
Expand All @@ -301,11 +302,11 @@
)
if (result.metadataSaved) {
disableManagedIndexConfig(managedIndexConfig)
publishErrorNotification(policy, managedIndexMetaData)
}
return
}

val policy = managedIndexConfig.policy
val state = policy.getStateToExecute(managedIndexMetaData)
val action: Action? = state?.getActionToExecute(managedIndexMetaData, indexMetadataProvider)
val stepContext = StepContext(
Expand All @@ -328,8 +329,10 @@
managedIndexMetaData
.copy(actionMetaData = currentActionMetaData?.copy(failed = true), info = info)
)
if (updated.metadataSaved)
if (updated.metadataSaved) {
disableManagedIndexConfig(managedIndexConfig)
publishErrorNotification(policy, managedIndexMetaData)
}
return
}

Expand All @@ -355,7 +358,10 @@
policyRetryInfo = PolicyRetryInfoMetaData(true, 0), info = info
)
)
if (updated.metadataSaved) disableManagedIndexConfig(managedIndexConfig)
if (updated.metadataSaved) {
disableManagedIndexConfig(managedIndexConfig)
publishErrorNotification(policy, managedIndexMetaData)

Check warning on line 363 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#L362-L363

Added lines #L362 - L363 were not covered by tests
}
return
}
}
Expand All @@ -369,7 +375,10 @@
policyRetryInfo = PolicyRetryInfoMetaData(true, 0), info = info
)
)
if (updated.metadataSaved) disableManagedIndexConfig(managedIndexConfig)
if (updated.metadataSaved) {
disableManagedIndexConfig(managedIndexConfig)
publishErrorNotification(policy, managedIndexMetaData)

Check warning on line 380 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#L379-L380

Added lines #L379 - L380 were not covered by tests
}
return
}

Expand All @@ -382,7 +391,10 @@
policyRetryInfo = PolicyRetryInfoMetaData(true, 0), info = info
)
)
if (updated.metadataSaved) disableManagedIndexConfig(managedIndexConfig)
if (updated.metadataSaved) {
disableManagedIndexConfig(managedIndexConfig)
publishErrorNotification(policy, managedIndexMetaData)
}
return
}

Expand Down Expand Up @@ -424,16 +436,7 @@
var executedManagedIndexMetaData = startingManagedIndexMetaData.getCompletedManagedIndexMetaData(action, step)

if (executedManagedIndexMetaData.isFailed) {
try {
// if the policy has no error_notification this will do nothing otherwise it will try to send the configured error message
publishErrorNotification(policy, executedManagedIndexMetaData)
} catch (e: Exception) {
logger.error("Failed to publish error notification", e)
val errorMessage = e.message ?: "Failed to publish error notification"
val mutableInfo = executedManagedIndexMetaData.info?.toMutableMap() ?: mutableMapOf()
mutableInfo["errorNotificationFailure"] = errorMessage
executedManagedIndexMetaData = executedManagedIndexMetaData.copy(info = mutableInfo.toMap())
}
executedManagedIndexMetaData = publishErrorNotification(policy, executedManagedIndexMetaData)
}

if (executedManagedIndexMetaData.isSuccessfulDelete) {
Expand Down Expand Up @@ -753,13 +756,37 @@
}
}

private suspend fun publishErrorNotification(policy: Policy, managedIndexMetaData: ManagedIndexMetaData) {
policy.errorNotification?.run {
errorNotificationRetryPolicy.retry(logger) {
val compiledMessage = compileTemplate(messageTemplate, managedIndexMetaData)
destination?.buildLegacyBaseMessage(null, compiledMessage)?.publishLegacyNotification(client)
channel?.sendNotification(client, ErrorNotification.CHANNEL_TITLE, managedIndexMetaData, compiledMessage, policy.user)
private suspend fun publishErrorNotification(policy: Policy, metadata: ManagedIndexMetaData): ManagedIndexMetaData {
return try {
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
}
} 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"
val mutableInfo = metadata.info?.toMutableMap() ?: mutableMapOf()
mutableInfo["error_notification"] = errorMessage
metadata.copy(info = mutableInfo.toMap())

Check warning on line 789 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#L788-L789

Added lines #L788 - L789 were not covered by tests
}
}

Expand Down
Loading