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

debug: use human readable dates for filenames and improve the tests #10806

Merged
merged 2 commits into from
Aug 18, 2021

Conversation

dnephin
Copy link
Contributor

@dnephin dnephin commented Aug 6, 2021

Branched from #10804

The unix timestamps that were used previously make the debug data a little bit more difficult to consume. By using human readable dates we can easily see when the profile data was collected.

Also moves profile.prof, trace.out, consul.log, and metrics.json out of the sub-directories. There is only one of each of these, so we can put them in the top-level directory.

Also improves the test coverage. Two test cases are removed and the assertions from those cases are moved to TestDebugCommand.

Now TestDebugCommand is able to validate the contents of all files. This change reduces the test runtime of the command/debug package by almost 50%, while also improving the test coverage by making much more strict assertions about the files and their contents.

@dnephin dnephin added the pr/no-changelog PR does not need a corresponding .changelog entry label Aug 6, 2021
@dnephin dnephin requested a review from a team August 6, 2021 21:22
@github-actions github-actions bot added the theme/cli Flags and documentation for the CLI interface label Aug 6, 2021
@dnephin dnephin force-pushed the dnephin/debug-filenames-2 branch from 460477f to 6f5698b Compare August 6, 2021 21:39
@vercel vercel bot temporarily deployed to Preview – consul August 6, 2021 21:39 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging August 6, 2021 21:39 Inactive
Comment on lines +78 to +79
fs.WithFile("metrics.json", "", fs.MatchAnyFileContent),
fs.WithFile("consul.log", "", fs.MatchFileContent(validLogFile)),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another possible improvement here might be to ensure the files contain at least one line. We may need to run a goroutine to perform some operations to ensure that some logs and metrics are emitted.

Metrics in particular are difficult to capture because we'd have to wait the 10s interval window, which makes the test a bit slower to run.

Copy link
Contributor

@markan markan left a comment

Choose a reason for hiding this comment

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

Generally looks good, but one question about timestamps

command/debug/debug.go Outdated Show resolved Hide resolved
command/debug/debug.go Show resolved Hide resolved
Copy link
Collaborator

@dhiaayachi dhiaayachi 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 for cleaning this up @dnephin !!
I have a question about the time precision and a suggested cosmetic change.

command/debug/debug.go Outdated Show resolved Hide resolved
command/debug/debug.go Show resolved Hide resolved
@dnephin dnephin force-pushed the dnephin/debug-filenames branch from 22bbd7c to 26ef0df Compare August 18, 2021 16:29
Use the new WriteJsonFile function to write index.json
Remove .String() from time.local() since that is done by %s
Remove an unused field.
@dnephin dnephin force-pushed the dnephin/debug-filenames-2 branch from 6f5698b to f8b36d0 Compare August 18, 2021 16:33
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging August 18, 2021 16:33 Inactive
@vercel vercel bot temporarily deployed to Preview – consul August 18, 2021 16:33 Inactive
@dnephin dnephin removed the pr/no-changelog PR does not need a corresponding .changelog entry label Aug 18, 2021
@dnephin dnephin force-pushed the dnephin/debug-filenames-2 branch from f8b36d0 to bf97e89 Compare August 18, 2021 17:01
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging August 18, 2021 17:01 Inactive
@vercel vercel bot temporarily deployed to Preview – consul August 18, 2021 17:01 Inactive
The unix timestamps that were used make the debug data a little bit more
difficult to consume. By using human readable dates we can easily see
when the profile data was collected.

This commit also improves the test coverage. Two test cases are removed
and the assertions from those cases are moved to TestDebugCommand.

Now TestDebugCommand is able to validate the contents of all files. This
change reduces the test runtime of the command/debug package by almost
50%. It also makes much more strict assertions about the contents by
using gotest.tools/v3/fs.
@dnephin dnephin force-pushed the dnephin/debug-filenames-2 branch from bf97e89 to 797ee06 Compare August 18, 2021 17:07
@vercel vercel bot temporarily deployed to Preview – consul August 18, 2021 17:07 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging August 18, 2021 17:07 Inactive
Base automatically changed from dnephin/debug-filenames to main August 18, 2021 17:18
Copy link
Collaborator

@dhiaayachi dhiaayachi left a comment

Choose a reason for hiding this comment

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

LGTM!

@dnephin dnephin merged commit a2c4069 into main Aug 18, 2021
@dnephin dnephin deleted the dnephin/debug-filenames-2 branch August 18, 2021 19:16
@hc-github-team-consul-core
Copy link
Collaborator

🍒 If backport labels were added before merging, cherry-picking will start automatically.

To retroactively trigger a backport after merging, add backport labels and re-run https://circleci.com/gh/hashicorp/consul/430133.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme/cli Flags and documentation for the CLI interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants