Skip to content
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

fix: Safely add livestream host #28727

Merged
merged 18 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bin/deploy-hobby
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ $TLS_BLOCK
$DOMAIN, http://, https:// {
encode gzip zstd
reverse_proxy http://web:8000
reverse_proxy http://livestream:8666
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aaaaahhhhhhh, dang of course

}
EOF

Expand Down Expand Up @@ -199,7 +200,7 @@ fi

# setup docker-compose
echo "Setting up Docker Compose"
sudo curl -L "https://github.com/docker/compose/releases/download/v2.13.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose || true
sudo curl -L "https://github.com/docker/compose/releases/download/v2.33.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose || true
sudo chmod +x /usr/local/bin/docker-compose

# enable docker without sudo
Expand Down
12 changes: 12 additions & 0 deletions docker-compose.hobby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ services:
environment:
SENTRY_DSN: $SENTRY_DSN
SITE_URL: https://$DOMAIN
LIVESTREAM_HOST: 'https://${DOMAIN}:8666'
SECRET_KEY: $POSTHOG_SECRET
OBJECT_STORAGE_ACCESS_KEY_ID: 'object_storage_root_user'
OBJECT_STORAGE_SECRET_ACCESS_KEY: 'object_storage_root_password'
Expand Down Expand Up @@ -276,6 +277,17 @@ services:
file: docker-compose.base.yml
service: property-defs-rs

livestream:
extends:
file: docker-compose.base.yml
service: livestream
environment:
- JWT.TOKEN=${POSTHOG_SECRET}
ports:
- '8666:8080'
volumes:
- ./posthog/docker/livestream/configs-dev.yml:/configs/configs.yml

volumes:
zookeeper-data:
zookeeper-datalog:
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/lib/utils/apiHost.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getAppContext } from './getAppContext'

export function apiHostOrigin(): string {
const appOrigin = window.location.origin
if (appOrigin === 'https://us.posthog.com') {
Expand All @@ -10,6 +12,8 @@ export function apiHostOrigin(): string {

export function liveEventsHostOrigin(): string | null {
const appOrigin = window.location.origin
const appContext = getAppContext()

if (appOrigin === 'https://us.posthog.com') {
return 'https://live.us.posthog.com'
} else if (appOrigin === 'https://eu.posthog.com') {
Expand All @@ -20,5 +24,5 @@ export function liveEventsHostOrigin(): string | null {
return 'http://localhost:6006'
}

return 'http://localhost:8666'
return appContext?.livestream_host || 'http://localhost:8666'
}
1 change: 1 addition & 0 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3479,6 +3479,7 @@ export interface AppContext {
year_in_hog_url?: string
/** Support flow aid: a staff-only list of users who may be impersonated to access this resource. */
suggested_users_with_access?: UserBasicType[]
livestream_host?: string
}

export type StoredMetricMathOperations = 'max' | 'min' | 'sum'
Expand Down
3 changes: 3 additions & 0 deletions posthog/settings/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,3 +425,6 @@ def static_varies_origin(headers, path, url):

# temporary setting to control if a cluster has person_properties_map_custom column optimization
USE_PERSON_PROPERTIES_MAP_CUSTOM = get_from_env("USE_PERSON_PROPERTIES_MAP_CUSTOM", False, type_cast=bool)

# Passed to the frontend for the web app to know where to connect to
LIVESTREAM_HOST = get_from_env("LIVESTREAM_HOST", "")
1 change: 1 addition & 0 deletions posthog/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ def render_template(
"switched_team": getattr(request, "switched_team", None),
"suggested_users_with_access": getattr(request, "suggested_users_with_access", None),
"commit_sha": context["git_rev"],
"livestream_host": settings.LIVESTREAM_HOST,
**posthog_app_context,
}

Expand Down
Loading