AtlasOfLivingAustralia / logger-service

Atlas event logging
https://logger.ala.org.au
1 stars 8 forks source link

Attempting to access LogEvents list page in the production instance throws an error. #49

Open sughics opened 2 years ago

sughics commented 2 years ago
  1. In the logger-service production instance, the LogEvents List page accessible via the logger admin portal attempts to load for a while and then returns an error page. This does not occur on the test instance.

Screen Shot 2022-07-06 at 1 33 43 pm

  1. (11/08/22) Similar to the issue above, the LogDetail List page accessible via the logger admin portal throws same error. This only occurs when attempting to sort the table using the following columns Entity Type, Entity Uid, and Record Count.
sughics commented 2 years ago

Issue potentially related to #35

sughics commented 2 years ago

Appears to be a memory issue on the database when retrieving the LogEvent list . Latest mysql error logs show Out of sort memory error Screen Shot 2022-07-06 at 5 42 38 pm

These errors correlate with the exact times requests were made to to GET /admin/logEvent.

I was able to replicate the same error as seen above via CLI sql statements as well. Error is thrown on any attempts to sort the returned data if all columns are selected e.g. select * from <<table_name>> ORDER BY created DESC LIMIT 1000; ERROR 1038 (HY001): Out of sort memory, consider increasing server sort buffer size

sughics commented 2 years ago

As suggested by @joe-lipson , indexes have not been added/set properly for the columns which are used to sort the results. Adding index correctly for the column i.e. month used to filter the default query significantly reduced query times when tested via the CLI but the error still persisted when the /admin/logEvent path was requested via the UI.

SQL logs were inspected on local db instance to get the actual SQL query made by the application. The query used by grails' scaffolded LogEvent controller implementation actually converts any selected sorting column e.g.month (default) to uppercase. e.g. select * from log_event ORDER BY uppercase(month) DESC LIMIT 10. Regardless of any indexes set for the relevant column, this query throws Out of sort memory error.

Converting the sorting column to uppercase during the query is not explicitly defined anywhere is the codebase or configuration. It seems to be set internally by Grails or Hibernate

Fix

Looking into archiving current log_event and log_detail per README.md

sughics commented 2 years ago

To test the above in local environment, please enable general sql logs in your local mysql instance as root and tail the generated logs as you make requests to admin/logEvent or admin/logDetail. The relevant sql logs should not include the UPPER function on the order column e.g. order by upper(logevent0_.month) desc limit 10

Please also test explicit sorting of the results using the columns in the UI for either of the pages mentioned above.
Screen Shot 2022-07-11 at 4 54 01 pm

To enable SQL logging locally:

SET global general_log = 1; SET global log_output. = 'file'; SET global general_log_file = '<path_to_file>' ;