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

fix: reduce log size #2680

Merged
merged 43 commits into from
Jul 21, 2022
Merged

fix: reduce log size #2680

merged 43 commits into from
Jul 21, 2022

Conversation

MuckT
Copy link
Collaborator

@MuckT MuckT commented Jul 8, 2022

Description

Creates monthly logs files. If a log file is older than 60 days it's deleted on app start. When sending to support all log files are separately attached to the support email.

Other changes

Tested

Tested locally on iOS with a device to known reproduce the issue of failing to send logs to support.

How others should test

Perquisite: An email client present on test device.

  1. Navigate to Settings
  2. Tap 'Show Debug Screen'
  3. Observe logs present
  4. Tap 'Email Logs to Support'
  5. Type in a Test Message e.g. 'Testing Logs'
  6. Tap 'Submit'
  7. Observe email client with pre-populated message and logs attached.

Related issues

Backwards compatibility

Yes

@MuckT MuckT requested a review from jeanregisser July 8, 2022 08:30
@codecov
Copy link

codecov bot commented Jul 8, 2022

Codecov Report

Merging #2680 (c3b9650) into main (b21bc3c) will decrease coverage by 0.04%.
The diff coverage is 61.66%.

❗ Current head c3b9650 differs from pull request most recent head 4e1055a. Consider uploading reports for the commit 4e1055a to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2680      +/-   ##
==========================================
- Coverage   79.76%   79.71%   -0.05%     
==========================================
  Files         604      605       +1     
  Lines       21756    21787      +31     
  Branches     3947     3956       +9     
==========================================
+ Hits        17354    17368      +14     
- Misses       4350     4367      +17     
  Partials       52       52              
Impacted Files Coverage Δ
src/utils/readFile.ts 40.00% <40.00%> (ø)
src/utils/Logger.ts 65.87% <58.97%> (+1.87%) ⬆️
src/account/SupportContact.tsx 90.00% <88.88%> (-0.77%) ⬇️
src/account/emailSender.ts 88.23% <100.00%> (ø)
src/app/Debug.tsx 93.02% <100.00%> (ø)
src/web3/saga.ts 77.77% <0.00%> (-3.04%) ⬇️
src/tokens/utils.ts 97.05% <0.00%> (-2.95%) ⬇️

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 b21bc3c...4e1055a. Read the comment docs.

@MuckT MuckT requested a review from kathaypacific July 8, 2022 16:14
// If the creation time of the file is more than 28 days ago, delete it.
RNFS.stat(logFilePath)
.then((stat) => {
if (+stat.ctime < +new Date() - 4 * 7 * 24 * 60 * 60 * 1000) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we worried about losing valuable log content that could help support fix issues?

Another simple option that avoids this is to use a different log file for each day or week (and delete the old ones). We keep recent content, but can still clean up the old stuff that doesn't matter.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If the user is sending a log to support in the worst case we would have from the application start to sending the contact support which would likely contain the issue; additionally, since all the transactions are on the chain support can and developers can also be triage via Celo Explorer.

We could create logs for each week or day and combine them when sending to support, we'd just need a bit more logic around combining logs alongside finding and deleting old logs. If this is preferred we can certainly do it either in a follow up PR or adjust this PR.

Copy link
Member

@jeanregisser jeanregisser Jul 11, 2022

Choose a reason for hiding this comment

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

It's always annoying to be missing important log content when debugging. Like you said @MuckT there's not so much chance the important info would be missing, but still it can happen.

I like the option of writing a different log files each week. And cleaning up old ones.
We don't necessarily need to combine them when sending to support. We can send the last X log files as individual attachments. But not sure it plays well with the current way we're sending logs via email.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@jeanregisser I did end up creating log files for each day and combining them; however, given the performance hit of combining several files, can take upwards of 25 seconds, maybe this is a good path to go if we don't implement #2701.

Copy link
Member

@jeanregisser jeanregisser left a comment

Choose a reason for hiding this comment

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

Thanks for taking this one 🙏

src/utils/Logger.ts Outdated Show resolved Hide resolved
// If the creation time of the file is more than 28 days ago, delete it.
RNFS.stat(logFilePath)
.then((stat) => {
if (+stat.ctime < +new Date() - 4 * 7 * 24 * 60 * 60 * 1000) {
Copy link
Member

@jeanregisser jeanregisser Jul 11, 2022

Choose a reason for hiding this comment

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

It's always annoying to be missing important log content when debugging. Like you said @MuckT there's not so much chance the important info would be missing, but still it can happen.

I like the option of writing a different log files each week. And cleaning up old ones.
We don't necessarily need to combine them when sending to support. We can send the last X log files as individual attachments. But not sure it plays well with the current way we're sending logs via email.

@emerge-tools
Copy link

emerge-tools bot commented Jul 12, 2022

📏 Size Analysis

Total install size 68.1 MB | This change: ⬆️ +153.2 kB (+0.225%)

Image of diff

🗂 See size breakdown
Item Install size
main.jsbundle ⬆️ 151.6 kB
react_native_mail.framework/RNMail.mail:callback: 743 B

🔎 See the full size analysis (4e1055a) merging into main (b21bc3c)

Copy link
Member

@jeanregisser jeanregisser left a comment

Choose a reason for hiding this comment

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

Great!

src/utils/Logger.ts Outdated Show resolved Hide resolved
src/utils/Logger.ts Outdated Show resolved Hide resolved
src/utils/Logger.ts Outdated Show resolved Hide resolved
src/utils/Logger.ts Outdated Show resolved Hide resolved
@MuckT MuckT changed the title Reduce Log Size fix: reduce log size Jul 13, 2022
Copy link
Collaborator

@silasbw silasbw left a comment

Choose a reason for hiding this comment

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

nice!

src/utils/Logger.ts Outdated Show resolved Hide resolved
src/utils/Logger.ts Outdated Show resolved Hide resolved
src/utils/Logger.ts Outdated Show resolved Hide resolved
src/utils/Logger.ts Outdated Show resolved Hide resolved
const writeLog = async (level: string, message: string) => {
// If log folder not present create it
if (!(await RNFS.exists(this.getReactNativeLogsDir()))) {
await RNFS.mkdir(this.getReactNativeLogsDir())
Copy link
Collaborator

Choose a reason for hiding this comment

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

this could throw, it's a toctou bug. you should handle the error, or have this code as part of log initialization (where's it's guaranteed to be serialized)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The problem I am seeing testing the change with moving it to the log initialization, out of writeLog up into the overrideConsoleLogs call, is that we miss some of the early logs from the the app start.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The first line in the daily logs should be Reactotron Configured from index.js if it's not that line we're missing logs from app start. This can be tested by creating a new app install locally and navigating to developer settings and selecting debug.

@MuckT
Copy link
Collaborator Author

MuckT commented Jul 17, 2022

@jean ended up going with the option from #2680 (comment) as creating the combined logs was taking sometimes upwards of 25 seconds. The only thing left should be to cleanup the typings in src/account/SupportContact.tsx.

src/utils/Logger.ts Outdated Show resolved Hide resolved
src/utils/readFile.ts Outdated Show resolved Hide resolved
src/utils/readFile.ts Outdated Show resolved Hide resolved
src/utils/Logger.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@kathaypacific kathaypacific left a comment

Choose a reason for hiding this comment

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

I think this looks good, just added a few questions ✨

src/account/SupportContact.tsx Outdated Show resolved Hide resolved
src/account/SupportContact.tsx Outdated Show resolved Hide resolved
src/account/SupportContact.tsx Outdated Show resolved Hide resolved
src/account/SupportContact.tsx Outdated Show resolved Hide resolved
src/utils/Logger.ts Outdated Show resolved Hide resolved
src/utils/Logger.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@kathaypacific kathaypacific left a comment

Choose a reason for hiding this comment

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

thank you!! 🚀

@MuckT MuckT added the automerge Have PR merge automatically when checks pass label Jul 21, 2022
@mergify mergify bot merged commit d6bd8a4 into main Jul 21, 2022
@mergify mergify bot deleted the tomm/reduce-log-size branch July 21, 2022 17:26
@ValoraQA
Copy link

ValoraQA commented Jul 26, 2022

Hey @MuckT, We have verified above issue on Latest Android Internal Release Build and iOS Test Flight Release build V1.37.0 & updated status in test rails.

Observations:

  • User is able to see email id fields pre-populated and also logs.txt file is seen attached

Test rail link:
Android 12: https://valoraapp.testrail.io/index.php?/tests/view/54640
iOS 14: https://valoraapp.testrail.io/index.php?/tests/view/54655
Android 10: https://valoraapp.testrail.io/index.php?/tests/view/54625

Devices: Google Pixel 4a (12.0), iPhone 12(14.7.1), Google Pixel XL (10.0)

Thanks..!!

@ValoraQA
Copy link

Hey @MuckT, We have verified above issue on Latest iOS Test Flight Release build V1.37.0 & updated status in test rails.

Observations:

  • User is able to see email id fields pre-populated and also logs.txt file is seen attached.

Test rail link:
iOS 15: https://valoraapp.testrail.io/index.php?/tests/view/54670

Device: iPhone 13 mini(15.1.1)

Thanks..!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Have PR merge automatically when checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants