-
Notifications
You must be signed in to change notification settings - Fork 4
task: set status betterstack page conditionally for staging and production #434
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,10 @@ | |
| REDIRECT_URI_TEST, | ||
| REDIRECT_URI_STAGING, | ||
| REDIRECT_URI_PRODUCTION, | ||
| STATUS_PAGE_URL_DEV, | ||
| STATUS_PAGE_URL_TEST, | ||
| STATUS_PAGE_URL_STAGING, | ||
| STATUS_PAGE_URL_PRODUCTION, | ||
| TOKEN_URL_DEV, | ||
| TOKEN_URL_TEST, | ||
| TOKEN_URL_STAGING, | ||
|
|
@@ -205,6 +209,9 @@ def profile_edit_url(self) -> str: | |
| str, BeforeValidator(_validate_url), Field(description="JWS key set URL for token verification") | ||
| ] | ||
| client_id_interactive: Annotated[str, Field(description="OAuth client ID for interactive flows")] | ||
| status_page_url: Annotated[ | ||
| str | None, Field(description="Status page URL for monitoring platform health", default=None) | ||
| ] = None | ||
|
|
||
| @computed_field # type: ignore[prop-decorator] | ||
| @property | ||
|
|
@@ -510,6 +517,20 @@ def pre_init(cls, values: dict) -> dict: # type: ignore[type-arg] # noqa: N805 | |
| # See https://github.com/pydantic/pydantic/issues/9789 | ||
| api_root = values.get("api_root", API_ROOT_PRODUCTION) | ||
|
|
||
| # Set status_page_url based on environment (independent of auth fields) | ||
| if "status_page_url" not in values: | ||
| match api_root: | ||
| case x if x == API_ROOT_DEV: | ||
| values["status_page_url"] = STATUS_PAGE_URL_DEV | ||
| case x if x == API_ROOT_TEST: | ||
| values["status_page_url"] = STATUS_PAGE_URL_TEST | ||
| case x if x == API_ROOT_STAGING: | ||
| values["status_page_url"] = STATUS_PAGE_URL_STAGING | ||
| case x if x == API_ROOT_PRODUCTION: | ||
| values["status_page_url"] = STATUS_PAGE_URL_PRODUCTION | ||
| case _: | ||
| values["status_page_url"] = None | ||
|
Comment on lines
+520
to
+532
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not put this into the existing |
||
|
|
||
| # Check if all required auth fields are already provided | ||
| auth_fields = [ | ||
| "audience", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """Tests for GUI module.""" |
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we decide to move the status page URL resolution to the existing |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| """Tests for GUI frame module.""" | ||
|
|
||
| import pytest | ||
|
|
||
| from aignostics.platform import ( | ||
| API_ROOT_DEV, | ||
| API_ROOT_PRODUCTION, | ||
| API_ROOT_STAGING, | ||
| API_ROOT_TEST, | ||
| STATUS_PAGE_URL_DEV, | ||
| STATUS_PAGE_URL_PRODUCTION, | ||
| STATUS_PAGE_URL_STAGING, | ||
| STATUS_PAGE_URL_TEST, | ||
| Settings, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.unit | ||
| def test_status_page_url_production(record_property) -> None: | ||
| """Test that production environment has correct status page URL in settings. | ||
|
|
||
| Args: | ||
| record_property: pytest record_property fixture | ||
| """ | ||
| record_property("tested-item-id", "SPEC-PLATFORM-SETTINGS") | ||
| settings = Settings(api_root=API_ROOT_PRODUCTION) | ||
| assert settings.status_page_url == STATUS_PAGE_URL_PRODUCTION | ||
| assert settings.status_page_url == "https://status.platform.aignostics.com" | ||
|
|
||
|
|
||
| @pytest.mark.unit | ||
| def test_status_page_url_staging(record_property) -> None: | ||
| """Test that staging environment has correct status page URL in settings. | ||
|
|
||
| Args: | ||
| record_property: pytest record_property fixture | ||
| """ | ||
| record_property("tested-item-id", "SPEC-PLATFORM-SETTINGS") | ||
| settings = Settings(api_root=API_ROOT_STAGING) | ||
| assert settings.status_page_url == STATUS_PAGE_URL_STAGING | ||
| assert settings.status_page_url == "https://status.platform-staging.aignostics.com" | ||
|
|
||
|
|
||
| @pytest.mark.unit | ||
| def test_status_page_url_dev(record_property) -> None: | ||
| """Test that dev environment has no status page URL in settings. | ||
|
|
||
| Args: | ||
| record_property: pytest record_property fixture | ||
| """ | ||
| record_property("tested-item-id", "SPEC-PLATFORM-SETTINGS") | ||
| settings = Settings(api_root=API_ROOT_DEV) | ||
| assert settings.status_page_url == STATUS_PAGE_URL_DEV | ||
| assert settings.status_page_url is None | ||
|
|
||
|
|
||
| @pytest.mark.unit | ||
| def test_status_page_url_test(record_property) -> None: | ||
| """Test that test environment has no status page URL in settings. | ||
|
|
||
| Args: | ||
| record_property: pytest record_property fixture | ||
| """ | ||
| record_property("tested-item-id", "SPEC-PLATFORM-SETTINGS") | ||
| settings = Settings(api_root=API_ROOT_TEST) | ||
| assert settings.status_page_url == STATUS_PAGE_URL_TEST | ||
| assert settings.status_page_url is None | ||
|
|
||
|
|
||
| @pytest.mark.unit | ||
| def test_status_page_url_configurable(record_property, monkeypatch) -> None: | ||
| """Test that status page URL can be explicitly configured via settings. | ||
|
|
||
| Args: | ||
| record_property: pytest record_property fixture | ||
| monkeypatch: pytest monkeypatch fixture | ||
| """ | ||
| record_property("tested-item-id", "SPEC-PLATFORM-SETTINGS") | ||
| # Test that we can override the status page URL | ||
| custom_url = "https://custom-status.example.com" | ||
| monkeypatch.setenv("AIGNOSTICS_STATUS_PAGE_URL", custom_url) | ||
| settings = Settings(api_root=API_ROOT_PRODUCTION) | ||
| assert settings.status_page_url == custom_url | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ui.run_javascriptunconditionally dereferencesdocument.getElementById('betterstack')whenapi_rootis prod/staging. On initial page load (or during navigation) the timer callback can run before the iframe is in the DOM, which will cause a JS error (null.src). Consider guarding in the JS itself (check element exists) so the refresh is safe regardless of render timing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure whether this is an actual problem or not. Are you able to start the Launchpad against all environments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@olivermeyer yes, it looks correct against the branch - no Betterstack status page icon for dev and test, different links for staging and prod.