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

chore: move livestream to posthog monorepo #23044

Merged
merged 143 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 138 commits
Commits
Show all changes
143 commits
Select commit Hold shift + click to select a range
a1fe96c
🔥 initial commit
fuziontech May 15, 2024
07b815d
update readme
fuziontech May 15, 2024
e479599
Update README.md
fuziontech May 15, 2024
6623330
Update README.md
fuziontech May 15, 2024
a9c5ee0
deploy scripts
fuziontech May 15, 2024
6a59635
Merge branch 'main' of https://github.com/PostHog/livestream
fuziontech May 15, 2024
d2bc94c
very basic consumer setup
bretthoerner May 15, 2024
aeeb784
add some configs and docker-compose
fuziontech May 15, 2024
23344ea
Merge pull request #1 from PostHog/configs
fuziontech May 15, 2024
1062112
formatting for testing
fuziontech May 15, 2024
0318de3
add tailscale
fuziontech May 15, 2024
ed110de
flip from dev to prod flag
fuziontech May 15, 2024
2e32046
set default to be not prod
fuziontech May 15, 2024
1b0761c
default for group_id
fuziontech May 15, 2024
6a4ac7c
tailscale up
fuziontech May 15, 2024
dd37c66
Merge pull request #2 from PostHog/configs
fuziontech May 15, 2024
de98dda
update gitignore
fuziontech May 15, 2024
5282954
merge configs and gitignore
fuziontech May 15, 2024
a60304e
basic geolocation
bretthoerner May 15, 2024
a56d027
remove unused localServer
fuziontech May 15, 2024
c237095
Merge branch 'main' of https://github.com/PostHog/livestream
fuziontech May 15, 2024
7c71b6d
document mmdb
bretthoerner May 15, 2024
3f13e5d
just make configs an example
fuziontech May 15, 2024
f287b30
merge
fuziontech May 15, 2024
7250672
drop raw print
bretthoerner May 15, 2024
3144a90
add a start script (downloads the mmdb)
fuziontech May 15, 2024
61ca13b
Merge branch 'main' of https://github.com/PostHog/livestream
fuziontech May 15, 2024
56d2ce7
add readme and update configs.example
fuziontech May 15, 2024
efe784e
ts working
fuziontech May 15, 2024
d7c8fba
if in start
bretthoerner May 15, 2024
b2e7cc8
update start script
fuziontech May 15, 2024
0c53c86
fix start
fuziontech May 15, 2024
6292b0c
fix start
fuziontech May 15, 2024
913c521
fix more
fuziontech May 15, 2024
dd85a97
add sql endpoints for tokenId and Person lookups
fuziontech May 15, 2024
d318f08
Merge pull request #3 from PostHog/sql
bretthoerner May 15, 2024
9eec011
work towards filter
bretthoerner May 15, 2024
3b3f156
sub channel
bretthoerner May 15, 2024
2f71f97
Merge pull request #4 from PostHog/brett/1
bretthoerner May 15, 2024
fe50e6b
fix subChan
bretthoerner May 15, 2024
3ffa9ef
hardcode team2 token
bretthoerner May 15, 2024
6446c10
add cors
zlwaterfield May 15, 2024
21740e8
only allow get and head
zlwaterfield May 15, 2024
a1af346
add atomicbool
bretthoerner May 15, 2024
642ea32
add channel to kafka
bretthoerner May 15, 2024
feca4c4
add logs
bretthoerner May 15, 2024
10be8d9
verbose logs
bretthoerner May 15, 2024
43261ac
make array
bretthoerner May 15, 2024
016975e
drop sub ptrs
bretthoerner May 15, 2024
a755310
more logs
bretthoerner May 15, 2024
b0aaf94
helps to loop
bretthoerner May 15, 2024
168de0c
drop some logigng
bretthoerner May 15, 2024
7b8313f
move sub branch
bretthoerner May 15, 2024
9aec09e
logging
bretthoerner May 15, 2024
6421116
drop log
bretthoerner May 15, 2024
4294c4b
hog
bretthoerner May 15, 2024
bb89a7c
Deal with numeric distinct ids later
bretthoerner May 15, 2024
5f8ba8b
logs
bretthoerner May 15, 2024
d2caf75
api_key
bretthoerner May 15, 2024
3b18b2a
send 1/1000
bretthoerner May 15, 2024
2a623a2
remove log
fuziontech May 15, 2024
71e936d
Merge pull request #5 from PostHog/zach/cors
fuziontech May 15, 2024
d5f4fdd
remove more logs
fuziontech May 15, 2024
7fc9f6b
change response payload
bretthoerner May 15, 2024
8996e77
set timestamp if needed
bretthoerner May 15, 2024
d48db8c
fill in person_id if team_id is set
bretthoerner May 15, 2024
2c3e454
require teamid, convert to token
bretthoerner May 15, 2024
922f2d4
clean up subs on disconnect
fuziontech May 15, 2024
12b24aa
log
bretthoerner May 15, 2024
2acfbf1
check for token in another place
bretthoerner May 15, 2024
a158aae
clean up subs on disconnect
fuziontech May 15, 2024
c04383d
drop modulo and log
bretthoerner May 15, 2024
a187f03
merge fix
fuziontech May 15, 2024
55eb90b
fix no assign
fuziontech May 15, 2024
c449f56
fix merges
fuziontech May 15, 2024
bd82d90
don't reuse db conn for now
bretthoerner May 15, 2024
9474564
drop a log
bretthoerner May 15, 2024
607ab81
add back commented out log
fuziontech May 15, 2024
1e2dfee
Merge pull request #6 from PostHog/clean_subs
fuziontech May 15, 2024
eaf2633
Don't block on send to client channel
bretthoerner May 15, 2024
3d602fd
add geo bool
bretthoerner May 15, 2024
8e08c9d
only geo events
bretthoerner May 15, 2024
a5983cb
use wrapper ip
bretthoerner May 15, 2024
dac19f2
don't require team in geo mode
bretthoerner May 15, 2024
e5f3b86
add an endpoint and stats keeper for teams
fuziontech May 15, 2024
565341a
Merge pull request #7 from PostHog/live_stats
fuziontech May 15, 2024
ad6cf9b
remove stats keeper
fuziontech May 15, 2024
ca00d6c
start stats keeper
fuziontech May 15, 2024
33125c5
wire it up
fuziontech May 15, 2024
867520d
change the shape of the response
fuziontech May 15, 2024
bbe8847
omit empty error
fuziontech May 15, 2024
b05ffbb
omit empty on the stats as well
fuziontech May 15, 2024
af08459
enable logging on back pressure
fuziontech May 15, 2024
7c4d0b2
add jwt endpoint for testing
fuziontech May 15, 2024
5f7ad61
support multiple event types
bretthoerner May 16, 2024
2400d93
Get Auth Setup
fuziontech May 16, 2024
c1bda9a
Merge pull request #8 from PostHog/auth
fuziontech May 16, 2024
60c8907
jwt team is float so turn that into int
fuziontech May 16, 2024
0c87990
logs
fuziontech May 16, 2024
913fdfb
add auth for stats endpoint
fuziontech May 16, 2024
feda553
remove tailscale and use autoTLS on public endpoints
fuziontech May 16, 2024
fe0a696
default to :443 for auto tls
fuziontech May 16, 2024
d6e031b
remove un-needed endpoints and handlers
fuziontech May 17, 2024
ce0617c
Use compression because... a lot of data (#9)
fuziontech Jun 5, 2024
b4194be
add dockerfile and CI/CD (#10)
frankh Jun 6, 2024
155c5d4
Add MMDB download to Dockerfile (#11)
Twixes Jun 10, 2024
13c8a73
Use clearer name for MMDB
Twixes Jun 10, 2024
aaeb9a5
Don't connect to Kafka over SSL in dev
Twixes Jun 10, 2024
d940a44
Fix JWT token in example config
Twixes Jun 10, 2024
1c21f93
Add postgres.url to example config
Twixes Jun 10, 2024
7b488bf
Add expected scope
Twixes Jun 10, 2024
c2a2ab1
Fix const syntax
Twixes Jun 10, 2024
875ce72
Put scope validation where claims are known
Twixes Jun 10, 2024
69a3858
Fix audience validation
Twixes Jun 10, 2024
a221199
moves
fuziontech Jun 18, 2024
ad34a39
Merge remote-tracking branch 'livestream_repo/monorepo' into livestream
fuziontech Jun 18, 2024
6e8f61a
ignore livestream for ci
fuziontech Jun 18, 2024
d0ea718
main -> master
fuziontech Jun 18, 2024
5c5dd07
move GA to root
fuziontech Jun 18, 2024
a0d85fd
docker lint fix
fuziontech Jun 18, 2024
f0f4f25
fix typo
fuziontech Jun 18, 2024
f08c54f
fixes for docker builds
fuziontech Jun 18, 2024
d9a9cb9
test docker build
fuziontech Jun 18, 2024
5ff18cb
livestream build docker
fuziontech Jun 18, 2024
10d3a3c
dang
fuziontech Jun 18, 2024
57f43ae
Update .github/workflows/livestream-docker-image.yml
fuziontech Jun 18, 2024
6dfe363
Update .github/workflows/livestream-docker-image.yml
fuziontech Jun 18, 2024
eb0ecd3
don't build posthog container when PR is pushed for rust or livestream
fuziontech Jun 18, 2024
318f7a0
Update .github/workflows/livestream-docker-image.yml
fuziontech Jun 18, 2024
8999e02
add a lot of paths-ignore
fuziontech Jun 18, 2024
b8d4c8d
Update .github/workflows/livestream-docker-image.yml
fuziontech Jun 18, 2024
4231213
Dorny filters are handling most of what I was trying to do
fuziontech Jun 18, 2024
5d25e97
remove tailscale to speed up builds
fuziontech Jun 18, 2024
ae42a0a
maybe?
fuziontech Jun 18, 2024
c693108
push container to github.com/posthog/postog
fuziontech Jun 18, 2024
f78b430
don't build container on PR
fuziontech Jun 18, 2024
2f10422
remove more filters because dorny
fuziontech Jun 18, 2024
bd946ad
Merge branch 'master' into livestream
fuziontech Jun 18, 2024
f46bcb8
Update query snapshots
github-actions[bot] Jun 18, 2024
d55f1fd
undo rust.yml
fuziontech Jun 18, 2024
0ffb38a
Update .github/workflows/livestream-docker-image.yml
neilkakkar Jun 18, 2024
53a5466
enable codeql for go
fuziontech Jun 18, 2024
8e986ca
autobuild go
fuziontech Jun 18, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/build-and-deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
- master
paths-ignore:
- 'rust/**'
- 'livestream/**'

jobs:
slack:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ on:
push:
branches:
- master
pull_request:
workflow_dispatch:
inputs:
clickhouseServerVersion:
description: ClickHouse server version. Leave blank for default
type: string
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/ci-hog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ on:
push:
branches:
- master
paths-ignore:
- rust/**
- livestream/**
pull_request:
paths-ignore:
- rust/**
- livestream/**

jobs:
# Job to decide if we should run backend ci
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/container-images-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ on:
- master
paths-ignore:
- 'rust/**'
- 'livestream/**'
workflow_dispatch:

jobs:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/container-images-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Container Images CI

on:
pull_request:
paths-ignore:
- 'rust/**'
- 'livestream/**'

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
Expand Down
88 changes: 88 additions & 0 deletions .github/workflows/livestream-docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Livestream Docker CI/CD

on:
push:
branches:
- master
paths:
- 'livestream/**'
fuziontech marked this conversation as resolved.
Show resolved Hide resolved
- '.github/workflows/livestream-docker-image.yml'

jobs:
build:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

outputs:
sha: ${{ steps.push.outputs.digest }}

steps:
- name: Check out livestream code
uses: actions/checkout@v4
with:
sparse-checkout: 'livestream/'
sparse-checkout-cone-mode: false

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
fuziontech marked this conversation as resolved.
Show resolved Hide resolved
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
logout: false

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/posthog/posthog/livestream

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Build and push Docker image
id: push
if: github.ref != 'refs/heads/master'
neilkakkar marked this conversation as resolved.
Show resolved Hide resolved
uses: docker/build-push-action@v5
with:
context: livestream/
file: livestream/Dockerfile
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

# deploy:
# runs-on: ubuntu-latest
# needs: build
# steps:
# - name: get deployer token
# id: deployer
# uses: getsentry/action-github-app-token@v3
# with:
# app_id: ${{ secrets.DEPLOYER_APP_ID }}
# private_key: ${{ secrets.DEPLOYER_APP_PRIVATE_KEY }}

# - name: Trigger livestream deployment
# uses: peter-evans/repository-dispatch@v3
# with:
# token: ${{ steps.deployer.outputs.token }}
# repository: PostHog/charts
# event-type: commit_state_update
# client-payload: |
# {
# "values": {
# "image": {
# "sha": "${{ needs.build.outputs.sha }}"
# }
# },
# "release": "livestream",
# "commit": ${{ toJson(github.event.head_commit) }},
# "repository": ${{ toJson(github.repository) }}
# }
6 changes: 6 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ name: Rust test CI
on:
workflow_dispatch:
push:
paths:
- 'rust/**'
- '.github/workflows/rust.yml'
branches: [master, main]
pull_request:
paths:
- 'rust/**'
- '.github/workflows/rust.yml'

env:
CARGO_TERM_COLOR: always
Expand Down
32 changes: 32 additions & 0 deletions livestream/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work
go.work.sum

# binary / build
livestream

# tsnet
.tsnet-state/

# configs
configs/configs.yml
mmdb.db
24 changes: 24 additions & 0 deletions livestream/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM golang:1.22 as builder
WORKDIR /code
COPY go.sum go.mod ./
RUN go mod download -x

COPY . ./
RUN go get ./...
RUN go build -v -o /livestream ./...

Check notice on line 8 in livestream/Dockerfile

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Multiple consecutive `RUN` instructions. Consider consolidation.

# Fetch the GeoLite2-City database that will be used for IP geolocation within Django.
RUN apt-get update && \

Check warning on line 11 in livestream/Dockerfile

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Set the SHELL option -o pipefail before RUN with a pipe in it. If you are using /bin/sh in an alpine image or if your shell is symlinked to busybox then consider explicitly setting your SHELL to /bin/ash, or disable this check

Check warning on line 11 in livestream/Dockerfile

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`
apt-get install -y --no-install-recommends \
"ca-certificates" \
"curl" \
"brotli" \
&& \
rm -rf /var/lib/apt/lists/* && \
mkdir share && \
( curl -s -L "https://mmdbcdn.posthog.net/" --http1.1 | brotli --decompress --output=/GeoLite2-City.mmdb ) && \
chmod -R 755 /GeoLite2-City.mmdb

FROM ubuntu

Check warning on line 22 in livestream/Dockerfile

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Always tag the version of an image explicitly
COPY --from=builder /livestream /GeoLite2-City.mmdb /
CMD ["/livestream"]
19 changes: 19 additions & 0 deletions livestream/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<img src="https://github.com/PostHog/livestream/assets/391319/d4a4964d-4b19-4605-b268-157366817863" width="280" height="280" />

# RealTime Hog 3000

The start of something fresh.

## Installing

```bash
curl https://mmdbcdn.posthog.net/ | brotli -d > mmdb.db
```

Config the configs in `configs/config.yml`. You can take a peak at the examples in `configs/configs.example.yml`

Run it!

```bash
go run .
```
26 changes: 26 additions & 0 deletions livestream/configs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
"fmt"

"github.com/fsnotify/fsnotify"
"github.com/spf13/viper"
)

func loadConfigs() {
viper.SetConfigName("configs")
viper.AddConfigPath("configs/")

viper.SetDefault("kafka.group_id", "livestream")
viper.SetDefault("prod", false)

err := viper.ReadInConfig()
if err != nil {
panic(fmt.Errorf("fatal error config file: %w", err))
}

viper.OnConfigChange(func(e fsnotify.Event) {
fmt.Println("Config file changed:", e.Name)
})
viper.WatchConfig()
}
11 changes: 11 additions & 0 deletions livestream/configs/configs.example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
prod: true
kafka:
brokers: 'localhost:9092'
topic: ''
group_id: 'livestream-dev'
mmdb:
path: 'mmdb.db'
jwt:
token: '<randomly generated secret key>'
postgres:
url: 'postgres://postgres:postgres@localhost:5432/postgres'
18 changes: 18 additions & 0 deletions livestream/db.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import (
"context"
"log"

"github.com/jackc/pgx/v5"
"github.com/spf13/viper"
)

func getPGConn() *pgx.Conn {
url := viper.GetString("postgres.url")
conn, err := pgx.Connect(context.Background(), url)
if err != nil {
log.Panicf("Unable to connect to database: %v\n", err)
}
return conn
}
5 changes: 5 additions & 0 deletions livestream/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

env GOOS=linux GOARCH=arm64 go build -o dist/livestream
scp dist/livestream [email protected]:

62 changes: 62 additions & 0 deletions livestream/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
version: "3.8"

services:
postgres:
image: postgres:16-alpine
restart: always
ports:
- "5432:5432"
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: liveevents
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s

redis:
image: redis:alpine
restart: always
ports:
- "6379:6379"

redpanda:
image: vectorized/redpanda:v23.2.17
command:
- redpanda start
- --smp 1
- --overprovisioned
- --node-id 0
- --kafka-addr PLAINTEXT://0.0.0.0:29092,OUTSIDE://0.0.0.0:9092
- --advertise-kafka-addr PLAINTEXT://redpanda:29092,OUTSIDE://localhost:9092
- --pandaproxy-addr 0.0.0.0:8082
- --advertise-pandaproxy-addr localhost:8082
ports:
- 8081:8081
- 8082:8082
- 9092:9092
- 29092:29092

console:
image: docker.redpanda.com/redpandadata/console:v2.3.8
restart: on-failure
entrypoint: /bin/sh
command: -c "echo \"$$CONSOLE_CONFIG_FILE\" > /tmp/config.yml; /app/console"
environment:
CONFIG_FILEPATH: /tmp/config.yml
CONSOLE_CONFIG_FILE: |
kafka:
brokers: ["redpanda:29092"]
schemaRegistry:
enabled: true
urls: ["http://redpanda:8081"]
connect:
enabled: true
clusters:
- name: datagen
url: http://connect:8083
ports:
- "8088:8088"
depends_on:
- redpanda
Loading
Loading