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

Support sending email message via Notifications passthrough API #158

Merged
merged 2 commits into from
Apr 16, 2022

Conversation

qreshi
Copy link
Contributor

@qreshi qreshi commented Apr 13, 2022

Description

The Notifications passthrough API is used for sending legacy messages for consumers of the old notification subproject in Alerting. Alerting has support for Email Destinations that need to use the passthrough API as a fallback mechanism for Destinations that have not migrated.

This PR adds support for email via passthrough.

Issues Resolved

[List any issues this PR will resolve]

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff

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.

return try {
XContentHelper.toXContent(this, XContentType.JSON, EMPTY_PARAMS, true).utf8ToString()
} catch (e: IOException) {
super.toString() + " threw " + e.toString()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we publishing this information outside of the system?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alerting is using the response after publishing a message and setting that as the actionResponseContent in runAction.

Since this is the actionResult and we store it in the Alert it can be published externally via ctx.alert in messages.

I had to catch the IOException since detekt was complaining that toString() should not throw exceptions. If there are concerns here, should I log super.toString() + " threw " + e.toString() instead and make the returned string something generic?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but this would suppress the exception? which might be misleading for its consumers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I've read, it seems it's not that unusual to suppress the exception here. Conventionally, toString() should not be throwing exceptions.

Here is an example of a thread that I found when looking into it: https://stackoverflow.com/a/42011744

This is probably why the linter also failed on it. I can add a log entry as a follow-up change so the exception is logged at least for debugging purposes. If you disagree with this though, feel free to create an issue for it to discuss further.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on debug logger here instead

@rishabhmaurya
Copy link
Collaborator

Can you serialize and deserialize logic test for LegacyPublishNotificartionRequest with destination type LEGACY_EMAIL - https://github.com/qreshi/opensearch-common-utils/blob/email-via-passthrough/src/test/kotlin/org/opensearch/commons/notifications/action/LegacyPublishNotificationRequestTests.kt

Copy link
Member

@getsaurabh02 getsaurabh02 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall. Few minor comments to address. Thanks @qreshi

return try {
XContentHelper.toXContent(this, XContentType.JSON, EMPTY_PARAMS, true).utf8ToString()
} catch (e: IOException) {
super.toString() + " threw " + e.toString()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on debug logger here instead

@qreshi qreshi merged commit a80b8b1 into opensearch-project:main Apr 16, 2022
zelinh pushed a commit that referenced this pull request Aug 18, 2022
* Add legacy email support as a legacy Destination type

Signed-off-by: Mohammad Qureshi <[email protected]>

* Add accountName to LegacyEmailMessage

Signed-off-by: Mohammad Qureshi <[email protected]>
Signed-off-by: Zelin Hao <[email protected]>
wuychn pushed a commit to ochprince/common-utils that referenced this pull request Mar 16, 2023
…search-project#158)

* Add legacy email support as a legacy Destination type

Signed-off-by: Mohammad Qureshi <[email protected]>

* Add accountName to LegacyEmailMessage

Signed-off-by: Mohammad Qureshi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants