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 circular dep and extra permission error in logs #436

Merged
merged 8 commits into from Aug 3, 2020
Merged

Conversation

ml-evs
Copy link
Member

@ml-evs ml-evs commented Jul 31, 2020

Closes #435.

Reworks error handling of config and logging set up.

@ml-evs ml-evs added bug Something isn't working priority/medium Issue or PR with a consensus of medium priority server Issues pertaining to the example server implementation labels Jul 31, 2020
@ml-evs ml-evs requested a review from CasperWA July 31, 2020 16:02
@codecov
Copy link

codecov bot commented Jul 31, 2020

Codecov Report

Merging #436 into master will decrease coverage by 0.34%.
The diff coverage is 67.74%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #436      +/-   ##
==========================================
- Coverage   91.60%   91.25%   -0.35%     
==========================================
  Files          60       60              
  Lines        2800     2814      +14     
==========================================
+ Hits         2565     2568       +3     
- Misses        235      246      +11     
Flag Coverage Δ
#unittests 91.25% <67.74%> (-0.35%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
optimade/server/logger.py 68.75% <33.33%> (-7.92%) ⬇️
optimade/server/config.py 88.05% <57.14%> (-8.96%) ⬇️
optimade/server/main.py 94.73% <85.71%> (-1.35%) ⬇️
optimade/server/main_index.py 94.73% <85.71%> (-1.35%) ⬇️

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 c911e75...77c059b. Read the comment docs.

Copy link
Member

@CasperWA CasperWA left a comment

Choose a reason for hiding this comment

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

Great trick, thanks @ml-evs!

If this works with the tests, then there is indeed no need to have the extra validator for log_level.

A minor comment, since I am confused about this.

optimade/server/logger.py Show resolved Hide resolved
@ml-evs
Copy link
Member Author

ml-evs commented Jul 31, 2020

Great trick, thanks @ml-evs!

If this works with the tests, then there is indeed no need to have the extra validator for log_level.

A minor comment, since I am confused about this.

My only worry is that logging.get_logger("optimade") might get called before the logger is actually set up, so the default config errors go to the wrong place? Not sure it's that a big of a deal in that case though

@CasperWA
Copy link
Member

Great trick, thanks @ml-evs!
If this works with the tests, then there is indeed no need to have the extra validator for log_level.
A minor comment, since I am confused about this.

My only worry is that logging.get_logger("optimade") might get called before the logger is actually set up, so the default config errors go to the wrong place? Not sure it's that a big of a deal in that case though

You should be able to see this if you start the server via ./run.sh debug.
If you don't see a nicely formatted DEBUG: Found config file at ... or something like that, then it's not initializing the logger prior to this.

@CasperWA
Copy link
Member

Great trick, thanks @ml-evs!
If this works with the tests, then there is indeed no need to have the extra validator for log_level.
A minor comment, since I am confused about this.

My only worry is that logging.get_logger("optimade") might get called before the logger is actually set up, so the default config errors go to the wrong place? Not sure it's that a big of a deal in that case though

You should be able to see this if you start the server via ./run.sh debug.
If you don't see a nicely formatted DEBUG: Found config file at ... or something like that, then it's not initializing the logger prior to this.

I just checked this. And it seems that the logger is indeed not initialized.

We could instead completely remove the log statements from config.py? It would be nice to have it logged what config file is used though. But maybe we could move that to the main*.py files? I don't know... Or perhaps just the logger.py file?

optimade/server/config.py Outdated Show resolved Hide resolved
@ml-evs
Copy link
Member Author

ml-evs commented Aug 1, 2020

Just tweaked this some more with (hopefully) improved error handling. Only thing I can't get is for a RuntimeError to crash the server if the config is borked.

@ml-evs
Copy link
Member Author

ml-evs commented Aug 1, 2020

To summarise new behaviour (might not be what we actually want):

  1. If OPTIMADE_CONFIG_FILE is set, then try to crash if the file isn't found (as it stands, uvicorn keeps hanging on).
  2. If OPTIMADE_CONFIG_FILE is unset and ~/.optimade.json doesn't exist, emit a warning that the defaults are being used.

@CasperWA
Copy link
Member

CasperWA commented Aug 2, 2020

To summarise new behaviour (might not be what we actually want):

  1. If OPTIMADE_CONFIG_FILE is set, then try to crash if the file isn't found (as it stands, uvicorn keeps hanging on).

Yeah, I think as with the logging to files, this should just produce a very visible warning (through logging) and then use the default values.

  1. If OPTIMADE_CONFIG_FILE is unset and ~/.optimade.json doesn't exist, emit a warning that the defaults are being used.

Yir.

Wait, was the first point the one we now cannot do due to the circular import?

optimade/server/config.py Outdated Show resolved Hide resolved
optimade/server/config.py Outdated Show resolved Hide resolved
optimade/server/config.py Outdated Show resolved Hide resolved
optimade/server/config.py Outdated Show resolved Hide resolved
optimade/server/logger.py Outdated Show resolved Hide resolved
ml-evs and others added 5 commits August 3, 2020 11:34
- Raise RuntimeError of a specific config file was requested, but not found
- Emit warning if the config file was not found in the default location
  without a custom location provided
Co-authored-by: Casper Welzel Andersen <43357585+CasperWA@users.noreply.github.com>
@ml-evs
Copy link
Member Author

ml-evs commented Aug 3, 2020

It's a little bit verbose now, but I think this is a sensible set up. Config emits warnings that are caught (and then reset) by the server and written to the main log. Any config load failures only warn and don't cause a crash, but clearly print that defaults are being used instead.

I also moved all the CONFIG importing code to the top of the server code, as it was actually being imported for the first time inside exception_handling somewhere.

@ml-evs ml-evs requested a review from CasperWA August 3, 2020 12:04
CasperWA
CasperWA previously approved these changes Aug 3, 2020
Copy link
Member

@CasperWA CasperWA left a comment

Choose a reason for hiding this comment

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

Quite verbose now, yes. But in this case, I think it really makes sense.

This is great work @ml-evs ! Chanks.

I have approved with a single comment. I may have missed something, so it might indeed be important to keep that line in. If not, just ping me and I'll quickly re-approve 👍

optimade/server/config.py Outdated Show resolved Hide resolved
Co-authored-by: Casper Welzel Andersen <43357585+CasperWA@users.noreply.github.com>
@ml-evs ml-evs merged commit cada2a4 into master Aug 3, 2020
@CasperWA CasperWA deleted the ml-evs/fix_logs branch August 3, 2020 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority/medium Issue or PR with a consensus of medium priority server Issues pertaining to the example server implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

log_dir option in config is unused
2 participants