-
Notifications
You must be signed in to change notification settings - Fork 107
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
523 bug fix - Sending notification under more error conditions #667
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Angie Zhang <langelzh@amazon.com>
Codecov Report
@@ Coverage Diff @@
## main #667 +/- ##
============================================
- Coverage 75.56% 75.53% -0.04%
- Complexity 2657 2663 +6
============================================
Files 333 333
Lines 15395 15453 +58
Branches 2384 2395 +11
============================================
+ Hits 11633 11672 +39
- Misses 2410 2414 +4
- Partials 1352 1367 +15
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
@@ -527,6 +560,7 @@ object ManagedIndexRunner : | |||
|
|||
@Suppress("TooGenericExceptionCaught") | |||
private suspend fun disableManagedIndexConfig(managedIndexConfig: ManagedIndexConfig) { | |||
logger.info("Start to disable ManagedIndexConfig") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably don't need this.
private fun compileTemplate(template: Script, managedIndexConfig: ManagedIndexConfig): String { | ||
return try { | ||
scriptService.compile(template, TemplateScript.CONTEXT) | ||
.newInstance(template.params + mapOf("ctx" to managedIndexConfig.convertToMap())) | ||
.execute() | ||
} catch (e: Exception) { | ||
val message = "There was an error compiling mustache template" | ||
logger.error(message, e) | ||
e.message ?: message | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor this. Just one compileTemplate here is enough, the only difference is "ctx", let's explicitly choose fields to put into context
private suspend fun publishErrorNotification(policy: Policy?, managedIndexConfig: ManagedIndexConfig, additionalMessage: String) { | ||
if (policy == null) { | ||
logger.error("Policy for index ${managedIndexConfig.index} is not available to obtain. Notifications for this policy is aborted.") | ||
return | ||
} | ||
policy.errorNotification?.run { | ||
errorNotificationRetryPolicy.retry(logger) { | ||
val compiledMessage = compileTemplate(messageTemplate, managedIndexConfig) | ||
val finalMessage = "$additionalMessage $compiledMessage" | ||
destination?.buildLegacyBaseMessage(null, finalMessage)?.publishLegacyNotification(client) | ||
channel?.sendNotification(client, ErrorNotification.CHANNEL_TITLE, managedIndexConfig, compiledMessage, policy.user) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we combine this with above same name method? additionalMessage method can be nullable
For managedIndexMetaData, managedIndexConfig, we can just pick out index uuid, index name and input here. You can check if any other fields are useful to compose the notification message
// doing a check of local cluster health as we do not want to overload cluster manager node with potentially a lot of calls | ||
if (clusterIsRed()) { | ||
val message = "Skipping current execution of ${managedIndexConfig.index} because of red cluster health." | ||
logger.debug(message) | ||
publishErrorNotification(policy, managedIndexConfig, message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Red cluster check has to be at top, because it may affect all the following step: read metadata, write... Any reason to move it here?
Signed-off-by: Angie Zhang langelzh@amazon.com
Issue #, if available:
#523
Description of changes:
CheckList:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.