Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

API health check #311

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open

API health check #311

wants to merge 2 commits into from

Conversation

d-rita
Copy link
Contributor

@d-rita d-rita commented Aug 30, 2022

What does this PR do?
This PR adds an endpoint /health/ to check if the following endpoints are working as expected, i.e. authentication, mapathon summary, mapathon detail, and raw data.

How to test:

  • Run git fetch origin && git checkout feature/health-check to pull the branch.
  • Connect to all data sources: underpass, insights, TM, raw data.
  • To your config.txt, under the [API_MONITORING] header, add these:
    1. MAIN_API_URL=http://127.0.0.1:8000/v1
    2. ACCESS_TOKEN=''
      NB: The access token is generated using valid credentials of an OSM account. Follow these steps on how to generate a valid token to test authenticated routes in Galaxy.
  • Start server: uvicorn API.main:app --reload
  • Go to the health endpoint via docs to test the endpoint.
  • The expected response, if all the endpoints are working as expected, is:
    {
        "authentication": "healthy",
        "mapathonSummary": "healthy",
        "mapathonDetail": "healthy",
        "rawData": "healthy"
     }

Issues:

@d-rita d-rita requested a review from eternaltyro September 14, 2022 10:30
@d-rita d-rita force-pushed the feature/health-check branch 2 times, most recently from 0ed8991 to 13d7d60 Compare September 19, 2022 10:10
@d-rita d-rita marked this pull request as ready for review September 19, 2022 10:13
- Add API monitoring config variables; API URL and access token
- Monitor authentication, raw data and mapathon endpoints
- Add system health validation models
@d-rita d-rita force-pushed the feature/health-check branch from 13d7d60 to e69ce11 Compare September 26, 2022 17:02
get_req = requests.get(endpoint)
return get_req.status_code
if request_type == 'POST':
post_req = requests.post(endpoint, json=body, headers={'access-token':ACCESS_TOKEN})
Copy link
Member

Choose a reason for hiding this comment

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

Just a question , I can see from the website that access_token is not going to expire but have you tried it ? Do they remain same all the time ? Since you are reading it from config , I am just concerned if they will expire or not . Generally access token do expire

@@ -83,6 +83,9 @@
"value not supported for file_upload_method ,switching to default disk method")
use_s3_to_upload = False

MAIN_API_URL = config.get("API_MONITORING", "MAIN_API_URL", fallback="http://127.0.0.1:8000/v1/")
ACCESS_TOKEN = config.get("API_MONITORING", "ACCESS_TOKEN", fallback=None)
Copy link
Member

Choose a reason for hiding this comment

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

May be checking and raising the error if access_token is not supplied would be fruitful since the monitoring depends on it , API should be able to run without those configuration , you can check if it is supplied or not when endpoint is called !

@@ -0,0 +1,36 @@
raw_data_testing_query = {
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 moving these to /src/tests/fixtures will be fruitful

@@ -49,6 +49,10 @@ env=dev
#env=dev # default is prod , supported values are dev and prod
#shp_limit=6000 # in mb default is 4096

#[API_MONITORING]
#MAIN_API_URL=http://127.0.0.1:8000/v1/
Copy link
Member

Choose a reason for hiding this comment

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

Renaming to API URL ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Health check for API
2 participants