-
Notifications
You must be signed in to change notification settings - Fork 295
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
[DDW-248] Refactor compress/download logs handling #995
Conversation
There was a problem hiding this 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:
- 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):
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'; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔︎
source/common/fileName.js
Outdated
`${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})`)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔︎
source/main/utils/setupLogging.js
Outdated
@@ -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) => { |
There was a problem hiding this comment.
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 🎉
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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; | ||
|
There was a problem hiding this comment.
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; | ||
|
There was a problem hiding this comment.
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.
Generating the logs only upon form submission allowed for a much simpler logic 🙂 |
There was a problem hiding this 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!
source/common/fileName.js
Outdated
import moment from 'moment'; | ||
|
||
export const filenameWithTimestamp = (prefix:string = 'logs', filetype:string = 'zip') => | ||
`${prefix}-${moment.utc().format('YYYY-MM-DDThhmmss.0SSS')}.${filetype}`; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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! :)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔︎
@@ -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(); |
There was a problem hiding this comment.
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} />} |
There was a problem hiding this comment.
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!
@daniloprates can you please post screenshots of how the Dialog close button looks while disabled? |
@nikolaglumac @a-rukin ✔︎ |
Close button in disable state - OK |
af76c11
to
27fc619
Compare
|
There was a problem hiding this 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 👍
This PR refactors compress/download logs handling.
Todo:
logs.zip
filelogs.zip
file and submit it to the Report server.logs.zip
files with timestamp [1].[1] Format based in this answer.
Screenshots:
Normal state
Submitting state (Close button is disabled, 50% opacity)
Review Checklist:
Basics
yarn run test
)yarn run dev
)yarn run package
/ CI builds)yarn run flow:test
)yarn run lint
)yarn run manage:translations
produces no changes)yarn run storybook
)yarn.lock
file is updatedCode Quality
Testing
After Review:
done
on the Youtrack board