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 #406

Merged
merged 3 commits into from
Apr 16, 2022

Conversation

qreshi
Copy link
Contributor

@qreshi qreshi commented Apr 13, 2022

Description

Depends on opensearch-project/common-utils#158 so GitHub Actions are expected to fail until that is merged in.

This PR includes the following:

  • Changes needed from the Notification plugin side to support sending email notification via the passthrough API for Alerting.
  • Fixes the fallback settings for the EMAIL_USERNAME and EMAIL_PASSWORD to correctly use Alerting's when they aren't set for an SMTP email account

Issues Resolved

[List any issues this PR will resolve]

Check List

  • New functionality includes testing.
    • All tests pass, including unit test, integration test and doctest
  • New functionality has been documented.
    • New functionality has javadoc added
    • New functionality has user manual doc 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.

@codecov-commenter
Copy link

Codecov Report

Merging #406 (213b8e9) into main (5421f98) will increase coverage by 16.00%.
The diff coverage is n/a.

@@              Coverage Diff              @@
##               main     #406       +/-   ##
=============================================
+ Coverage     70.40%   86.40%   +16.00%     
=============================================
  Files           123       51       -72     
  Lines          3849     1479     -2370     
  Branches        612      352      -260     
=============================================
- Hits           2710     1278     -1432     
+ Misses          960      198      -762     
+ Partials        179        3      -176     
Flag Coverage Δ
dashboards-notifications 86.40% <ø> (ø)
opensearch-notifications ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...earch/notifications/core/setting/PluginSettings.kt
...arch/notifications/send/SendMessageActionHelper.kt
...ions/core/transport/WebhookDestinationTransport.kt
...pensearch/notifications/settings/PluginSettings.kt
...tlin/org/opensearch/notifications/model/DocInfo.kt
...notifications/model/SendTestNotificationRequest.kt
...notifications/core/client/DestinationClientPool.kt
...earch/notifications/spi/utils/ValidationHelpers.kt
...notifications/action/SendTestNotificationAction.kt
...opensearch/notifications/index/ConfigOperations.kt
... and 62 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5421f98...213b8e9. Read the comment docs.

@qreshi
Copy link
Contributor Author

qreshi commented Apr 13, 2022

If anyone is wondering why the Notification Dashboards CI passed when the backend isn't building yet, it's because the workflow just checks out the backend plugin and is running the unit test for the frontend.

Once we fix the Cypress tests, we can add them to the Test and Build Dashboards Notifications workflow so the integration tests can catch this stuff.

{ key: String ->
SecureSetting.secureString(
key,
fallback(key, LEGACY_EMAIL_USERNAME, "opensearch\\.notifications\\.core", "plugins.alerting.destination")
Copy link
Contributor

Choose a reason for hiding this comment

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

do we have a unit test for fallback case?

// The naming is a little confusing but need to use the subject from LegacyEmailMessage as the title,
// so it appears as the subject of the email
message = MessageContent(title = baseMessage.subject, textDescription = baseMessage.messageContent)
runBlocking {
Copy link
Member

Choose a reason for hiding this comment

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

Do we plan to simplify this blocking call in the future?

@@ -291,6 +292,45 @@ object SendMessageActionHelper {
LegacyDestinationResponse.Builder().withStatusCode(status.statusCode)
.withResponseContent(status.statusText).build()
}
LegacyDestinationType.LEGACY_EMAIL -> {
Copy link
Member

Choose a reason for hiding this comment

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

Can we not re-use the logic from sendEmailMessage below by abstracting out to the pieces in a util method, to avoid code duplication?

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. Few suggestions/clarifications which are non-blocking

@qreshi qreshi merged commit 23dd949 into opensearch-project:main Apr 16, 2022
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.

5 participants