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

Enable email notifier to send emails for health check failures #244

Closed
wants to merge 57 commits into from

Conversation

prakhar10
Copy link
Member

This change enables to send email notifications for healthcheck failures on backend trino clusters.

New fields added in the NotifierConfiguration.java class:
enabled - To enable or disable sending emails for healthcheck failures
gatewayInstance - To specify gateway instance name in case there are multiple instances. This will be displayed in the email subject so that one can know in which instance the cluster is unhealthy.
customContent - To provide custom email body in case the default content is not very helpful.

Copy link

cla-bot bot commented Feb 10, 2024

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@prakhar10
Copy link
Member Author

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

I have already sent this.

@ebyhr ebyhr changed the title fix: Enable email notifier to send emails for health check failures Enable email notifier to send emails for health check failures Feb 14, 2024
Copy link
Member

@ebyhr ebyhr left a comment

Choose a reason for hiding this comment

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

Just skimmed.

Copy link

cla-bot bot commented Feb 14, 2024

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@willmostly
Copy link
Contributor

@prakhar10 could you squash your commits?

I think this enhancement should include some tests, there are currently none for notifications.

Copy link
Contributor

@willmostly willmostly left a comment

Choose a reason for hiding this comment

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

Good progress, some suggestions on the tests

ImmutableList.Builder<TrinoClusterStatsObserver> observerBuilder = ImmutableList.builder();
observerBuilder.add(new HealthCheckObserver(mgr));
observerBuilder.add(new ClusterStatsObserver(backendStateManager));
if (notifierConfiguration.isEnabled()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove

 NotifierConfiguration notifierConfiguration = getConfiguration().getNotifier();

above and use

if (monitorConfig.getNotifier().isEnabled()) {

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we cannot get monitorConfig.getNotifier() because monitorConfig is an object of MonitorConfiguration and not NotifierConfiguration

@Test
public void testSendNotificationCustomContent()
{
NotifierConfiguration notifierConfiguration = mock(NotifierConfiguration.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

A mock isn't needed here - just initialize directly and use the setters. This applies to the other tests using NotifierConfiguration as well


EmailNotifier emailNotifier = new EmailNotifier(notifierConfiguration);

emailNotifier.sendNotification("Test Subject", "Test Content");
Copy link
Contributor

Choose a reason for hiding this comment

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

Its not clear to me what this is testing. Can you assert a success condition, or is the test just that this runs without throwing an error?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah it was just basically to see if there are no errors produced since the method returns void

@Test
public void testNotifyUnhealthyCluster()
{
Notifier notifier = Mockito.mock(Notifier.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

This test suite may be better with a TestingNotifier implementation of Notifier instead of of mocks - wdyt @prakhar10 and @ebyhr? Sth like

public class TestingNotifier
        implements Notifier
{
    List<Notification> notifications = new ArrayList<>();
    public void sendNotification(String from, List<String> recipients, String subject, String content)
    {
       recipients.forEach(recipient -> notifications.add(new Notification(from, recipient, subject, content))
    }
    
    public List<Notification> getNotifications()
    {
       return notifications;
    }   
    class Notification { 
       //should have fields for rom, recipient, subject, content
    }
}

Then tests can observe the notifications produced rather than testing for internal details like method invocations.

public class TestClusterStateListenerModule
{
@Test
public void testGetClusterStatsObservers()
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename to testClusterStateListenerModule

@mosabua
Copy link
Member

mosabua commented Mar 20, 2024

@prakhar10 can you address to the feedback comments

oneonestar and others added 28 commits April 14, 2024 23:11
* Clean brew install in quick start doc 
* Use gateway version 7
* Use PostgreSQL docker container
- Including recommendation for dev and test usage only
- change langing page to /dashboard
- Add hyperlink to Trino Gateway in UI
The restUserInfo method in the LoginResource class and
the findQueryHistory method in the GatewayWapResource
were using string manipulation of the getMemberOf method
from the LbPrincipal to do role authorization. This change
fixes the role authorization to be consistent throughout
the app by utilizing the isUserInRole method that keeps
the context of the LbAuthorization when checking user
access to the ADMIN, USER, and API roles.
- with process forwarding config only for now
Ensure objects are serializable without AUTO_DETECT_GETTERS.
Convert request objects into record to reduce boilerplate.
@prakhar10 prakhar10 closed this Apr 15, 2024
@prakhar10
Copy link
Member Author

Branch was messed up, created a new PR - #319

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet