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

Improve config deprecated upgrade log, etc #2854

Conversation

matthewrmshin
Copy link
Contributor

@matthewrmshin matthewrmshin commented Nov 12, 2018

Use DEBUG level for site files - users may not be able to fix them
easily. Use WARNING level for all other files to better alert users.

Remove more print or sys.std*.write statements by converting them to use logging.

  • Remove some unnecessary diagnostics.
  • Remove some debug flag check in favour logging level check.
  • Exit with error message instead of print error then sys.exit(1).

@matthewrmshin
Copy link
Contributor Author

(Not done yet.)

@oliver-sanders
Copy link
Member

See #1136.

@matthewrmshin matthewrmshin force-pushed the improve-conf-deprecated-upgrade-logging branch 2 times, most recently from 8b01653 to 80cfabf Compare November 13, 2018 13:10
@@ -1023,15 +1016,11 @@ def upgrade_pickle_to_json(self):
else:
args.append(cell)
except (EOFError, TypeError, LookupError, ValueError):
n_skips += 1 # skip bad rows
pass
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These were diagnostics for my own use when I wrote these upgrade methods.

They are mostly upgrade methods for restarting Cylc 6 suites in Cylc 7. We should not have much usage for them any more. Happy to revert and leave them alone but aim to remove them for Cylc 8.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's OK to remove them, as they were for testing/debugging only.

When we go full Python3, this - and other try/catch with similar pattern - can go away too with

with ignored(EOFError, TypeError, LookupError, ValueError):
    for col, cell in zip(cols, row):
        ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool syntax.

Copy link
Member

Choose a reason for hiding this comment

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

Cool indeed, I dislike except: pass type statements (although I guess that's probably what this is doing underneath). I've been stuck with Python 2.6 for too long, need to get up to date.

sys.stderr.write(
"fork #1 failed: %d (%s)\n" % (exc.errno, exc.strerror))
sys.exit(1)
except OSError as exc:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For Python 3 readiness.

Copy link
Member

Choose a reason for hiding this comment

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

👏 👏 👏 thanks!!!


# reset umask, octal
os.umask(022)
os.umask(0o22)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For Python 3 readiness.

@matthewrmshin matthewrmshin force-pushed the improve-conf-deprecated-upgrade-logging branch from 80cfabf to 88352a1 Compare November 13, 2018 14:45
sys.exit(1)

LOG.exception(exc2)
raise exc
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here we have an unknown Exception. I think it is best if we re-raise it regardless of debug mode or log level.

Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Member

Choose a reason for hiding this comment

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

Indeed Cylc is a little too fond of swallowing exceptions, particularly in cylc.config.

# Remove symlink to the original suite.
os.unlink(target)

# Create symlink to the suite, if it doesn't already exist.
if source != orig_source:
os.symlink(source, target)

print 'REGISTERED %s -> %s' % (reg, source)
return reg
return reg, source
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 increases the purity of the method:

  • Let it return all the useful variables to the caller.
  • Let the caller decide if it needs to print any diagnostics.
  • I would have wanted to remove the remaining logging logic if there is an easy way to do so.

Copy link
Member

Choose a reason for hiding this comment

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

My first impression was a bit of confusion. Why should we return source, being it is an argument for the function in the first place (which can be a code smell, or a feature or per design [e.g. builder pattern]).

Then I realized reg is also a parameter. I think the code would be simpler to read if it did not return anything. Simply received parameters, registered suites and threw exceptions if any error occurred.

The caller of the function would be responsible for choosing the right value for reg (i.e. if you don't have one, use os.path.basename(os.getcwd())), and for source.

This way, IMO, it would be easier to i) read and understand what the function does, ii) write tests, iii) maintain the code.

The iii may not be clear right now, but if we decide to adopt other strategies for choosing the possible default value for reg or source (e.g. say we have AWS and decide to use an environment variable for the default values?) we wouldn't have to touch this function, but move the logic to the caller.

So I agree with the change, for the current design of the function 😬 but later will try to come up with alternatives (unless I'm missing something that prevents other designs).

@@ -524,8 +524,7 @@ def _event_email_callback(self, proc_ctx, schd_ctx):
else:
self.event_timers[id_key].unset_waiting()
except KeyError as exc:
if cylc.flags.debug:
LOG.exception(exc)
LOG.exception(exc)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

KeyError used to happen quite often because we were relying on the task proxy being in the pool. In the current logic, this is no longer the case - as the event handler contexts are now kept in a dict independent of their original task proxies.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So if an exception is caught, we want to log it, regardless.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the info!

@matthewrmshin
Copy link
Contributor Author

Done, I think.

@matthewrmshin matthewrmshin changed the title Improve config deprecated upgrade log Improve config deprecated upgrade log, etc Nov 13, 2018
Copy link
Member

@kinow kinow left a comment

Choose a reason for hiding this comment

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

This pull request had - besides the great work on better logging - some nice improvements for Python3 in exception handling, new comments in the code, some extra comments in GitHub's UI explaining the rationale behind the change in the pull request and some history of the code 👏

+1, LGTM, and big thanks!

lib/cylc/task_events_mgr.py Outdated Show resolved Hide resolved
@cylc cylc deleted a comment Nov 13, 2018
bin/cylc-register Outdated Show resolved Hide resolved
@@ -1023,15 +1016,11 @@ def upgrade_pickle_to_json(self):
else:
args.append(cell)
except (EOFError, TypeError, LookupError, ValueError):
n_skips += 1 # skip bad rows
pass
Copy link
Member

Choose a reason for hiding this comment

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

Cool indeed, I dislike except: pass type statements (although I guess that's probably what this is doing underneath). I've been stuck with Python 2.6 for too long, need to get up to date.

sys.exit(1)

LOG.exception(exc2)
raise exc
Copy link
Member

Choose a reason for hiding this comment

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

Indeed Cylc is a little too fond of swallowing exceptions, particularly in cylc.config.

Use DEBUG level for site files - users may not be able to fix them
easily. Use WARNING level for all other files to better alert users.

Remove more print and sys.std*.write
* Where possible, use logging instead of print or sys.std*.write.
* Remove unnecessary diagnostics and some debug flag check in favour of
  simple logging.
* Exit with error message instead of print error then exit 1.

Use 0o syntax for octal literal.
@matthewrmshin matthewrmshin force-pushed the improve-conf-deprecated-upgrade-logging branch from a0460ed to 64b4d9e Compare November 14, 2018 15:22
@oliver-sanders oliver-sanders merged commit 4f8dc47 into cylc:master Nov 14, 2018
@matthewrmshin matthewrmshin deleted the improve-conf-deprecated-upgrade-logging branch November 14, 2018 16:11
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.

3 participants