This script checks the uptime of a set of HTTP endpoints defined in a YAML config file. It checks the availability of endpoints every 15 seconds and logs the results by domain.
-
Clone the repository:
git clone https://github.com/Pilas01/sre-take-home-exercise-python.git cd sre-take-home-exercise-python
-
Create and activate a virtual environment (optional but recommended):
python -m venv venv source venv/Scripts/activate # Use `venv/bin/activate` on Mac/Linux
-
Install dependencies:
pip install -r requirements.txt
-
Create a
config.yaml
file with your endpoints:- name: Google url: https://www.google.com - name: Example url: https://example.com
-
Run the script:
python healthcheck.py config.yaml
-
Issue 1: The script didn’t read from a YAML file.
- Fix: I added support for reading a
config.yaml
file usingargparse
andPyYAML
.
- Fix: I added support for reading a
-
Issue 2: No way to customize the HTTP request (e.g., method, headers).
- Fix: Now, the script supports optional
method
,headers
, andbody
fields in the YAML file.
- Fix: Now, the script supports optional
-
Issue 3: No validation for status code and response time.
- Fix: The script now checks if the status code is between
200-299
and the response time is under500ms
.
- Fix: The script now checks if the status code is between
-
Issue 4: The script didn’t group results by domain.
- Fix: I used
urlparse()
to extract domains from the URLs and grouped results accordingly.
- Fix: I used
-
Issue 5: Availability percentage included decimals.
- Fix: Per Fetch Rewards’ requirement, I made the script drop the decimal part by casting the percentage to
int()
.
- Fix: Per Fetch Rewards’ requirement, I made the script drop the decimal part by casting the percentage to
When running the script, it will log availability percentages every 15 seconds like this:
2025-04-22 17:50:19,378 - www.google.com: 100% availability 2025-04-22 17:50:19,379 - example.com: 100% availability