Skip to content

Support sending email message via Notifications passthrough API#158

Merged
qreshi merged 2 commits intoopensearch-project:mainfrom
qreshi:email-via-passthrough
Apr 16, 2022
Merged

Support sending email message via Notifications passthrough API#158
qreshi merged 2 commits intoopensearch-project:mainfrom
qreshi:email-via-passthrough

Conversation

@qreshi
Copy link
Copy Markdown
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.

qreshi added 2 commits April 10, 2022 08:43
Signed-off-by: Mohammad Qureshi <47198598+qreshi@users.noreply.github.com>
Signed-off-by: Mohammad Qureshi <47198598+qreshi@users.noreply.github.com>
return try {
XContentHelper.toXContent(this, XContentType.JSON, EMPTY_PARAMS, true).utf8ToString()
} catch (e: IOException) {
super.toString() + " threw " + e.toString()
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 <47198598+qreshi@users.noreply.github.com>

* Add accountName to LegacyEmailMessage

Signed-off-by: Mohammad Qureshi <47198598+qreshi@users.noreply.github.com>
Signed-off-by: Zelin Hao <zelinhao@amazon.com>
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 <47198598+qreshi@users.noreply.github.com>

* Add accountName to LegacyEmailMessage

Signed-off-by: Mohammad Qureshi <47198598+qreshi@users.noreply.github.com>
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