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

Fix scheduler#shutdown when reference-log option is used #3035

Merged
merged 2 commits into from
Apr 1, 2019

Conversation

kinow
Copy link
Member

@kinow kinow commented Mar 22, 2019

Not sure if it was better to modify to read binary, but we are doing line in array_of_strings... so would have to modify that array too I think. I thought this would be the simplest way to fix it.

Added a functional test (my very first!) for this case of scheduler#shutodown when --reference-log is used 👍

Not applicable to 7.8.x

Cheers
Bruno

@kinow kinow added bug Something is wrong :( small labels Mar 22, 2019
@kinow kinow added this to the cylc-8.0a1 milestone Mar 22, 2019
@kinow kinow self-assigned this Mar 22, 2019
@hjoliver
Copy link
Member

Haha, I guess we have a gazillion tests that use "reference logs" (which contain what-triggered-off-what info) but never thought to make a test that generates one 😬

@hjoliver
Copy link
Member

Adding @matthewrmshin as reviewer - he is the author of the relevant code block.

Copy link
Member

@hjoliver hjoliver left a comment

Choose a reason for hiding this comment

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

The logic in this block seems a bit odd to me:

  • open the "reference log" for writing in binary mode
  • open the main suite log file for reading in text mode
  • read the main log line by line (as strings)
  • filter for certain lines and write them to the reference log

Shouldn't we just open the reference log file in text mode??

@matthewrmshin
Copy link
Contributor

An over-the-top 2to3 change?

@hjoliver
Copy link
Member

hjoliver commented Mar 22, 2019 via email

@hjoliver
Copy link
Member

@kinow @matthewrmshin do you agree with my comment:

Shouldn't we just open the reference log file in text mode??

If so let's just do that, no? (The only reason I'm a bit hesitant is I'm not fully up to speed yet with Python 3 string encoding ... but I expect you guys are).

@matthewrmshin
Copy link
Contributor

Now that I am awake on Monday... The problem with text mode file in Python <3.7 is that it is susceptible to locale setting. The horrible LANG=C simply makes everything go haywire. The problem does appear to be fixed in 3.7 with PEP538 implemented.

@hjoliver
Copy link
Member

Does that matter in this particular context though? (even before 3.7) (we are already opening the main log in text mode...)

@matthewrmshin
Copy link
Contributor

It is probably OK in this context.

And now that I am really thinking (Monday mid morning - best thinking time)...

Instead of parsing the log, and filtering it, we should just add a custom log handler to the logger when we are in --reference-log mode - which should filter log messages and write the relevant stuffs to the reference.log file. Probably a follow-on when we revisit logging again.

@hjoliver
Copy link
Member

hjoliver commented Mar 25, 2019

Instead of parsing the log, and filtering it, we should just add a custom log handler to the logger when we are in --reference-log mode - which should filter log messages and write the relevant stuffs to the reference.log file. Probably a follow-on when we revisit logging again.

Yes I was wondering about that myself. The current method isn't very elegant, but I suppose it doesn't really matter because generating a reference log is a rare thing to do, and doesn't affect users.

Copy link
Contributor

@matthewrmshin matthewrmshin left a comment

Choose a reason for hiding this comment

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

Change is quick fix for current logic, but we agree that we may want to revisit the logic again in the future.

Copy link
Member

@hjoliver hjoliver left a comment

Choose a reason for hiding this comment

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

@kinow I would still prefer that you change this as I suggested above, to consistent use of text mode for the two log files involved here, otherwise we may be left wondering in the future if there was some real reason for using binary mode with one and text for the other. @matthewrmshin seemed to agree above that text mode is fine here (I think?).

@kinow kinow force-pushed the fix-scheduler-shutdown-reference-log branch from e9aa151 to 8fec490 Compare March 31, 2019 22:17
@kinow
Copy link
Member Author

kinow commented Mar 31, 2019

@hjoliver , I hadn't looked around the code when I first suggested the fix. After the comments here, got a cup of coffee and read what the reference log was doing, and @matthewrmshin 's comment about using a logging.Handler seemed like a good idea.

Every logging.Handler is also a logging.Filterer (i.e. extends it). So we can add filterers with #addFilter, which is pretty much what we need with the reference log... as far as I could tell. And it seemed easier than fixing the existing code for binary/text.

I tried it locally with ol' suite number five, and got similar output (only the timestamps differ, obviously). So pushed the changes here to see if Travis-CI passes all tests OK.

Only issue I actually had was that we cannot initialize the new ReferenceLogHandler with the other logging.Handler's in Scheduler#_setup_suite_logger, because _setup_suite_logger is called before the configure method. And ReferenceLogHandler depends on the configuration being loaded for the reference log output directory.

So the ReferenceLogHandler is initialized in the same part it was already checking for the option to generate reference log (i.e. it should kill 1 if statement, making Codacy a bit happier).

Hope that makes sense?

Copy link
Member

@hjoliver hjoliver left a comment

Choose a reason for hiding this comment

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

Nice, thanks @kinow

@hjoliver hjoliver merged commit 8b97d33 into cylc:master Apr 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is wrong :( small
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants