-
Notifications
You must be signed in to change notification settings - Fork 1.7k
ENG-9279: Add status to reflex.dev footer #6351
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b92356a
ENG-9279: Add status to reflex.dev footer
carlosabadia 493aa5a
update tests
carlosabadia 466a32d
thanks greptile
carlosabadia abe7b82
update
carlosabadia 72da4db
change those
carlosabadia f2b2214
Merge branch 'main' of https://github.com/reflex-dev/reflex into carl…
carlosabadia a25badf
revert that
carlosabadia 18e4591
remove this
carlosabadia 91a46eb
revert uv lock
carlosabadia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
111 changes: 111 additions & 0 deletions
111
packages/reflex-site-shared/src/reflex_site_shared/backend/status.py
This file contains hidden or 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,111 @@ | ||
| """Checkly-backed service status state and polling utilities.""" | ||
|
|
||
| import asyncio | ||
| import contextlib | ||
| from enum import StrEnum | ||
|
|
||
| import httpx | ||
|
|
||
| import reflex as rx | ||
| from reflex_site_shared.constants import ( | ||
| CHECKLY_ACCOUNT_ID, | ||
| CHECKLY_API_BASE_URL, | ||
| CHECKLY_API_KEY, | ||
| CHECKLY_CHECK_GROUP_ID, | ||
| ) | ||
|
|
||
|
|
||
| class ServiceStatus(StrEnum): | ||
| """Supported service health states exposed in the UI.""" | ||
|
|
||
| SUCCESS = "Success" | ||
| WARNING = "Warning" | ||
| CRITICAL = "Critical" | ||
|
|
||
|
|
||
| CURRENT_STATUS = ServiceStatus.SUCCESS.value | ||
|
|
||
|
|
||
| # Check status of each check in parallel | ||
| async def check_status(check_id: str) -> dict: | ||
| """Fetch status flags for a single Checkly check. | ||
|
|
||
| Returns: | ||
| A dictionary with failure and degraded flags. | ||
| """ | ||
| status_url = f"{CHECKLY_API_BASE_URL}/check-statuses/{check_id}" | ||
| async with httpx.AsyncClient() as client: | ||
| status_response = await client.get( | ||
| status_url, | ||
| headers={ | ||
| "Authorization": f"Bearer {CHECKLY_API_KEY}", | ||
| "X-Checkly-Account": CHECKLY_ACCOUNT_ID, | ||
| }, | ||
| ) | ||
| if status_response.status_code == 200: | ||
| status_data = status_response.json() | ||
| return { | ||
| "has_failures": status_data.get("hasFailures", False), | ||
| "is_degraded": status_data.get("isDegraded", False), | ||
| } | ||
|
|
||
| return {"has_failures": False, "is_degraded": False} | ||
|
|
||
|
|
||
| async def monitor_checkly_status() -> None: | ||
| """Continuously monitor Checkly check group status. | ||
|
|
||
| Updates the global STATUS variable every 60 seconds. | ||
| - Critical: if any check has failures | ||
| - Warning: if no failures but some checks are degraded | ||
| - Success: all checks are healthy | ||
|
|
||
| """ | ||
| if not all((CHECKLY_API_KEY, CHECKLY_ACCOUNT_ID, CHECKLY_CHECK_GROUP_ID)): | ||
| return | ||
|
|
||
| headers = { | ||
| "Authorization": f"Bearer {CHECKLY_API_KEY}", | ||
| "X-Checkly-Account": CHECKLY_ACCOUNT_ID, | ||
| } | ||
|
|
||
| try: | ||
| while True: | ||
| with contextlib.suppress(Exception): | ||
| global CURRENT_STATUS | ||
|
|
||
| # Get checks in this group | ||
| checks_url = f"{CHECKLY_API_BASE_URL}/check-groups/{CHECKLY_CHECK_GROUP_ID}/checks" | ||
| async with httpx.AsyncClient(timeout=httpx.Timeout(30)) as client: | ||
| checks_response = await client.get(checks_url, headers=headers) | ||
| if checks_response.status_code == 200: | ||
| checks = checks_response.json() | ||
|
|
||
| check_ids = [check.get("id") for check in checks if check.get("id")] | ||
| results = await asyncio.gather(*[ | ||
| check_status(check_id) for check_id in check_ids | ||
| ]) | ||
|
|
||
| # Determine overall status | ||
| has_any_failures = any(r["has_failures"] for r in results) | ||
| has_any_degraded = any(r["is_degraded"] for r in results) | ||
|
|
||
| if has_any_failures: | ||
| CURRENT_STATUS = ServiceStatus.CRITICAL.value | ||
| elif has_any_degraded: | ||
| CURRENT_STATUS = ServiceStatus.WARNING.value | ||
| else: | ||
| CURRENT_STATUS = ServiceStatus.SUCCESS.value | ||
|
|
||
| await asyncio.sleep(60) | ||
| except asyncio.CancelledError: | ||
| pass | ||
|
carlosabadia marked this conversation as resolved.
|
||
|
|
||
|
|
||
| class StatusState(rx.State): | ||
| """Reflex state that exposes the current service status.""" | ||
|
|
||
| @rx.var(interval=60) | ||
| def status(self) -> str: | ||
| """Return the current status value for the status pill.""" | ||
| return CURRENT_STATUS | ||
This file contains hidden or 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
88 changes: 88 additions & 0 deletions
88
packages/reflex-site-shared/src/reflex_site_shared/components/server_status.py
This file contains hidden or 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,88 @@ | ||
| """Server status badge component used in site footers.""" | ||
|
|
||
| from typing import Literal | ||
|
|
||
| import reflex as rx | ||
| from reflex_site_shared.components.icons import get_icon | ||
| from reflex_site_shared.constants import STATUS_WEB_URL | ||
|
|
||
| StatusVariant = Literal["Success", "Warning", "Critical"] | ||
|
|
||
| DEFAULT_CLASS_NAME = "inline-flex flex-row gap-1.5 items-center font-medium text-sm px-2.5 rounded-[10px] h-9 hover:bg-secondary-3 transition-bg" | ||
|
|
||
| STATUS_TEXT_COLORS: dict[StatusVariant, str] = { | ||
| "Success": "text-success-9", | ||
| "Warning": "text-warning-11", | ||
| "Critical": "text-destructive-10", | ||
| } | ||
|
|
||
|
|
||
| STATUS_VARIANT_TEXT: dict[StatusVariant, str] = { | ||
| "Success": "All servers are operational", | ||
| "Warning": "Some servers are unavailable", | ||
| "Critical": "All servers are down", | ||
| } | ||
|
|
||
| STATUS_ICON_COLORS: dict[StatusVariant, str] = { | ||
| "Success": "!text-success-8", | ||
| "Warning": "!text-warning-8", | ||
| "Critical": "!text-destructive-9", | ||
| } | ||
|
|
||
|
|
||
| def _status_icon(color: str) -> rx.Component: | ||
| """Create a fresh status icon component for each render branch. | ||
|
|
||
| Returns: | ||
| A new circle icon component with the given color class. | ||
| """ | ||
| return get_icon("circle", class_name=color) | ||
|
|
||
|
|
||
| def server_status(status: StatusVariant | rx.Var[str]) -> rx.Component: | ||
| """Create a server status component. | ||
|
|
||
| Args: | ||
| status: The status of the server. | ||
|
|
||
| Returns: | ||
| A linked status badge that points to the public status page. | ||
|
|
||
| """ | ||
| return rx.el.a( | ||
| rx.match( | ||
| status, | ||
| ( | ||
| "Success", | ||
| rx.el.div( | ||
| _status_icon(STATUS_ICON_COLORS["Success"]), | ||
| STATUS_VARIANT_TEXT["Success"], | ||
| class_name=f"{DEFAULT_CLASS_NAME} {STATUS_TEXT_COLORS['Success']}", | ||
| ), | ||
| ), | ||
| ( | ||
| "Warning", | ||
| rx.el.div( | ||
| _status_icon(STATUS_ICON_COLORS["Warning"]), | ||
| STATUS_VARIANT_TEXT["Warning"], | ||
| class_name=f"{DEFAULT_CLASS_NAME} {STATUS_TEXT_COLORS['Warning']}", | ||
| ), | ||
| ), | ||
| ( | ||
| "Critical", | ||
| rx.el.div( | ||
| _status_icon(STATUS_ICON_COLORS["Critical"]), | ||
| STATUS_VARIANT_TEXT["Critical"], | ||
| class_name=f"{DEFAULT_CLASS_NAME} {STATUS_TEXT_COLORS['Critical']}", | ||
| ), | ||
| ), | ||
| rx.el.div( | ||
| _status_icon(STATUS_ICON_COLORS["Success"]), | ||
| STATUS_VARIANT_TEXT["Success"], | ||
| class_name=f"{DEFAULT_CLASS_NAME} {STATUS_TEXT_COLORS['Success']}", | ||
| ), | ||
| ), | ||
| href=STATUS_WEB_URL, | ||
| target="_blank", | ||
| rel="noopener noreferrer", | ||
| ) |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.