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

Add "debug mode" #190

Merged
merged 6 commits into from Mar 5, 2020
Merged

Add "debug mode" #190

merged 6 commits into from Mar 5, 2020

Conversation

CasperWA
Copy link
Member

@CasperWA CasperWA commented Feb 19, 2020

Closes #130

I have attempted to add a "debug" mode to the server.
At the moment it only toggles whether a Python traceback should be added under the toplevel meta response if an error occurs.

It is implemented so it can be activated if debug is added when running the server, e.g.:

./run.sh debug

or

./run.sh index debug

To start the regular or index server in debug mode, respectively.

The debug mode can also be run "always" by setting the environment variable DEBUG to 1, i.e. export DEBUG=1.

I've added some tests. Currently I've put them in test_config.py, but the main part of them should be moved to a future test_exception_handlers.py or even better, their own file completely.
It was more difficult than expected to make sure the debug mode was set properly for the test clients, so I needed to circumvent the "standard" setup of inheriting from SetClient, and instead use the utility functions to create the clients directly. This also means the test time has increased significantly for a very small test. This may be more justified in the future if more debug tests are added, to make sure other things are properly toggled according to the debug mode. But at the moment its a bit overkill - but it was the only way I could figure out to do the tests.

Edit: I have made CONFIG.debug togglable, i.e., one can now set it on the go - this is quite useful for the tests - but I originally wanted it not to be settable, since at no time would you change it while the server is running.

@CasperWA CasperWA requested a review from ml-evs February 19, 2020 16:22
@codecov
Copy link

codecov bot commented Feb 19, 2020

Codecov Report

Merging #190 into master will increase coverage by 0.07%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #190      +/-   ##
==========================================
+ Coverage   86.67%   86.74%   +0.07%     
==========================================
  Files          39       39              
  Lines        1853     1863      +10     
==========================================
+ Hits         1606     1616      +10     
  Misses        247      247              
Flag Coverage Δ
#unittests 86.74% <100.00%> (+0.07%) ⬆️

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 24637f2...34dad03. Read the comment docs.

@CasperWA CasperWA force-pushed the close_130_add_debug_flag branch 3 times, most recently from 7f93d1d to 666afe9 Compare March 5, 2020 11:53
Copy link
Member

@ml-evs ml-evs left a comment

Choose a reason for hiding this comment

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

Tested this locally and it works well, thanks @CasperWA.

Just a couple of comments.

tests/server/test_config.py Outdated Show resolved Hide resolved
run.sh Show resolved Hide resolved
@CasperWA CasperWA requested a review from ml-evs March 5, 2020 15:07
CasperWA and others added 6 commits March 5, 2020 16:19
Traceback is only shown in the top-level meta response if in debug mode.
Also, use the log-level debug for uvicorn if in debug mode.

Co-Authored-By: Matthew Evans <me388@cam.ac.uk>
Copy link
Member

@ml-evs ml-evs left a comment

Choose a reason for hiding this comment

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

Useful changes, thanks again @CasperWA!

@CasperWA CasperWA merged commit dfa42e1 into master Mar 5, 2020
@CasperWA CasperWA deleted the close_130_add_debug_flag branch March 5, 2020 15:34
@CasperWA CasperWA mentioned this pull request Mar 5, 2020
CasperWA added a commit that referenced this pull request Mar 6, 2020
Up to v0.6.0.

**New features**:
- GitHub Action validator that runs `optimade_validator` for a locally running OPTiMaDe server (#191, @CasperWA, tested by @ml-evs)
- Support filter queries for `HAS ALL`, `HAS ANY` and `HAS ONLY` and value lists on MongoDB backends (#173, @ml-evs)
  Note: `OPERATOR` use in value lists are still _not_ supported.
- Debug mode. Start the server in debug mode to enable `debug` log-level in `uvicorn` and get a full Python traceback in the JSON response (#190, @CasperWA)
- Add testing of mandatory `filter` queries to `optimade_validator` (#205, @ml-evs)

**Updates**:
- Allow Cross-Origin requests from anywhere (`*`), i.e., enable CORS for both servers (#194, @CasperWA)
- Updates to models (correct misspelling, more transparent model class naming, streamline models with respect to python class inheritance, update field descriptions) (#195, @CasperWA)
- API change: Rename `optimade.models.toplevel.py` to `optimade.models.responses.py` (#195, @CasperWA)
- Update dependencies to newest versions (as of 02.03.2020) (#202, #196, @CasperWA)
- Move imports from `starlette` to `fastapi`, where possible (#202, @ml-evs)
- Remove custom middleware to redirect slashed URLs in favor of `starlette` implementation (#202, @ml-evs)
- CI tests are now performed with a real MongoDB in the backend. CI tests are also performed with a `mongomock` backend for the tests in `server/test_middleware.py`, `server/test_server_validation.py`, and `server/test_config.py` (#196, @ml-evs, additional testing by @CasperWA )
- Remove `/optimade` from base URLs. This was especially important for the OpenAPI schema (#201, #216, @CasperWA, @ml-evs)
- Check integrity of query part of the raw URL using a custom middleware (#209, @CasperWA)
- New `optimade/server/exceptions.py` to contain custom `HttpException`s, moved `BadRequest` here (#209, @CasperWA)
- Pattern and regex testing for `data.available_api_versions` parts in `/info` endpoint and fix tests for the same (#211, @CasperWA)
- Restructure import of test data for regular server (#212, @shyamd)

**Bug fixes**:
- New retrieval URL for Materials-Consortia's list of providers (#187, @CasperWA)
- Skip local `HAS ONLY` tests with a `mongomock` backend, since v3.19.0 does not support these (#206, @ml-evs)
- Resource ID's can now contain slashes (`/`) (#183, @ml-evs, @CasperWA)
- Remove _valid_ version part of base URL in `meta.query.representation` (#201, @CasperWA)
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.

Add debug flag to server
2 participants