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

[DDW-248] Refactor compress/download logs handling #995

Merged

Conversation

thedanheller
Copy link
Contributor

@thedanheller thedanheller commented Jun 26, 2018

This PR refactors compress/download logs handling.

Todo:

  • Download logs should always pack fresh logs into logs.zip file
  • Bug report should always pack fresh logs into logs.zip file and submit it to the Report server.
  • Create logs.zip files with timestamp [1].

[1] Format based in this answer.

Screenshots:

Normal state

image

Submitting state (Close button is disabled, 50% opacity)

image


Review Checklist:

Basics

  • PR is updated to the most recent version of target branch (and there are no conflicts)
  • PR has a good description that summarizes all changes and shows some screenshots or animated GIFs of important UI changes
  • CHANGELOG entry has been added and is linked to the correct PR on GitHub
  • Automated tests: All acceptance tests are passing (yarn run test)
  • Manual tests (minimum tests should cover newly added feature/fix): App works correctly in development build (yarn run dev)
  • Manual tests (minimum tests should cover newly added feature/fix): App works correctly in production build (yarn run package / CI builds)
  • There are no flow errors or warnings (yarn run flow:test)
  • There are no lint errors or warnings (yarn run lint)
  • Text changes are proofread and approved (Jane Wild)
  • There are no missing translations (running yarn run manage:translations produces no changes)
  • UI changes look good in all themes (Alexander Rukin)
  • Storybook works and no stories are broken (yarn run storybook)
  • In case of dependency changes yarn.lock file is updated

Code Quality

  • Important parts of the code are properly documented and commented
  • Code is properly typed with flow
  • React components are split-up enough to avoid unnecessary re-rendering
  • Any code that only works in Electron is neatly separated from components

Testing

  • New feature / change is covered by acceptance tests
  • All existing acceptance tests are still up-to-date
  • New feature / change is covered by Daedalus Testing scenario
  • All existing Daedalus Testing scenarios are still up-to-date

After Review:

  • Merge PR
  • Delete source branch
  • Move ticket to done on the Youtrack board

Copy link
Contributor

@nikolaglumac nikolaglumac left a comment

Choose a reason for hiding this comment

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

Great work @daniloprates 👍

I see only a couple of issues:

  • compressed log files name should contain the UTC timestamp instead of the local time zone time (please see how we do it here: https://github.com/input-output-hk/daedalus/blob/develop/source/main/utils/setupLogging.js#L19)
  • support-request dialog generates the logs in the moment of opening of the dialog instead of in the moment user clicks on "Submit" (this is bad as it can happen that the user leaves the dialog open for a long time and then submitted logs will be missing the part of the data)
  • even if the user keeps the "attach-logs" switch off the support request will still attach his logs which should not happen:
    logs
  • when you open the support-dialog the submit button shows with the spinner (as if something is happening) - probably due to the fact you are compressing the logs on dialog mount (which should not be the case):
    spinner
    The last of the issues on the list points me into direction of thinking that this issue actually hasn't been resolved: https://iohk.myjetbrains.com/youtrack/oauth?state=%2Fyoutrack%2Fissue%2FDDW-246

Thanks for fixing this!

@@ -0,0 +1,7 @@
import moment from 'moment';
Copy link
Contributor

Choose a reason for hiding this comment

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

@daniloprates please add // @flow to the top of this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

✔︎

`${prefix}-${moment().format('YYYY-MM-DDThhmmss')}.${filetype}`;

export const getFilenameWithTimestamp = (prefix = 'logs', filetype = 'zip') => fileName =>
fileName.match(RegExp(`(${prefix}-)([0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{6})(.${filetype})`));
Copy link
Contributor

Choose a reason for hiding this comment

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

@daniloprates this regexp will have to be updated once you change the filenames to contain timestamp in UTC.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

✔︎

@@ -19,4 +21,19 @@ export const setupLogging = () => {
const formattedDate = moment.utc(msg.date).format('YYYY-MM-DDTHH:mm:ss.0SSS');
return `[${formattedDate}Z] [${msg.level}] ${msg.data}`;
};

// Removes existing logs
fs.readdir(appLogsFolderPath, (err, files) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

@daniloprates this part works great 🎉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🙂

};

componentWillMount() {
this.props.onGetLogs();
this.props.onDeleteCompressedLogs();
this.props.onGetFreshLogs();
Copy link
Contributor

Choose a reason for hiding this comment

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

@daniloprates we need to make sure this call only fetches the log files list and doesn't compress them!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Even when the user submits it?

// regular submit
this.props.onSubmit(data);
}
this.props.onSubmit(data);
Copy link
Contributor

Choose a reason for hiding this comment

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

@daniloprates we shouldn't send the log files if the user has set the "attach-logs" switch to off state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

✔︎

@@ -61,8 +65,8 @@ export default class BugReportDialogContainer extends Component<InjectedProps> {
onGetLogs={() => {
getLogs.trigger();
}}
onCompressLogs={(logs) => {
compressLogs.trigger({ logs });
onGetFreshLogs={(logs) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

@daniloprates what is the difference between onGetLogs and onGetFreshLogs?
If the later one actually compresses the logs then I think the name should be changed...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed it to avoid confusion

_compressLogs = action(({ logs }) => {
this.isCompressing = true;
ipcRenderer.send(COMPRESS_LOGS.REQUEST, toJS(logs));
const { fileName = filenameWithTimestamp() } = this.compressedFileDownload;

Copy link
Contributor

Choose a reason for hiding this comment

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

@daniloprates we don't need this empty line. Please remove it.

fileName: filenameWithTimestamp()
};
this.isCompressing = true;

Copy link
Contributor

Choose a reason for hiding this comment

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

@daniloprates we don't need this empty line. Please remove it.

@thedanheller
Copy link
Contributor Author

Generating the logs only upon form submission allowed for a much simpler logic 🙂

Copy link
Contributor

@nikolaglumac nikolaglumac left a comment

Choose a reason for hiding this comment

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

@daniloprates great improvements!
Just a couple of more small changes and then we are done:

  • please update log file timestamp format (posted comment in code)
  • now with your awesome deletion of the log files on app-start-time we no longer need to delete them on report-dialog close action (as it could cause race conditions)
  • one extra thing I think we need to do is to prevent closing of the report-dialog in case of an active submission (both on "X" button and on click outside of the dialog)
    Thanks for implementing these!

import moment from 'moment';

export const filenameWithTimestamp = (prefix:string = 'logs', filetype:string = 'zip') =>
`${prefix}-${moment.utc().format('YYYY-MM-DDThhmmss.0SSS')}.${filetype}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

@daniloprates please use the following format YYYY-MM-DDTHH:mm:ss.0SSS here (and this should be reflected on the getFilenameWithTimestamp function.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh one thing I forgot - please append Z to the end of the timestamp so that it looks like this: logs-2018-07-04T08:48:19.0182Z.zip
Thanks! :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @nikolaglumac!

I'll add the 'Z', however, it's not possible to add the colons, as it's an invalid character for filenames.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

✔︎

@thedanheller thedanheller removed the WIP label Jul 5, 2018
@@ -236,6 +236,11 @@ export default class BugReportDialog extends Component<Props, State> {
this.setState({ showLogs: value });
};

onClose = () => {
const { error, onCancel } = this.props;
if (!this.state.isSubmitting || error) onCancel();
Copy link
Contributor

Choose a reason for hiding this comment

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

@daniloprates closing should be possible in case of an error - we should prevent it only in case of submitting state!

onClose={onCancel}
closeButton={<DialogCloseButton onClose={onCancel} />}
onClose={this.onClose}
closeButton={<DialogCloseButton disabled={isSubmitting && !error} onClose={this.onClose} />}
Copy link
Contributor

Choose a reason for hiding this comment

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

@daniloprates closing should be possible in case of an error - we should prevent it only in case of submitting state!

@nikolaglumac
Copy link
Contributor

@daniloprates can you please post screenshots of how the Dialog close button looks while disabled?
I think @a-rukin should take a look at it ;)

@thedanheller
Copy link
Contributor Author

@nikolaglumac @a-rukin ✔︎

@thedanheller thedanheller removed the WIP label Jul 6, 2018
@alexander-rukin
Copy link
Contributor

Close button in disable state - OK

@thedanheller thedanheller force-pushed the chore/ddw-248-refactor-compress-download-logs-handling branch from af76c11 to 27fc619 Compare July 10, 2018 16:30
@thedanheller thedanheller removed the WIP label Jul 10, 2018
@thedanheller
Copy link
Contributor Author

thedanheller commented Jul 10, 2018

Commits 27fc619 and 43a75fc:

  • Fixed bug where, when submitting the Bug Report form without filling the inputs, the button would get disabled;
  • Requesting the logs 2 times, when loading the BugReport dialog AND when submitting it;
  • Moved the isSubmitting logic into the ProfileStore;
  • Renamed requestFreshCompressedLogs to getLogsAndCompress;
  • Renamed compressedFileDownload.inProgress to compressedLogsFile.downloadInProgress;
  • Created bugReportInProgress;
  • Renamed getFileNameWithTimestamp to isFileNameWithTimestamp;
  • Created extractFileNameFromPath to get the fileName from the log's path.

Copy link
Contributor

@nikolaglumac nikolaglumac left a comment

Choose a reason for hiding this comment

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

Brilliant work @daniloprates 🎉
This is an amazing improvement and I can see how this will eliminate all the logs-related issues we had 👍

@nikolaglumac nikolaglumac merged commit 077a182 into develop Jul 12, 2018
@nikolaglumac nikolaglumac deleted the chore/ddw-248-refactor-compress-download-logs-handling branch July 12, 2018 11:37
This was referenced Oct 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants