-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Backend Message and Frontend Banner for Service Maintenance (#294)
### Description - I am taking over this draft PR to implement display of service maintenance banner selectively based on environment variables - Added `health_status` endpoint on backend that reads from the env var - Frontend displays maintenance banner if health status is `maintenance` or if backend has no response coming back ### Tests - When backend is down OR when backend has environment variable `SERVICE_MAINTENANCE_BANNER=True` <img width="1152" alt="image" src="https://github.com/astronomer/ask-astro/assets/26350341/ca2fef7c-923e-43b1-b445-8003bbfe47f9"> - Other times (when env var is empty or if banner set to False) <img width="1117" alt="image" src="https://github.com/astronomer/ask-astro/assets/26350341/e4e70373-0a20-48ea-af97-b3160c5a2a6d"> - Slack <img width="454" alt="image" src="https://github.com/astronomer/ask-astro/assets/26350341/90c9874f-1e29-489b-98b0-b4b89228e098"> closes #302 --------- Co-authored-by: David Xue <xuegdxw@gmail.com>
- Loading branch information
Showing
10 changed files
with
114 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
""" | ||
Handles GET requests to the /ask/{question_id} endpoint. | ||
""" | ||
from __future__ import annotations | ||
|
||
from logging import getLogger | ||
|
||
from sanic import Request, json | ||
from sanic_ext import openapi | ||
|
||
from ask_astro import settings | ||
from ask_astro.models.request import HealthStatus | ||
|
||
logger = getLogger(__name__) | ||
|
||
|
||
@openapi.definition(response=HealthStatus.schema_json()) | ||
async def on_get_health_status(request: Request) -> json: | ||
""" | ||
Handles GET requests to the /health_status endpoint. | ||
:param request: The Sanic request object. | ||
""" | ||
if settings.SHOW_SERVICE_MAINTENANCE_BANNER: | ||
return json({"status": "maintenance"}, status=200) | ||
return json({"status": "healthy"}, status=200) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
tests/api/ask_astro/rest/controllers/test_health_status.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.asyncio | ||
@pytest.mark.parametrize( | ||
"show_maintenance_banner, expected_response", | ||
[ | ||
(True, {"status": "maintenance"}), | ||
(False, {"status": "healthy"}), | ||
], | ||
) | ||
async def test_health_status(app, show_maintenance_banner, expected_response): | ||
""" | ||
Test the /health_status endpoint by mocking banner status environment variable | ||
""" | ||
|
||
with patch("ask_astro.settings.SHOW_SERVICE_MAINTENANCE_BANNER", new=show_maintenance_banner): | ||
_, response = await app.asgi_client.get("/health_status") | ||
|
||
# Validating the response status code and content | ||
assert response.status == 200 | ||
assert response.json == expected_response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters