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

ENH: Automated Bug Reporting #92

Merged
merged 33 commits into from
Mar 29, 2018
Merged

ENH: Automated Bug Reporting #92

merged 33 commits into from
Mar 29, 2018

Conversation

teddyrendahl
Copy link
Contributor

Description

The idea of this PR is that user should be able to report a bug from the IPython session that will eventually make its way to Bug-Reports. Because we have standardized the way that we organize logs, CONDA environments e.t.c we can tell a lot about the current Python environment by just poking the right environment variables e.t.c.. To see the polished example of what the bug report will look like checkout https://github.com/teddyrendahl/Bug-Reports/issues/1. The process is kind of multi-step so I figure I'd give a quick walkthrough here. Everything is kicked off when the user call the report_bug function. This can either be used as an IPython magic to report a bug in a single line of code, or run as a regular function where you can grab the last n commands from the shell.

#IPython Magic
%report_bug my_buggy_function(foo=bar)
# Standard function call
foo = 1
bar = 2
first_buggy_function(foo)
second_buggy_function(bar)
report_bug(prior_commands=4)

We then ask the operator some brief questions about the issue we will not be able to determine programatically.

Please provide a one sentence description of the problem you are encountering: Issue running fake scan
How many of the previous commands are relevant  to the issue you would like investigated?:  5
Please enter a name so we can follow-up with additional questions: trendahl

A vim window with a little prompt is also opened up so that the operator can type a more detailed explanation of the issue that looks like

# Please describe the issue you are wishing to report. What did you expect to
# happen? What actually happened? Does this issue occur every time you use this
# function?

# Lines that start with a '#' will be ignored. Save the session and exit to
# store the description. Press "i" to be begin typing, then "Esc" followed by
# ":wq" to exit.

Now the major issue is that we can't expect every operator to have a GitHub account so instead when the issue is created it gets stored in a JSON file in a known location in NFS. Once this is ready for ops we can setup a CRON job with a reasonable frequency to scan the directory, find new issues and post them to GitHub. This will probably be done with a pcdsbot account I'll setup. The post_to_github function is there when this is ready to go, and I also created the full script as hutch-python/bin/post-issues

Motivation and Context

Closes #64

How Has This Been Tested?

Tests added for relevant top-level functions.

Where Has This Been Documented?

Added this to the Useful Utilities page of the User Documentation. Also updated the Internal API Reference

@teddyrendahl teddyrendahl requested a review from ZLLentz March 27, 2018 00:37
@codecov-io
Copy link

codecov-io commented Mar 27, 2018

Codecov Report

Merging #92 into master will decrease coverage by 1.12%.
The diff coverage is 92.24%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #92      +/-   ##
==========================================
- Coverage   98.75%   97.62%   -1.13%     
==========================================
  Files          14       15       +1     
  Lines         560      674     +114     
==========================================
+ Hits          553      658     +105     
- Misses          7       16       +9
Impacted Files Coverage Δ
hutch_python/cli.py 100% <100%> (ø) ⬆️
hutch_python/constants.py 100% <100%> (ø) ⬆️
hutch_python/log_setup.py 100% <100%> (ø) ⬆️
hutch_python/bug.py 90.81% <90.81%> (ø)

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 4ab1d18...56d7601. Read the comment docs.

@teddyrendahl
Copy link
Contributor Author

After sleeping on it. I think I'll switch this to use an OAuth token and post issues immediately instead of the folder and CRON job. Recommending that this is done in a follow-up PR though.

Copy link
Member

@ZLLentz ZLLentz left a comment

Choose a reason for hiding this comment

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

I like this implementation, see comments for suggestions for changes. Consider trying to bump up the coverage too, bug.py is the lowest-coverage file in the module by a fair bit.

bin/post-issues Outdated


description = """\
Post all of the stored issue to https://github.com/pcdshub/Bug-Reports
Copy link
Member

Choose a reason for hiding this comment

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

typo, issue should be issues

bin/post-issues Outdated
pw = args.password or getpass.getpass()
# Run post_to_github on every stored issue
for issue in os.listdir(BUG_REPORT_PATH):
if issue.endswith('.json'):
Copy link
Member

Choose a reason for hiding this comment

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

Is anything else in this folder? It seems odd to me to check for the file extension when that isn't sufficient to guarantee that we have a well-formed bug report. I guess it's a good first cut though if someone mangles the BUG_REPORT_PATH

bin/post-issues Outdated
formatter_class=fclass)
parser.add_argument('-u', '--user', dest='username',
default=None,
help="Username for GitHub account")
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this is an optional argument, which is odd because we don't prompt the user for it if omitted. I expect the script breaks if this isn't passed.

without valid GitHub accounts. Once issues are received on GitHub the
appropriate action will be made by the PCDS staff. This may mean a deeper look
at the linked log files and/or creating a distilled issue or action item in a
different repository.
Copy link
Member

Choose a reason for hiding this comment

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

None of the bug reporting stuff belongs on this page, it's not a user utility that you'd include in a beamline file. It deserves it's own page before this one on the index.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't realize this was only for beamline.py utilities. Might suggest a rename if this was your intention.

Copy link
Member

Choose a reason for hiding this comment

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

I agree, the page should be renamed. Even if it would fit on the page, bug reporting still deserves it's own page because of how important it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. Bug Reporting page has been created 👍

"""
One advantage of standardizing the logging system and startup scripts with
hutch-python is programatically being able to gather information about the
currrent Python environment. One common use case for much of this information
Copy link
Member

Choose a reason for hiding this comment

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

currrent typo

# If the user somehow has no IPython history this is raised. A very rare
# occurence except for in Continuous Integration tests
except OSError:
logger.exception
Copy link
Member

Choose a reason for hiding this comment

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

What does this do without a call or inputs?

try:
logfiles = get_session_logfiles()
except RuntimeError:
logger.warning("No debug RotatingFileHandler configured for session")
Copy link
Member

Choose a reason for hiding this comment

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

Surely not every RuntimeError is because the rotating file handler is missing? I feel like get_session_logfiles() should return an empty list instead of raising an error when there are no session logfiles.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a hold over from the get_console_handler functionality.

@line_magic
def report_bug(self, line):
"""Creates a bug_report while running the given line"""
# Enter both the DEBUG context and store the output of our command
Copy link
Member

Choose a reason for hiding this comment

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

Is this comment true?

return r


def test_bug_report(monkeypatch):
Copy link
Member

Choose a reason for hiding this comment

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

didn't realize this monkeypatch fixture existed, neat trick

bin/post-issues Outdated
logger.exception("Error posting %s", issue)


if __name__ == '__main__':
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a test that runs this script? Look for my tests that shell out and call hutch-python. Alternatively, move main into bug.py and test it there.

@teddyrendahl
Copy link
Contributor Author

This is ready for review again.

path = os.path.join(BUG_REPORT_PATH, '{}.json'.format(str(uuid.uuid4())))
logger.info("Saving JSON representation of bug report %s", path)
simplejson.dump(report, open(path, 'w+'))
return path
Copy link
Member

Choose a reason for hiding this comment

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

Did you change your mind about making this skip the save file step?

Copy link
Member

Choose a reason for hiding this comment

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

Never mind, you wanted to do this in a separate PR.

@ZLLentz
Copy link
Member

ZLLentz commented Mar 28, 2018

I'm still uneasy about the low coverage. If you'd like, I'll suggest lines that should be covered.

@teddyrendahl
Copy link
Contributor Author

Fair retort. The major hole is the get_text_from_editor function because I was too lazy to mock a vim session. I'll write this up.

@teddyrendahl
Copy link
Contributor Author

Added two additional tests for the specifics of get_current_environment and get_text_from_editor. Uncovered an issue if PYTHONPATH is configured but not pointing to a directory that exists so 👏 for being persistent @ZLLentz

I left the BugMagics class untested. Not very clear how to do it and the function is largely just making IPython API calls we assume are correct then calling report_bug which is tested already.

Copy link
Member

@ZLLentz ZLLentz left a comment

Choose a reason for hiding this comment

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

👍

@teddyrendahl teddyrendahl merged commit ac9d8f7 into pcdshub:master Mar 29, 2018
@teddyrendahl teddyrendahl deleted the bug_report branch March 29, 2018 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug Reporting
3 participants