From 3e5f3ec948cb7ae2930892f51263d577a5ecb293 Mon Sep 17 00:00:00 2001 From: Michael Matloka Date: Fri, 3 Jan 2025 13:04:18 +0100 Subject: [PATCH] chore(dev): Warn about port 8010 vs. 8000 in debug notice (#27108) --- ee/api/test/test_authentication.py | 4 +- ee/api/test/test_billing.py | 4 +- ee/billing/test/test_quota_limiting.py | 4 +- .../subscriptions/test_slack_subscriptions.py | 10 ++-- .../navigation-3000/components/Navbar.tsx | 2 +- frontend/src/lib/components/DebugNotice.tsx | 54 +++++++++++++------ .../scenes/PreflightCheck/preflightLogic.tsx | 12 ++++- posthog/api/test/test_insight.py | 2 +- posthog/api/test/test_preflight.py | 4 +- posthog/api/test/test_uploaded_media.py | 2 +- posthog/api/test/test_user.py | 12 ++--- posthog/models/test/test_integration_model.py | 4 +- posthog/models/test/test_user_model.py | 4 +- posthog/settings/__init__.py | 2 +- posthog/settings/access.py | 7 ++- posthog/tasks/test/test_periodic_digest.py | 4 +- posthog/tasks/test/test_plugin_server.py | 2 +- posthog/tasks/test/test_usage_report.py | 6 +-- 18 files changed, 90 insertions(+), 49 deletions(-) diff --git a/ee/api/test/test_authentication.py b/ee/api/test/test_authentication.py index 4f8a3adb5afd1..d102b7257cd8c 100644 --- a/ee/api/test/test_authentication.py +++ b/ee/api/test/test_authentication.py @@ -25,8 +25,10 @@ "SOCIAL_AUTH_SAML_SECURITY_CONFIG": { "wantAttributeStatement": False, # already present in settings "allowSingleLabelDomains": True, # to allow `http://testserver` in tests - } + }, + "SITE_URL": "http://localhost:8000", # http://localhost:8010 is now the default, but fixtures use 8000 } +SAML_MOCK_SETTINGS["SOCIAL_AUTH_SAML_SP_ENTITY_ID"] = SAML_MOCK_SETTINGS["SITE_URL"] GOOGLE_MOCK_SETTINGS = { "SOCIAL_AUTH_GOOGLE_OAUTH2_KEY": "google_key", diff --git a/ee/api/test/test_billing.py b/ee/api/test/test_billing.py index d2afa2bc46569..4fad1b6d8941f 100644 --- a/ee/api/test/test_billing.py +++ b/ee/api/test/test_billing.py @@ -360,7 +360,7 @@ def mock_implementation(url: str, headers: Any = None, params: Any = None) -> Ma "available_product_features": [], "custom_limits_usd": {}, "has_active_subscription": True, - "stripe_portal_url": "http://localhost:8000/api/billing/portal", + "stripe_portal_url": "http://localhost:8010/api/billing/portal", "current_total_amount_usd": "100.00", "deactivated": False, "products": [ @@ -563,7 +563,7 @@ def mock_implementation(url: str, headers: Any = None, params: Any = None) -> Ma "free_trial_until": None, "current_total_amount_usd": "0.00", "deactivated": False, - "stripe_portal_url": "http://localhost:8000/api/billing/portal", + "stripe_portal_url": "http://localhost:8010/api/billing/portal", } @patch("ee.api.billing.requests.get") diff --git a/ee/billing/test/test_quota_limiting.py b/ee/billing/test/test_quota_limiting.py index 04357830f8063..3b533f1b4c0e3 100644 --- a/ee/billing/test/test_quota_limiting.py +++ b/ee/billing/test/test_quota_limiting.py @@ -78,7 +78,7 @@ def test_quota_limiting_feature_flag_enabled(self, patch_feature_enabled, patch_ org_id, "quota limiting suspended", properties={"current_usage": 109}, - groups={"instance": "http://localhost:8000", "organization": org_id}, + groups={"instance": "http://localhost:8010", "organization": org_id}, ) # Feature flag is enabled so they won't be limited. assert quota_limited_orgs["events"] == {} @@ -223,7 +223,7 @@ def test_billing_rate_limit(self, patch_capture) -> None: "quota_limited_recordings": 1612137599, "quota_limited_rows_synced": None, }, - groups={"instance": "http://localhost:8000", "organization": org_id}, + groups={"instance": "http://localhost:8010", "organization": org_id}, ) assert self.redis_client.zrange(f"@posthog/quota-limits/events", 0, -1) == [ diff --git a/ee/tasks/test/subscriptions/test_slack_subscriptions.py b/ee/tasks/test/subscriptions/test_slack_subscriptions.py index 758f74cd3b2d1..b340843549298 100644 --- a/ee/tasks/test/subscriptions/test_slack_subscriptions.py +++ b/ee/tasks/test/subscriptions/test_slack_subscriptions.py @@ -68,12 +68,12 @@ def test_subscription_delivery(self, MockSlackIntegration: MagicMock) -> None: { "type": "button", "text": {"type": "plain_text", "text": "View in PostHog"}, - "url": "http://localhost:8000/insights/123456?utm_source=posthog&utm_campaign=subscription_report&utm_medium=slack", + "url": "http://localhost:8010/insights/123456?utm_source=posthog&utm_campaign=subscription_report&utm_medium=slack", }, { "type": "button", "text": {"type": "plain_text", "text": "Manage Subscription"}, - "url": f"http://localhost:8000/insights/123456/subscriptions/{self.subscription.id}?utm_source=posthog&utm_campaign=subscription_report&utm_medium=slack", + "url": f"http://localhost:8010/insights/123456/subscriptions/{self.subscription.id}?utm_source=posthog&utm_campaign=subscription_report&utm_medium=slack", }, ], }, @@ -141,12 +141,12 @@ def test_subscription_dashboard_delivery(self, MockSlackIntegration: MagicMock) { "type": "button", "text": {"type": "plain_text", "text": "View in PostHog"}, - "url": f"http://localhost:8000/dashboard/{self.dashboard.id}?utm_source=posthog&utm_campaign=subscription_report&utm_medium=slack", + "url": f"http://localhost:8010/dashboard/{self.dashboard.id}?utm_source=posthog&utm_campaign=subscription_report&utm_medium=slack", }, { "type": "button", "text": {"type": "plain_text", "text": "Manage Subscription"}, - "url": f"http://localhost:8000/dashboard/{self.dashboard.id}/subscriptions/{self.subscription.id}?utm_source=posthog&utm_campaign=subscription_report&utm_medium=slack", + "url": f"http://localhost:8010/dashboard/{self.dashboard.id}/subscriptions/{self.subscription.id}?utm_source=posthog&utm_campaign=subscription_report&utm_medium=slack", }, ], }, @@ -181,7 +181,7 @@ def test_subscription_dashboard_delivery(self, MockSlackIntegration: MagicMock) "type": "section", "text": { "type": "mrkdwn", - "text": f"Showing 3 of 10 Insights. ", + "text": f"Showing 3 of 10 Insights. ", }, } ] diff --git a/frontend/src/layout/navigation-3000/components/Navbar.tsx b/frontend/src/layout/navigation-3000/components/Navbar.tsx index e287b2e06220e..49c8435649d95 100644 --- a/frontend/src/layout/navigation-3000/components/Navbar.tsx +++ b/frontend/src/layout/navigation-3000/components/Navbar.tsx @@ -112,7 +112,7 @@ export function Navbar(): JSX.Element { {!systemStatusHealthy ? ( } - identifier={Scene.Settings} + identifier={Scene.SystemStatus} title="System issue!" to={urls.instanceStatus()} /> diff --git a/frontend/src/lib/components/DebugNotice.tsx b/frontend/src/lib/components/DebugNotice.tsx index ac027f28fa1f7..72fbb460955aa 100644 --- a/frontend/src/lib/components/DebugNotice.tsx +++ b/frontend/src/lib/components/DebugNotice.tsx @@ -1,4 +1,5 @@ -import { IconCode, IconX } from '@posthog/icons' +import { IconCode, IconWarning, IconX } from '@posthog/icons' +import { Link, Tooltip } from '@posthog/lemon-ui' import { useValues } from 'kea' import { IconBranch } from 'lib/lemon-ui/icons' import { LemonButton } from 'lib/lemon-ui/LemonButton' @@ -63,25 +64,48 @@ export function DebugNotice(): JSX.Element | null { } tooltip="Dismiss" + tooltipPlacement="right" size="small" noPadding onClick={() => setNoticeHidden(true)} /> -
- - {debugInfo.branch} -
-
- - {debugInfo.revision} -
+ +
+ + {debugInfo.branch} +
+
+ +
+ + {debugInfo.revision} +
+
+ {window.location.port !== '8010' && ( + + You're currently using the app over port 8000, +
+ which only serves the web app, without capture (/e/). +
+ Use port 8010 for full PostHog, proxied via Caddy. + + } + placement="right" + > +
+ + + Click here to fix port! + +
+
+ )} ) } diff --git a/frontend/src/scenes/PreflightCheck/preflightLogic.tsx b/frontend/src/scenes/PreflightCheck/preflightLogic.tsx index 8bae1653241c7..a48c832ce7979 100644 --- a/frontend/src/scenes/PreflightCheck/preflightLogic.tsx +++ b/frontend/src/scenes/PreflightCheck/preflightLogic.tsx @@ -230,7 +230,17 @@ export const preflightLogic = kea([ // http://localhost:6006, but in the local dockerized setup http://host.docker.internal:6006 return false } - return !!preflight && (!preflight.site_url || preflight.site_url != window.location.origin) + const isMismatchPresent = + !!preflight && (!preflight.site_url || preflight.site_url != window.location.origin) + if ( + isMismatchPresent && + preflight.site_url === 'http://localhost:8010' && + window.location.origin === 'http://localhost:8000' + ) { + // Local development setup using the old port - we have a warning in DebugNotice for this + return false + } + return isMismatchPresent }, ], configOptions: [ diff --git a/posthog/api/test/test_insight.py b/posthog/api/test/test_insight.py index eca2b96230c8b..57024518b2a68 100644 --- a/posthog/api/test/test_insight.py +++ b/posthog/api/test/test_insight.py @@ -2488,7 +2488,7 @@ def test_insight_trends_csv(self) -> None: lines = response.content.splitlines() - self.assertEqual(lines[0], b"http://localhost:8000/insights/test123/", lines[0]) + self.assertEqual(lines[0], b"http://localhost:8010/insights/test123/", lines[0]) self.assertEqual( lines[1], b"series,8-Jan-2012,9-Jan-2012,10-Jan-2012,11-Jan-2012,12-Jan-2012,13-Jan-2012,14-Jan-2012,15-Jan-2012", diff --git a/posthog/api/test/test_preflight.py b/posthog/api/test/test_preflight.py index e86a87d774e78..c5a8b29c1b00a 100644 --- a/posthog/api/test/test_preflight.py +++ b/posthog/api/test/test_preflight.py @@ -54,7 +54,7 @@ def preflight_authenticated_dict(self, options=None): preflight = { "opt_out_capture": False, "licensed_users_available": None, - "site_url": "http://localhost:8000", + "site_url": "http://localhost:8010", "can_create_org": False, "instance_preferences": {"debug_queries": True, "disable_paid_fs": False}, "object_storage": False, @@ -207,7 +207,7 @@ def test_cloud_preflight_request_with_social_auth_providers(self): "debug_queries": False, "disable_paid_fs": True, }, - "site_url": "http://localhost:8000", + "site_url": "http://localhost:8010", "available_social_auth_providers": { "google-oauth2": True, "github": False, diff --git a/posthog/api/test/test_uploaded_media.py b/posthog/api/test/test_uploaded_media.py index 2a7a23407fef6..2ad082e697683 100644 --- a/posthog/api/test/test_uploaded_media.py +++ b/posthog/api/test/test_uploaded_media.py @@ -59,7 +59,7 @@ def test_can_upload_and_retrieve_a_file(self) -> None: self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.json()) assert response.json()["name"] == "a-small-but-valid.gif" media_location = response.json()["image_location"] - assert re.match(r"^http://localhost:8000/uploaded_media/.*", media_location) is not None + assert re.match(r"^http://localhost:8010/uploaded_media/.*", media_location) is not None self.client.logout() response = self.client.get(media_location) diff --git a/posthog/api/test/test_user.py b/posthog/api/test/test_user.py index 0d60d7c9c4992..a289a83239eaf 100644 --- a/posthog/api/test/test_user.py +++ b/posthog/api/test/test_user.py @@ -858,11 +858,11 @@ def test_deleting_current_user_is_not_supported(self): def test_redirect_user_to_site_with_toolbar(self, patched_token): patched_token.return_value = "tokenvalue" - self.team.app_urls = ["http://127.0.0.1:8000"] + self.team.app_urls = ["http://127.0.0.1:8010"] self.team.save() response = self.client.get( - "/api/user/redirect_to_site/?userIntent=add-action&appUrl=http%3A%2F%2F127.0.0.1%3A8000" + "/api/user/redirect_to_site/?userIntent=add-action&appUrl=http%3A%2F%2F127.0.0.1%3A8010" ) self.assertEqual(response.status_code, status.HTTP_302_FOUND) locationHeader = response.headers.get("location", "not found") @@ -870,18 +870,18 @@ def test_redirect_user_to_site_with_toolbar(self, patched_token): self.maxDiff = None self.assertEqual( unquote(locationHeader), - 'http://127.0.0.1:8000#__posthog={"action": "ph_authorize", "token": "token123", "temporaryToken": "tokenvalue", "actionId": null, "experimentId": null, "userIntent": "add-action", "toolbarVersion": "toolbar", "apiURL": "http://testserver", "dataAttributes": ["data-attr"]}', + 'http://127.0.0.1:8010#__posthog={"action": "ph_authorize", "token": "token123", "temporaryToken": "tokenvalue", "actionId": null, "experimentId": null, "userIntent": "add-action", "toolbarVersion": "toolbar", "apiURL": "http://testserver", "dataAttributes": ["data-attr"]}', ) @patch("posthog.api.user.secrets.token_urlsafe") def test_redirect_user_to_site_with_experiments_toolbar(self, patched_token): patched_token.return_value = "tokenvalue" - self.team.app_urls = ["http://127.0.0.1:8000"] + self.team.app_urls = ["http://127.0.0.1:8010"] self.team.save() response = self.client.get( - "/api/user/redirect_to_site/?userIntent=edit-experiment&experimentId=12&appUrl=http%3A%2F%2F127.0.0.1%3A8000" + "/api/user/redirect_to_site/?userIntent=edit-experiment&experimentId=12&appUrl=http%3A%2F%2F127.0.0.1%3A8010" ) self.assertEqual(response.status_code, status.HTTP_302_FOUND) locationHeader = response.headers.get("location", "not found") @@ -889,7 +889,7 @@ def test_redirect_user_to_site_with_experiments_toolbar(self, patched_token): self.maxDiff = None self.assertEqual( unquote(locationHeader), - 'http://127.0.0.1:8000#__posthog={"action": "ph_authorize", "token": "token123", "temporaryToken": "tokenvalue", "actionId": null, "experimentId": "12", "userIntent": "edit-experiment", "toolbarVersion": "toolbar", "apiURL": "http://testserver", "dataAttributes": ["data-attr"]}', + 'http://127.0.0.1:8010#__posthog={"action": "ph_authorize", "token": "token123", "temporaryToken": "tokenvalue", "actionId": null, "experimentId": "12", "userIntent": "edit-experiment", "toolbarVersion": "toolbar", "apiURL": "http://testserver", "dataAttributes": ["data-attr"]}', ) @patch("posthog.api.user.secrets.token_urlsafe") diff --git a/posthog/models/test/test_integration_model.py b/posthog/models/test/test_integration_model.py index d4184d9e0265a..91394fd043f84 100644 --- a/posthog/models/test/test_integration_model.py +++ b/posthog/models/test/test_integration_model.py @@ -112,7 +112,7 @@ def test_authorize_url(self): url = OauthIntegration.authorize_url("salesforce", next="/projects/test") assert ( url - == "https://login.salesforce.com/services/oauth2/authorize?client_id=salesforce-client-id&scope=full+refresh_token&redirect_uri=https%3A%2F%2Flocalhost%3A8000%2Fintegrations%2Fsalesforce%2Fcallback&response_type=code&state=next%3D%252Fprojects%252Ftest" + == "https://login.salesforce.com/services/oauth2/authorize?client_id=salesforce-client-id&scope=full+refresh_token&redirect_uri=https%3A%2F%2Flocalhost%3A8010%2Fintegrations%2Fsalesforce%2Fcallback&response_type=code&state=next%3D%252Fprojects%252Ftest" ) def test_authorize_url_with_additional_authorize_params(self): @@ -120,7 +120,7 @@ def test_authorize_url_with_additional_authorize_params(self): url = OauthIntegration.authorize_url("google-ads", next="/projects/test") assert ( url - == "https://accounts.google.com/o/oauth2/v2/auth?client_id=google-client-id&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fadwords+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&redirect_uri=https%3A%2F%2Flocalhost%3A8000%2Fintegrations%2Fgoogle-ads%2Fcallback&response_type=code&state=next%3D%252Fprojects%252Ftest&access_type=offline&prompt=consent" + == "https://accounts.google.com/o/oauth2/v2/auth?client_id=google-client-id&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fadwords+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&redirect_uri=https%3A%2F%2Flocalhost%3A8010%2Fintegrations%2Fgoogle-ads%2Fcallback&response_type=code&state=next%3D%252Fprojects%252Ftest&access_type=offline&prompt=consent" ) @patch("posthog.models.integration.requests.post") diff --git a/posthog/models/test/test_user_model.py b/posthog/models/test/test_user_model.py index 53a83fd2a27f9..a1cd137facb43 100644 --- a/posthog/models/test/test_user_model.py +++ b/posthog/models/test/test_user_model.py @@ -40,7 +40,7 @@ def test_analytics_metadata(self): "has_social_auth": False, "social_providers": [], "strapi_id": None, - "instance_url": "http://localhost:8000", + "instance_url": "http://localhost:8010", "instance_tag": "none", "is_email_verified": None, "has_seen_product_intro_for": None, @@ -76,7 +76,7 @@ def test_analytics_metadata(self): "has_social_auth": False, "social_providers": [], "strapi_id": None, - "instance_url": "http://localhost:8000", + "instance_url": "http://localhost:8010", "instance_tag": "none", "is_email_verified": None, "has_seen_product_intro_for": None, diff --git a/posthog/settings/__init__.py b/posthog/settings/__init__.py index 3e7ebc0b7c984..e39ab1506bdb8 100644 --- a/posthog/settings/__init__.py +++ b/posthog/settings/__init__.py @@ -58,7 +58,7 @@ "disable_paid_fs": disable_paid_fs, } -SITE_URL: str = os.getenv("SITE_URL", "http://localhost:8000").rstrip("/") +SITE_URL: str = os.getenv("SITE_URL", "http://localhost:8010").rstrip("/") INSTANCE_TAG: str = os.getenv("INSTANCE_TAG", "none") if DEBUG: diff --git a/posthog/settings/access.py b/posthog/settings/access.py index 6915d320abcf2..34cfcf2065e57 100644 --- a/posthog/settings/access.py +++ b/posthog/settings/access.py @@ -25,7 +25,12 @@ if get_from_env("DISABLE_SECURE_SSL_REDIRECT", False, type_cast=str_to_bool): SECURE_SSL_REDIRECT = False -CSRF_TRUSTED_ORIGINS = [os.getenv("SITE_URL", "http://localhost:8000").rstrip("/")] +raw_site_url = os.getenv("SITE_URL") +CSRF_TRUSTED_ORIGINS = ( + [raw_site_url.rstrip("/")] + if raw_site_url + else ["http://localhost:8000", "http://localhost:8010"] # 8000 is just Django, 8010 is Django + Capture via Caddy +) # Proxy settings IS_BEHIND_PROXY = get_from_env("IS_BEHIND_PROXY", False, type_cast=str_to_bool) diff --git a/posthog/tasks/test/test_periodic_digest.py b/posthog/tasks/test/test_periodic_digest.py index 826886a68a871..99df488cce07e 100644 --- a/posthog/tasks/test/test_periodic_digest.py +++ b/posthog/tasks/test/test_periodic_digest.py @@ -141,7 +141,7 @@ def test_periodic_digest_report(self, mock_capture: MagicMock) -> None: "plugins_installed": {}, "product": "open source", "realm": "hosted-clickhouse", - "site_url": "http://localhost:8000", + "site_url": "http://localhost:8010", "table_sizes": ANY, "clickhouse_version": ANY, "deployment_infrastructure": "unknown", @@ -255,7 +255,7 @@ def test_periodic_digest_report_custom_dates(self, mock_capture: MagicMock) -> N "plugins_installed": {}, "product": "open source", "realm": "hosted-clickhouse", - "site_url": "http://localhost:8000", + "site_url": "http://localhost:8010", "table_sizes": ANY, "clickhouse_version": ANY, "deployment_infrastructure": "unknown", diff --git a/posthog/tasks/test/test_plugin_server.py b/posthog/tasks/test/test_plugin_server.py index cf03f845e684d..b2cda79c6c22a 100644 --- a/posthog/tasks/test/test_plugin_server.py +++ b/posthog/tasks/test/test_plugin_server.py @@ -25,7 +25,7 @@ def test_tracks_events_regardless(self, mock_report_action: MagicMock, MockEmail "hog function state changed", { "hog_function_id": str(hog_function.id), - "hog_function_url": f"http://localhost:8000/project/{hog_function.team.id}/pipeline/destinations/hog-{str(hog_function.id)}", + "hog_function_url": f"http://localhost:8010/project/{hog_function.team.id}/pipeline/destinations/hog-{str(hog_function.id)}", "state": 1, }, ) diff --git a/posthog/tasks/test/test_usage_report.py b/posthog/tasks/test/test_usage_report.py index 6215af18f6821..d5b2a8b1777a5 100644 --- a/posthog/tasks/test/test_usage_report.py +++ b/posthog/tasks/test/test_usage_report.py @@ -1591,7 +1591,7 @@ def test_send_usage_cloud(self, mock_post: MagicMock, mock_client: MagicMock) -> "organization usage report", {**full_report_as_dict, "scope": "user"}, groups={ - "instance": "http://localhost:8000", + "instance": "http://localhost:8010", "organization": str(self.organization.id), }, timestamp=None, @@ -1703,7 +1703,7 @@ def test_capture_report_transforms_team_id_to_org_id(self, mock_client: MagicMoc self.user.distinct_id, "test event", {**report, "scope": "user"}, - groups={"instance": "http://localhost:8000", "organization": str(self.organization.id)}, + groups={"instance": "http://localhost:8010", "organization": str(self.organization.id)}, timestamp=None, ) @@ -1722,7 +1722,7 @@ def test_capture_report_transforms_team_id_to_org_id(self, mock_client: MagicMoc self.user.distinct_id, "test event", {**report, "scope": "user"}, - groups={"instance": "http://localhost:8000", "organization": str(self.organization.id)}, + groups={"instance": "http://localhost:8010", "organization": str(self.organization.id)}, timestamp=None, )