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

Flash an alert when loqus instance is not reachable #4673

Merged
merged 16 commits into from
Jun 13, 2024
Merged

Conversation

northwestwitch
Copy link
Member

@northwestwitch northwestwitch commented Jun 12, 2024

This PR adds a functionality or fixes a bug.

Testing on cg-vm1 server (Clinical Genomics Stockholm)

Prepare for testing

  1. Make sure the PR is pushed and available on Docker Hub
  2. Fist book your testing time using the Pax software available at https://pax.scilifelab.se/. The resource you are going to call dibs on is scout-stage and the server is cg-vm1.
  3. ssh <USER.NAME>@cg-vm1.scilifelab.se
  4. sudo -iu hiseq.clinical
  5. ssh localhost
  6. (optional) Find out which scout branch is currently deployed on cg-vm1: podman ps
  7. Stop the service with current deployed branch: systemctl --user stop scout.target
  8. Start the scout service with the branch to test: systemctl --user start scout@<this_branch>
  9. Make sure the branch is deployed: systemctl --user status scout.target
  10. After testing is done, repeat procedure at https://pax.scilifelab.se/, which will release the allocated resource (scout-stage) to be used for testing by other users.
Testing on hasta server (Clinical Genomics Stockholm)

Prepare for testing

  1. ssh <USER.NAME>@hasta.scilifelab.se
  2. Book your testing time using the Pax software. us; paxa -u <user> -s hasta -r scout-stage. You can also use the WSGI Pax app available at https://pax.scilifelab.se/.
  3. (optional) Find out which scout branch is currently deployed on cg-vm1: conda activate S_scout; pip freeze | grep scout-browser
  4. Deploy the branch to test: bash /home/proj/production/servers/resources/hasta.scilifelab.se/update-tool-stage.sh -e S_scout -t scout -b <this_branch>
  5. Make sure the branch is deployed: us; scout --version
  6. After testing is done, repeat the paxa procedure, which will release the allocated resource (scout-stage) to be used for testing by other users.

How to test -- on cg-vm1:

  1. Change the settings of a scout institute to connect to a broken or not existent loqus instance
  2. Go to a variant page

How to test -- locally:

  1. Uncomment the lines in the config file relative to the loqusdb API instance
  2. Go to a variant page

Expected outcome:

  • You should see a flashed error warning

Review:

  • code approved by DNIL
  • tests executed by DNIL, CR

@dnil
Copy link
Collaborator

dnil commented Jun 12, 2024

Nice! Just ping when ready for review!

Copy link

codecov bot commented Jun 12, 2024

Codecov Report

Attention: Patch coverage is 78.57143% with 3 lines in your changes missing coverage. Please review.

Project coverage is 84.50%. Comparing base (5e7adeb) to head (2d59d03).

Files Patch % Lines
scout/server/blueprints/variant/controllers.py 60.00% 2 Missing ⚠️
scout/server/extensions/loqus_extension.py 88.88% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4673   +/-   ##
=======================================
  Coverage   84.49%   84.50%           
=======================================
  Files         310      310           
  Lines       18798    18797    -1     
=======================================
  Hits        15884    15884           
+ Misses       2914     2913    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@northwestwitch northwestwitch requested a review from dnil June 12, 2024 07:31
Copy link
Collaborator

@dnil dnil left a comment

Choose a reason for hiding this comment

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

Nice start, but doesn't quite work yet?
Screenshot 2024-06-12 at 09 44 36
default, stage-loqusdb-rd-api is very sparsely populated and returns no variant found for this variant.

scout/server/blueprints/variant/controllers.py Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
scout/server/extensions/loqus_extension.py Outdated Show resolved Hide resolved
northwestwitch and others added 3 commits June 12, 2024 10:23
Co-authored-by: Daniel Nilsson <daniel.k.nilsson@gmail.com>
@northwestwitch
Copy link
Member Author

northwestwitch commented Jun 12, 2024

Ok I got confused by the fact that loqusdb api returns 404 when a variant is not found (I was expecting 200 but {} as content) and also from scout that modifies the response from that api before parsing it 🙄

Now it should be always returning {}, regardless of if the variant is found or not. But should flash a message if there is a connection error

image

scout/server/extensions/loqus_extension.py Show resolved Hide resolved
LOG.info(search_resp.get("detail"))
if "details" not in search_resp.get("message", {}): # Connection error
flash(
f"Connection to Loqusdb instance returned error: '{search_resp['message']}'",
Copy link
Collaborator

Choose a reason for hiding this comment

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

😊 Yeah, {} will not have "message"..

@@ -78,15 +76,15 @@ def mockapi(*args):
def test_loqus_api_snv_variant_not_found(loqus_api_app, monkeypatch, loqus_api_variant):
# GIVEN a mocked loqus API that doesn't return usable info
def mockapi(*args):
return {"message": {"details": "not found"}}
Copy link
Member Author

Choose a reason for hiding this comment

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

This was wrong, because api_get returns a response body with "message" only when there is an exception but variant not found doesn't trigger an exception

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right, that is loqusdbapi insert style errors. Maybe there was an intention to change at some point. 😊
Or fails obviously, which we were after elsewhere here.

Copy link

sonarcloud bot commented Jun 12, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

return {}
return search_resp.get("content")

if search_resp.get("status_code") == 200:
Copy link
Member Author

@northwestwitch northwestwitch Jun 12, 2024

Choose a reason for hiding this comment

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

This can't trigger error any more no?

Copy link
Collaborator

@dnil dnil left a comment

Choose a reason for hiding this comment

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

Agreed, this solves the issue. I think I will make a new one for loqusdbapi to return a bit more elegantly, especially with totals as well even if the variant was not found, and we can revisit the issue. CLI loqusdb does return totals always, if asked to.

obs_data[loqus_id]["observations"] = 0

if obs_data[loqus_id] == {}: # Variant was not found
obs_data[loqus_id]["observations"] = 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, that should be it. I do think before long we should modify the loqusdbapi return so that we get a total set also for variant not found - after all we do have the variant type, and can tell how many of those cases we have - but that is not for this issue.

@@ -78,15 +76,15 @@ def mockapi(*args):
def test_loqus_api_snv_variant_not_found(loqus_api_app, monkeypatch, loqus_api_variant):
# GIVEN a mocked loqus API that doesn't return usable info
def mockapi(*args):
return {"message": {"details": "not found"}}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Right, that is loqusdbapi insert style errors. Maybe there was an intention to change at some point. 😊
Or fails obviously, which we were after elsewhere here.

@northwestwitch northwestwitch merged commit 535a38b into main Jun 13, 2024
25 checks passed
@northwestwitch northwestwitch deleted the loqus_timeout branch July 24, 2024 08:04
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.

Warnings when loqusdb-api is not reachable
3 participants