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

ControllerServlet: do not sent email to admin upon error #6587 #6796

Merged
merged 12 commits into from
Mar 14, 2017

Conversation

LiHaoTan
Copy link
Contributor

Fixes #6587

Outline of Solution

  1. Error report is no longer sent by email immediately.
  2. Add comments to explain why an error report will not be sent.

Additional Info
I added the comments as I feel the code does not explain why an error report does not need to be sent through email. Not sure if this is appropriate.

I also worked on this issue because the person originally working on the issue KYUUBI have went missing.

@LiHaoTan LiHaoTan changed the title Remove sending of email to admin when error report is generated #6587 ControllerServlet: do not sent email to admin upon error #6587 Mar 12, 2017
*/
if (errorReport != null) {
log.severe(ActivityLogEntry.generateSystemErrorReportLogMessage(req, errorReport, userType));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

As we are trying to save time here (we have less than 1 second to finish this part), perhaps just a simple log.severe("Unexpected exception " + e.getMessage()) is enough, in which case we can avoid lines 126-134 too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I have removed the generating of error report.

* in GAE shutting down the instance.
* Note that severe logs are sent by email automatically in the cron job auto/compileLogs.
*/
log.severe("Unexpected exception " + t.getMessage());
Copy link
Contributor

Choose a reason for hiding this comment

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

Good work. While you are at it, see if there is a way to include the stack trace in the log message. Use TeammatesException#toStringWithStackTrace(...)?

@@ -126,7 +127,7 @@ public final void doPost(HttpServletRequest req, HttpServletResponse resp) throw
* in GAE shutting down the instance.
* Note that severe logs are sent by email automatically in the cron job auto/compileLogs.
*/
log.severe("Unexpected exception " + t.getMessage());
log.severe(TeammatesException.toStringWithStackTrace(t));
Copy link
Contributor

Choose a reason for hiding this comment

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

Better. Can you also include a"Unexpected exception caught by ControllerServlet : " ? I would like an easy way to identify log messages originating from this location.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I have added that. However, there seems to be a failing test unrelated to what I have changed. I have added more details in the conversation.

@LiHaoTan
Copy link
Contributor Author

LiHaoTan commented Mar 12, 2017

Running the TestNG test for AccountsDbTest.java results in a failure if testGetAccount is run before testEditAccount.

The failed test can be seen here: https://gist.github.com/anonymous/65a51785dcc12cc9880f5ecfb364cdfd

So if the order of the test changes it will work, for example the following test suite will work:
https://gist.github.com/anonymous/6b08ec022a187d5199a180c2149d9202

Additional Info

Usual sequence of working test:
ci-tests > component-tests > teammates.test.cases.storage.AccountsDbTest.testCreateAccount PASSED
ci-tests > component-tests > teammates.test.cases.storage.AccountsDbTest.testDeleteAccount PASSED
ci-tests > component-tests > teammates.test.cases.storage.AccountsDbTest.testEditAccount PASSED
ci-tests > component-tests > teammates.test.cases.storage.AccountsDbTest.testGetAccount PASSED

Sequence for failing test:
ci-tests > component-tests > teammates.test.cases.storage.AccountsDbTest.testDeleteAccount PASSED
ci-tests > component-tests > teammates.test.cases.storage.AccountsDbTest.testGetAccount FAILED
java.lang.AssertionError at AccountsDbTest.java:35
ci-tests > component-tests > teammates.test.cases.storage.AccountsDbTest.testEditAccount PASSED
ci-tests > component-tests > teammates.test.cases.storage.AccountsDbTest.testCreateAccount PASSED

@xpdavid
Copy link
Contributor

xpdavid commented Mar 12, 2017

@LiHaoTan Yes. The test cases for *LogicTest will fail randomly. Should be find after #6778.

@LiHaoTan
Copy link
Contributor Author

@xpdavid Thanks for the info. The tests are now passing.

@wkurniawan07
Copy link
Member

@damithc doing what is done right now will strip off all the information originally sent via email: request method, request user agent, request path, request URL, request parameters. I believe at least three of them are useful, if not critical, in troubleshooting.

@damithc
Copy link
Contributor

damithc commented Mar 12, 2017

@damithc doing what is done right now will strip off all the information originally sent via email: request method, request user agent, request path, request URL, request parameters. I believe at least three of them are useful, if not critical, in troubleshooting.

This PR is doing what I have been doing for many months now. I've been applying this "fix" to live code before deploying ever since we started having many server crashes. This PR is just migrating my hot patch to the permanent code base. :-p

Yes, it will strip off useful info from the log message, but those info are logged by GAE anyway, so they are not completely lost. It's just a bit harder to locate. I'm not sure how much we can do within 1 second under full load, so I don't want to risk entire server being killed in order to collect those info.

Having said that, we'll try to add those things back after we've resolved some of our other performance issues and server crashes are no longer a big concern.

@wkurniawan07
Copy link
Member

In that case, @LiHaoTan check if the following functions are still used somewhere else:

  • EmailGenerator#generateSystemErrorEmail
  • ActivityLogEntry#generateSystemErrorReportLogMessage

If they are not, remove them as well.

@xpdavid xpdavid added the s.Ongoing The PR is being worked on by the author(s) label Mar 12, 2017
Remove ActivityLogEntry#generateSystemErrorReportLogMessage.
Remove EmailGenerator#generateSystemErrorEmail.
Remove test case EmailGeneratorTest#testSystemCrashReportEmailContent.
@LiHaoTan
Copy link
Contributor Author

LiHaoTan commented Mar 12, 2017

Ok I have removed them. By the way, they still look useful, or are they not?

@wkurniawan07
Copy link
Member

@LiHaoTan useful as it may, retaining an unused method for that reason is a mindset that causes dead code to stay in a code base. Its effect is non-trivial; you can read about it here.

Copy link
Member

@wkurniawan07 wkurniawan07 left a comment

Choose a reason for hiding this comment

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

Few more things to remove.

String subject = String.format(EmailType.ADMIN_SYSTEM_ERROR.getSubject(),
Config.getAppVersion(), error.getMessage());

verifyEmail(email, Config.SUPPORT_EMAIL, subject, "/systemCrashReportEmail.html");
Copy link
Member

Choose a reason for hiding this comment

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

This HTML file should be fine to be removed. It can be found in the folder src/test/resources/emails.

modifiedContent = email.getContent().replaceAll(lastCommonLineRegex, "$1...$2");
email.setContent(modifiedContent);

verifyEmail(email, Config.SUPPORT_EMAIL, subject, "/systemCrashReportEmailLessInfo.html");
Copy link
Member

Choose a reason for hiding this comment

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

Similarly here.

@wkurniawan07 wkurniawan07 self-assigned this Mar 13, 2017
@LiHaoTan
Copy link
Contributor Author

LiHaoTan commented Mar 13, 2017

@wkurniawan07 Ok I have removed the files, sorry for overlooking them.

Thanks for the link on the dead code.

Copy link
Member

@wkurniawan07 wkurniawan07 left a comment

Choose a reason for hiding this comment

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

Few more things to remove.

"${stackTrace}", stackTrace);

EmailWrapper email = getEmptyEmailAddressedToEmail(Config.SUPPORT_EMAIL);
email.setSubject(String.format(EmailType.ADMIN_SYSTEM_ERROR.getSubject(), Config.getAppVersion(), errorMessage));
Copy link
Member

Choose a reason for hiding this comment

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

Looks like I missed this. This enum EmailType.ADMIN_SYSTEM_ERROR should be fine to be removed as well.


String actualUser = userType == null || userType.id == null ? "Not logged in" : userType.id;

String emailBody = Templates.populateTemplate(EmailTemplates.SYSTEM_ERROR,
Copy link
Member

Choose a reason for hiding this comment

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

So is EmailTemplates.SYSTEM_ERROR, and by extension src/main/resources/systemErrorEmailTemplate.html.

Copy link
Member

@wkurniawan07 wkurniawan07 left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for your contribution @LiHaoTan! 👍

@wkurniawan07 wkurniawan07 added the s.FinalReview The PR is ready for final review label Mar 13, 2017
@wkurniawan07 wkurniawan07 removed the s.Ongoing The PR is being worked on by the author(s) label Mar 13, 2017
@damithc damithc added s.ToMerge The PR is approved by all reviewers including final reviewer; ready for merging and removed s.FinalReview The PR is ready for final review labels Mar 14, 2017
@wkurniawan07 wkurniawan07 merged commit d0e3918 into TEAMMATES:master Mar 14, 2017
@wkurniawan07 wkurniawan07 added this to the V5.99 milestone Mar 14, 2017
@LiHaoTan LiHaoTan deleted the 6587-remove-send-email branch March 15, 2017 09:51
shrut1996 pushed a commit to shrut1996/teammates that referenced this pull request Apr 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s.ToMerge The PR is approved by all reviewers including final reviewer; ready for merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants