usnistgov / oar-pdr

The NIST Open Access to Research (OAR) Public Data Repository (PDR) system software
11 stars 10 forks source link

Python module for checking health of API endpoints #222

Closed RayPlante closed 2 years ago

RayPlante commented 2 years ago

A&A approval of the coming cache manager feature (for oar-dist-service) requires automated checking of its health via its API and sending an email when a check fails. This PR adds general support for checking the health of API endpoints to the Python library, building on its existing notification system. The addition consists of a new module, nistoar.pdr.health, and a new command-line script, pdrhealthcheck.py.

One way to check this locally is by building and running the command-line script (assuming you have Python 2.7). Within the feature/health branch, you can execute the following:

git submodule update --init
scripts/makedist.python
export PYTHONPATH=$PWD/python/dist/pdr/lib/python
python scripts/pdrhealthcheck.py -h                 # Confirm that script prints a help message
python scripts/pdrhealthcheck.py -c etc/testhealthcheck_config.yml -O proofoflife     # Prints email message to screen
python scripts/pdrhealthcheck.py -c etc/testhealthcheck_config.yml -O services

The "proofoflife" check is configured to simply check the SDP home page; regardless of success or failure, it will print to the terminal the mail message that it would normally send via mail (if the -O option was not given). The last check "services" checks three configured endpoints from data.nist.gov. It will only display a notification message if one of the endpoints does not respond or responds incorrectly; normally, it will not print anything.

It can also be tested via oar-docker; see oar-docker PR # 149.