Skip to content

Commit

Permalink
chore(dev): Warn about port 8010 vs. 8000 in debug notice (#27108)
Browse files Browse the repository at this point in the history
  • Loading branch information
Twixes authored Jan 3, 2025
1 parent 4826242 commit 3e5f3ec
Show file tree
Hide file tree
Showing 18 changed files with 90 additions and 49 deletions.
4 changes: 3 additions & 1 deletion ee/api/test/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions ee/api/test/test_billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions ee/billing/test/test_quota_limiting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"] == {}
Expand Down Expand Up @@ -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) == [
Expand Down
10 changes: 5 additions & 5 deletions ee/tasks/test/subscriptions/test_slack_subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
],
},
Expand Down Expand Up @@ -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",
},
],
},
Expand Down Expand Up @@ -181,7 +181,7 @@ def test_subscription_dashboard_delivery(self, MockSlackIntegration: MagicMock)
"type": "section",
"text": {
"type": "mrkdwn",
"text": f"Showing 3 of 10 Insights. <http://localhost:8000/dashboard/{self.dashboard.id}?utm_source=posthog&utm_campaign=subscription_report&utm_medium=slack|View the rest in PostHog>",
"text": f"Showing 3 of 10 Insights. <http://localhost:8010/dashboard/{self.dashboard.id}?utm_source=posthog&utm_campaign=subscription_report&utm_medium=slack|View the rest in PostHog>",
},
}
]
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/layout/navigation-3000/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export function Navbar(): JSX.Element {
{!systemStatusHealthy ? (
<NavbarButton
icon={<IconWarning />}
identifier={Scene.Settings}
identifier={Scene.SystemStatus}
title="System issue!"
to={urls.instanceStatus()}
/>
Expand Down
54 changes: 39 additions & 15 deletions frontend/src/lib/components/DebugNotice.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -63,25 +64,48 @@ export function DebugNotice(): JSX.Element | null {
<LemonButton
icon={<IconX />}
tooltip="Dismiss"
tooltipPlacement="right"
size="small"
noPadding
onClick={() => setNoticeHidden(true)}
/>
</div>
<div
className="flex items-center gap-2 px-2 h-8 border-l-4 border-brand-red"
title={`Branch: ${debugInfo.branch}`}
>
<IconBranch className="text-lg" />
<b className="min-w-0 flex-1 truncate">{debugInfo.branch}</b>
</div>
<div
className="flex items-center gap-2 px-2 h-8 border-l-4 border-brand-yellow"
title={`Revision: ${debugInfo.revision}`}
>
<IconCode className="text-lg" />
<b className="min-w-0 flex-1 truncate">{debugInfo.revision}</b>
</div>
<Tooltip title="Branch" placement="right">
<div className="flex items-center gap-2 w-fit px-2 h-8 border-l-4 border-brand-red">
<IconBranch className="text-lg" />
<b className="min-w-0 flex-1 truncate">{debugInfo.branch}</b>
</div>
</Tooltip>
<Tooltip title="Revision" placement="right">
<div className="flex items-center gap-2 w-fit px-2 h-8 border-l-4 border-brand-yellow">
<IconCode className="text-lg" />
<b className="min-w-0 flex-1 truncate">{debugInfo.revision}</b>
</div>
</Tooltip>
{window.location.port !== '8010' && (
<Tooltip
title={
<>
You're currently using the app over port 8000,
<br />
which only serves the web app, without capture (/e/).
<br />
Use port 8010 for full PostHog, proxied via Caddy.
</>
}
placement="right"
>
<div className="flex items-center gap-2 w-fit px-2 h-8 border-l-4 border-brand-key">
<IconWarning className="text-lg" />
<Link
to={window.location.href.replace(`:${window.location.port}`, ':8010')}
className="font-semibold text-default underline min-w-0 flex-1 truncate"
>
Click here to fix port!
</Link>
</div>
</Tooltip>
)}
</div>
)
}
12 changes: 11 additions & 1 deletion frontend/src/scenes/PreflightCheck/preflightLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,17 @@ export const preflightLogic = kea<preflightLogicType>([
// 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: [
Expand Down
2 changes: 1 addition & 1 deletion posthog/api/test/test_insight.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions posthog/api/test/test_preflight.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion posthog/api/test/test_uploaded_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions posthog/api/test/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,38 +858,38 @@ 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")
self.assertIn("22apiURL%22%3A%20%22http%3A%2F%2Ftestserver%22", locationHeader)
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")
self.assertIn("22apiURL%22%3A%20%22http%3A%2F%2Ftestserver%22", locationHeader)
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")
Expand Down
4 changes: 2 additions & 2 deletions posthog/models/test/test_integration_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ 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):
with self.settings(**self.mock_settings):
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")
Expand Down
4 changes: 2 additions & 2 deletions posthog/models/test/test_user_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion posthog/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 6 additions & 1 deletion posthog/settings/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions posthog/tasks/test/test_periodic_digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion posthog/tasks/test/test_plugin_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
)
Expand Down
Loading

0 comments on commit 3e5f3ec

Please sign in to comment.