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

feat(cdp): Use cyclotron part 2 #24746

Merged
merged 91 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
b69188d
very broken refactor
benjackwhite Aug 27, 2024
ee3166a
Refactor
benjackwhite Aug 29, 2024
a639c9d
Fixes all round
benjackwhite Aug 29, 2024
d34f0d9
Refactored tests
benjackwhite Aug 29, 2024
99c7b4c
Merge branch 'master' into feat/cdp-cyclotron
benjackwhite Aug 29, 2024
d2f923d
fixes
benjackwhite Aug 29, 2024
36578d7
Fixes all over
benjackwhite Aug 29, 2024
6782daa
Fixes
benjackwhite Aug 29, 2024
c1d9710
fixes
benjackwhite Aug 29, 2024
75472d7
Removed overflow
benjackwhite Aug 29, 2024
3861150
Fixes
benjackwhite Aug 29, 2024
43803c4
Fixes
benjackwhite Aug 29, 2024
93526d0
Merge branch 'master' into feat/cdp-cyclotron
benjackwhite Sep 2, 2024
e13ef86
Merge branch 'master' into feat/cdp-cyclotron
benjackwhite Sep 2, 2024
805ed9c
Fixes
benjackwhite Sep 2, 2024
6e329e7
fix
benjackwhite Sep 2, 2024
1cf633a
Merge branch 'master' into feat/cdp-cyclotron
benjackwhite Sep 2, 2024
db73a61
Fixes
benjackwhite Sep 2, 2024
6d55fb1
Fix up look sharp
benjackwhite Sep 2, 2024
3c8efd9
Fixes
benjackwhite Sep 2, 2024
8f6762f
Fixes
benjackwhite Sep 2, 2024
68b8e49
Fix
benjackwhite Sep 2, 2024
b2ecbf4
Fixes
benjackwhite Sep 3, 2024
b95a3b5
Fixes
benjackwhite Sep 3, 2024
71ec533
Fixes
benjackwhite Sep 3, 2024
98d7dd4
Changes all round
benjackwhite Sep 3, 2024
eff73c6
Fixes
benjackwhite Sep 3, 2024
831b362
Fixes
benjackwhite Sep 3, 2024
a97f7a0
Updated worker format
benjackwhite Sep 3, 2024
9b81210
Fixes
benjackwhite Sep 3, 2024
2236ec0
fix
benjackwhite Sep 3, 2024
5fa203c
Re-enable worker
benjackwhite Sep 3, 2024
b3b07b7
Fixes
benjackwhite Sep 3, 2024
9b6602a
Fixes
benjackwhite Sep 3, 2024
f396645
Fixes
benjackwhite Sep 3, 2024
b638063
Setup rust on ci
benjackwhite Sep 3, 2024
78627d3
Merge branch 'master' into feat/cdp-cyclotron
benjackwhite Sep 3, 2024
c0a7519
Merge branch 'feat/cdp-cyclotron' into feat/cdp-cyclotron-part-2
benjackwhite Sep 3, 2024
64fdc13
Fixes
benjackwhite Sep 3, 2024
d8169b0
More fixes
benjackwhite Sep 3, 2024
b96616a
fixes
benjackwhite Sep 3, 2024
14a4065
Merge branch 'feat/cdp-cyclotron' into feat/cdp-cyclotron-part-2
benjackwhite Sep 3, 2024
488c172
Fixes
benjackwhite Sep 3, 2024
01ede4e
Fix types
benjackwhite Sep 3, 2024
5720da4
Merge branch 'master' into feat/cdp-cyclotron
benjackwhite Sep 4, 2024
8dc6dce
Merge branch 'feat/cdp-cyclotron' into feat/cdp-cyclotron-part-2
benjackwhite Sep 4, 2024
7843af0
Fixes
benjackwhite Sep 4, 2024
ac20828
Fixes
benjackwhite Sep 4, 2024
61e63bb
fix
benjackwhite Sep 4, 2024
176fabf
Merge branch 'master' into feat/cdp-cyclotron-part-2
benjackwhite Sep 4, 2024
022b7d6
Fixes
benjackwhite Sep 4, 2024
4f5d0da
Fixes
benjackwhite Sep 4, 2024
7389d80
Merge branch 'master' into feat/cdp-cyclotron-part-2
benjackwhite Sep 4, 2024
52611be
Fixed up setting and parsing of blobs
benjackwhite Sep 4, 2024
47a4818
Fixed up tests
benjackwhite Sep 4, 2024
bb2b3e5
Fix tests
benjackwhite Sep 4, 2024
2d444aa
Merge branch 'master' into feat/cdp-cyclotron-part-2
benjackwhite Sep 4, 2024
9e7bcca
Fixes
benjackwhite Sep 4, 2024
43b54f4
Merge branch 'master' into feat/cdp-cyclotron-part-2
benjackwhite Sep 4, 2024
1311f64
Fix
benjackwhite Sep 4, 2024
e86ea4c
Fix
benjackwhite Sep 5, 2024
3f91dad
Merge branch 'master' into feat/cdp-cyclotron-part-2
benjackwhite Sep 5, 2024
ac159d2
Fixes
benjackwhite Sep 5, 2024
04a2e90
Fixes
benjackwhite Sep 5, 2024
af18caa
Removed old test
benjackwhite Sep 5, 2024
bfbf8a0
Fixes
benjackwhite Sep 5, 2024
cef34d9
Fixes
benjackwhite Sep 5, 2024
aac54af
Fixes
benjackwhite Sep 5, 2024
0ee8ba1
Fixes
benjackwhite Sep 5, 2024
64aa1e2
Fixes
benjackwhite Sep 5, 2024
4a53ac1
Fixes
benjackwhite Sep 5, 2024
4e9ea89
Fix
benjackwhite Sep 5, 2024
2951d9b
Fix
benjackwhite Sep 5, 2024
1fd7b99
Fix
benjackwhite Sep 5, 2024
158af77
Fixes
benjackwhite Sep 5, 2024
8302af5
Fix tests
benjackwhite Sep 5, 2024
d284e1d
Fixes
benjackwhite Sep 5, 2024
37c6c2d
Fixes
benjackwhite Sep 5, 2024
c5682e8
Fixes
benjackwhite Sep 5, 2024
4cdf0ce
fix
benjackwhite Sep 5, 2024
4196889
Merge branch 'master' into feat/cdp-cyclotron-part-2
benjackwhite Sep 5, 2024
6909aeb
Playing
benjackwhite Sep 6, 2024
6729b85
Fix
benjackwhite Sep 6, 2024
d118775
Fixes?
benjackwhite Sep 6, 2024
8e761c0
Merge branch 'master' into feat/cdp-cyclotron-part-2
benjackwhite Sep 6, 2024
8043ab7
Ditch cache
benjackwhite Sep 6, 2024
1edd85f
Disable for e2e testing
benjackwhite Sep 9, 2024
1ca3f6a
Fix?
benjackwhite Sep 9, 2024
26120dc
Fixes
benjackwhite Sep 9, 2024
2fd90cf
Fix
benjackwhite Sep 9, 2024
74e977e
Fix
benjackwhite Sep 9, 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
29 changes: 16 additions & 13 deletions .github/workflows/ci-plugin-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ jobs:
defaults:
run:
working-directory: 'plugin-server'

steps:
- uses: actions/checkout@v3

Expand All @@ -82,6 +81,7 @@ jobs:
tests:
name: Plugin Server Tests (${{matrix.shard}})
needs: changes
if: needs.changes.outputs.plugin-server == 'true'
runs-on: ubuntu-latest

strategy:
Expand All @@ -97,21 +97,17 @@ jobs:

steps:
- name: Code check out
if: needs.changes.outputs.plugin-server == 'true'
uses: actions/checkout@v3

- name: Stop/Start stack with Docker Compose
if: needs.changes.outputs.plugin-server == 'true'
run: |
docker compose -f docker-compose.dev.yml down
docker compose -f docker-compose.dev.yml up -d

- name: Add Kafka to /etc/hosts
if: needs.changes.outputs.plugin-server == 'true'
run: echo "127.0.0.1 kafka" | sudo tee -a /etc/hosts

- name: Set up Python
if: needs.changes.outputs.plugin-server == 'true'
uses: actions/setup-python@v5
with:
python-version: 3.11.9
Expand All @@ -122,50 +118,57 @@ jobs:
# uv is a fast pip alternative: https://github.com/astral-sh/uv/
- run: pip install uv

- name: Install rust
uses: dtolnay/[email protected]

- uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
rust/target
key: ${{ runner.os }}-cargo-release-${{ hashFiles('**/Cargo.lock') }}

- name: Install sqlx-cli
working-directory: rust
run: cargo install [email protected] --no-default-features --features native-tls,postgres

- name: Install SAML (python3-saml) dependencies
if: needs.changes.outputs.plugin-server == 'true'
run: |
sudo apt-get update
sudo apt-get install libxml2-dev libxmlsec1-dev libxmlsec1-openssl

- name: Install python dependencies
if: needs.changes.outputs.plugin-server == 'true'
run: |
uv pip install --system -r requirements-dev.txt
uv pip install --system -r requirements.txt

- name: Install pnpm
if: needs.changes.outputs.plugin-server == 'true'
uses: pnpm/action-setup@v4

- name: Set up Node.js
if: needs.changes.outputs.plugin-server == 'true'
uses: actions/setup-node@v4
with:
node-version: 18.12.1
cache: pnpm
cache-dependency-path: plugin-server/pnpm-lock.yaml

- name: Install package.json dependencies with pnpm
if: needs.changes.outputs.plugin-server == 'true'
run: cd plugin-server && pnpm i

- name: Wait for Clickhouse, Redis & Kafka
if: needs.changes.outputs.plugin-server == 'true'
run: |
docker compose -f docker-compose.dev.yml up kafka redis clickhouse -d --wait
bin/check_kafka_clickhouse_up

- name: Set up databases
if: needs.changes.outputs.plugin-server == 'true'
env:
TEST: 'true'
SECRET_KEY: 'abcdef' # unsafe - for testing only
DATABASE_URL: 'postgres://posthog:posthog@localhost:5432/posthog'
run: cd plugin-server && pnpm setup:test

- name: Test with Jest
if: needs.changes.outputs.plugin-server == 'true'
env:
# Below DB name has `test_` prepended, as that's how Django (ran above) creates the test DB
DATABASE_URL: 'postgres://posthog:posthog@localhost:5432/test_posthog'
Expand Down
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@
"WORKER_CONCURRENCY": "2",
"OBJECT_STORAGE_ENABLED": "True",
"HOG_HOOK_URL": "http://localhost:3300/hoghook",
"CDP_ASYNC_FUNCTIONS_RUSTY_HOOK_TEAMS": ""
"CDP_ASYNC_FUNCTIONS_RUSTY_HOOK_TEAMS": "",
"CDP_CYCLOTRON_ENABLED_TEAMS": "*"
},
"presentation": {
"group": "main"
Expand Down
6 changes: 6 additions & 0 deletions bin/migrate
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash
set -e
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")

# NOTE when running in docker, rust might not exist so we need to check for it
if [ -d "$SCRIPT_DIR/../rust" ]; then
bash $SCRIPT_DIR/../rust/bin/migrate-cyclotron
fi

python manage.py migrate
python manage.py migrate_clickhouse
Expand Down
2 changes: 1 addition & 1 deletion bin/start-cyclotron
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export RUST_LOG=${DEBUG:-debug}
SQLX_QUERY_LEVEL=${SQLX_QUERY_LEVEL:-warn}
export RUST_LOG=$RUST_LOG,sqlx::query=$SQLX_QUERY_LEVEL

export DATABASE_URL=${DATABASE_URL:-postgres://posthog:posthog@localhost:5432/posthog}
export DATABASE_URL=${CYCLOTRON_DATABASE_URL:-postgres://posthog:posthog@localhost:5432/cyclotron}
export ALLOW_INTERNAL_IPS=${ALLOW_INTERNAL_IPS:-true}

./target/debug/cyclotron-fetch &
Expand Down
3 changes: 2 additions & 1 deletion plugin-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"prettier:check": "prettier --check .",
"prepublishOnly": "pnpm build",
"setup:dev:clickhouse": "cd .. && DEBUG=1 python manage.py migrate_clickhouse",
"setup:test": "cd .. && TEST=1 python manage.py setup_test_environment",
"setup:test": "cd .. && TEST=1 python manage.py setup_test_environment && cd plugin-server && pnpm run setup:test:cyclotron",
"setup:test:cyclotron": "CYCLOTRON_DATABASE_NAME=test_cyclotron ../rust/bin/migrate-cyclotron",
"services:start": "cd .. && docker compose -f docker-compose.dev.yml up",
"services:stop": "cd .. && docker compose -f docker-compose.dev.yml down",
"services:clean": "cd .. && docker compose -f docker-compose.dev.yml rm -v",
Expand Down
14 changes: 11 additions & 3 deletions plugin-server/src/cdp/cdp-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { HogExecutor } from './hog-executor'
import { HogFunctionManager } from './hog-function-manager'
import { HogWatcher, HogWatcherState } from './hog-watcher'
import { HogFunctionInvocationResult, HogFunctionType, LogEntry } from './types'
import { createInvocation } from './utils'
import { createInvocation, queueBlobToString } from './utils'

export class CdpApi {
private hogExecutor: HogExecutor
Expand Down Expand Up @@ -144,11 +144,19 @@ export class CdpApi {
if (invocation.queue === 'fetch') {
if (mock_async_functions) {
// Add the state, simulating what executeAsyncResponse would do

// Re-parse the fetch args for the logging
const fetchArgs = {
...invocation.queueParameters,
body: queueBlobToString(invocation.queueBlob),
}

response = {
invocation: {
...invocation,
queue: 'hog',
queueParameters: { response: { status: 200, body: {} } },
queueParameters: { response: { status: 200 } },
queueBlob: Buffer.from('{}'),
},
finished: false,
logs: [
Expand All @@ -160,7 +168,7 @@ export class CdpApi {
{
level: 'info',
timestamp: DateTime.now(),
message: `fetch(${JSON.stringify(invocation.queueParameters, null, 2)})`,
message: `fetch(${JSON.stringify(fetchArgs, null, 2)})`,
},
],
}
Expand Down
Loading
Loading