Skip to content
This repository was archived by the owner on Nov 4, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
245 commits
Select commit Hold shift + click to select a range
254392a
Integrate fastify-postgres and fastify-kafka
Twixes Dec 2, 2020
7cd0ff5
Explicitly add node-rdkafka for its types
Twixes Dec 2, 2020
0b87dfb
Port UUIDT from Python
Twixes Dec 2, 2020
bb3f40a
Consume events from Kafka
Twixes Dec 2, 2020
d7448e5
Merge branch 'master' into ingestion-save
Twixes Dec 2, 2020
3a1412c
Update yarn.lock
Twixes Dec 2, 2020
be86920
Port handle_timestamp
Twixes Dec 2, 2020
43af8a0
Enhance startFastifyInstance with config
Twixes Dec 2, 2020
d2aaa2e
Prettier
Twixes Dec 2, 2020
7a15005
Handle dates with Luxon for similarity to Python's datetime
Twixes Dec 3, 2020
73d42d7
Fix UUIDT stringification
Twixes Dec 3, 2020
7f02e33
Port _capture_ee
Twixes Dec 3, 2020
8fd3e42
Create EventsProcessor with plugins server access
Twixes Dec 3, 2020
a122046
Rework ingestion to separate from Fastify, port over more Django
Twixes Dec 4, 2020
fca0ef9
Update utils.test.ts
Twixes Dec 4, 2020
bf88f22
Remove fastify-kafka and fastify-postgres
Twixes Dec 4, 2020
14fdf2c
Add protobuf
Twixes Dec 4, 2020
d2f42dd
Add types
Twixes Dec 4, 2020
dfb1454
Update yarn.lock
Twixes Dec 4, 2020
028c892
Improve info
Twixes Dec 4, 2020
239f904
Update server.ts
Twixes Dec 4, 2020
a3896f8
Port element functions
Twixes Dec 4, 2020
f9b88bb
Use Kafka producer stream and make overall optimizations
Twixes Dec 4, 2020
9f3bd13
Add session recording
Twixes Dec 4, 2020
2ba3353
Add plugin processing
Twixes Dec 4, 2020
4e8cbb0
Merge branch 'master' into ingestion-save
Twixes Dec 7, 2020
11700f6
Fix castTimestampOrNow
Twixes Dec 7, 2020
b18735e
Update yarn.lock
Twixes Dec 7, 2020
5ee99a5
Improve typing and consume event messages in batches of 100
Twixes Dec 7, 2020
a181259
Improve code clarity
Twixes Dec 7, 2020
2e7d476
Add timing with StatsD
Twixes Dec 7, 2020
9ae0f9a
Update style
Twixes Dec 7, 2020
698ddfa
Format
Twixes Dec 7, 2020
3488d04
Merge and alias
Twixes Dec 8, 2020
049feaf
Are last stuff
Twixes Dec 8, 2020
f4b7f97
Reimplement Protobuf with protos compiled to JS+TS
Twixes Dec 9, 2020
8a8fca2
Fix things
Twixes Dec 9, 2020
dfd1d46
Fix UUID#toString implementation
Twixes Dec 9, 2020
447fb3b
Update UUID number handling
Twixes Dec 9, 2020
75817b2
Merge branch 'master' into ingestion-save
Twixes Dec 9, 2020
a79b2bf
Unify
Twixes Dec 9, 2020
125f5e4
Prettier
Twixes Dec 9, 2020
0965844
Unify utils
Twixes Dec 9, 2020
79cd8fd
Merge branch 'master' into ingestion-save
Twixes Dec 9, 2020
11e95e2
Add newline
Twixes Dec 9, 2020
7a8f82a
Prettier but correctly
Twixes Dec 9, 2020
cdaf498
Fix types
Twixes Dec 9, 2020
b1c1523
Merge branch 'master' into ingestion-save
Twixes Dec 9, 2020
9e4745b
Improve types
Twixes Dec 9, 2020
3da3092
Bump version to 0.5.0
Twixes Dec 9, 2020
24a6fc8
Update worker.test.ts
Twixes Dec 9, 2020
5fa13a2
Merge branch 'master' into ingestion-save
Twixes Dec 9, 2020
7b50eef
Update types.ts
Twixes Dec 9, 2020
cc3de53
Update yarn.lock
Twixes Dec 9, 2020
528e57a
Merge branch 'master' into ingestion-save
Twixes Dec 9, 2020
182ea31
Update compile:protobuf with eslint --fix
Twixes Dec 9, 2020
c881fed
Fix typing
Twixes Dec 9, 2020
5da5bcb
Don't bump version
Twixes Dec 9, 2020
cae8ec8
Fix style
Twixes Dec 9, 2020
81b8605
Use @posthog/node-rdkafka for Worker thread support
Twixes Dec 9, 2020
918f9df
Improve logging
Twixes Dec 9, 2020
6662d2e
Unify Redis and Kafka approach to queuing events
Twixes Dec 10, 2020
abecf93
Merge branch 'master' into ingestion-save
Twixes Dec 10, 2020
427b89f
Fix consuming from Kafka
Twixes Dec 10, 2020
03b9eef
Make some optimizations
Twixes Dec 10, 2020
7f0b154
Merge branch 'master' into ingestion-save
Twixes Dec 10, 2020
f155291
Don't introduce KAFKA_EVENTS_HANDOFF
Twixes Dec 10, 2020
5dc8760
Consume 1 kiloevent / 50 ms = 20 kiloevents / s
Twixes Dec 11, 2020
35ecf02
Don't start web server by default
Twixes Dec 11, 2020
f851efa
Improve Redis logging
Twixes Dec 11, 2020
b4907ca
Fix connecting to dockerized Redis
Twixes Dec 11, 2020
c8f4d99
Merge branch 'master' into ingestion-save
Twixes Dec 11, 2020
15215ef
Update yarn.lock
Twixes Dec 11, 2020
0b774ed
Fix merge
Twixes Dec 11, 2020
6bec3ae
Clear Kafka consumption interval on graceful exit
Twixes Dec 14, 2020
511c40a
Improve logging and error handling
Twixes Dec 14, 2020
a83e254
Smooth out ingestion errors
Twixes Dec 14, 2020
f6db491
Merge branch 'master' into ingestion-save
Twixes Dec 14, 2020
cbec464
Fix StatsD prefixing
Twixes Dec 14, 2020
2bb8e78
Merge branch 'master' into ingestion-save
Twixes Dec 16, 2020
e13edac
Merge branch 'master' into ingestion-save
Twixes Jan 6, 2021
3a840e4
Move @types/luxon to devDependencies
Twixes Jan 7, 2021
e0bdb1c
Use Kafka.js Producer instead of node-rdkafka
Twixes Jan 8, 2021
5d2b69a
Merge branch 'master' into ingestion-save
Twixes Jan 8, 2021
e948f93
Use EventProto#encodeDelimited instead of #encode
Twixes Jan 11, 2021
d8e0b1e
Start UUIDT series from 0 instead of 1
Twixes Jan 12, 2021
77080d5
Use event UUID from Django server
Twixes Jan 12, 2021
74d667c
Make some fixes and improvements
Twixes Jan 12, 2021
156039b
Remove console.logs
Twixes Jan 12, 2021
81f01ed
Use plugin-scaffold 0.2.7
Twixes Jan 12, 2021
153893e
Fix style
Twixes Jan 12, 2021
e5b5892
Simplify compile:typescript
Twixes Jan 12, 2021
1ca29ba
await startQueue
Twixes Jan 12, 2021
81846ef
Clean up castTimestampOrNow
Twixes Jan 12, 2021
9a03a88
Don't use pesky ||=
Twixes Jan 12, 2021
4b3f3fd
Change consumer group to 'group1' from main repo
Twixes Jan 13, 2021
6d20d34
Revert "await startQueue"
Twixes Jan 13, 2021
26b5f44
Exit if queue failed to start
Twixes Jan 13, 2021
6dce496
Clean up elements handling
Twixes Jan 13, 2021
c5395c3
Merge branch 'master' into ingestion-save
Twixes Jan 13, 2021
3680481
Don't commit compiled protos
Twixes Jan 13, 2021
70c9e43
Rename consumer group to clickhouse-ingestion
Twixes Jan 13, 2021
f326b80
Consume from topic events_ingestion_handoff
Twixes Jan 15, 2021
5f1c17d
ee dev script
mariusandra Jan 15, 2021
737a8c7
Backport set_once and event name sanitization
Twixes Jan 19, 2021
bacf574
Add direct ClickHouse support base
Twixes Jan 19, 2021
757dd71
Upgrade plugin-scaffold to 0.2.8
Twixes Jan 19, 2021
732fb64
Add clickhouse to server object
Twixes Jan 19, 2021
915bdbf
Support ClickHouse persons and person distinct IDs
Twixes Jan 19, 2021
e49599a
Merge branch 'master' into ingestion-save
Twixes Jan 19, 2021
45aa41f
Update README with ClickHouse settings
Twixes Jan 19, 2021
49bbf72
Fix sanitizeEventName
Twixes Jan 19, 2021
8dca9a3
Await queue start
Twixes Jan 20, 2021
281e5d4
Prettier README
Twixes Jan 20, 2021
f153e87
Try ClickHouse CI skeleton
Twixes Jan 20, 2021
96bb543
Merge branch 'master' into ingestion-save
Twixes Jan 20, 2021
bdf9770
Update yarn.lock
Twixes Jan 20, 2021
c0a2e41
Possibly fix CI
Twixes Jan 20, 2021
a4474b5
Revert basic tests job to old name
Twixes Jan 20, 2021
0656a68
Cache pip install
Twixes Jan 20, 2021
314de74
Fix ClickHouse teardown and add Yarn installation
Twixes Jan 20, 2021
caf4d13
Await startQueue in tests
Twixes Jan 20, 2021
201afc9
Try existing test in new workflow
Twixes Jan 20, 2021
ec49e2c
Don't cache pip requirements
Twixes Jan 20, 2021
e6418d9
Add Redis to CH CI
Twixes Jan 20, 2021
7ee02ab
Make some env var changes
Twixes Jan 20, 2021
39f1899
Try test_default as Django test DB name
Twixes Jan 20, 2021
06b34de
Try test_posthog as Django test DB name
Twixes Jan 20, 2021
7fa5f11
Don't tear down ClickHouse
Twixes Jan 20, 2021
07bfd29
Make env vars common to all tests-clickhouse steps
Twixes Jan 20, 2021
0ab380b
Debug Postgres
Twixes Jan 20, 2021
e8d7960
Debug Postgres actually
Twixes Jan 20, 2021
111ff77
Revert "Make env vars common to all tests-clickhouse steps"
Twixes Jan 20, 2021
e9cbf7d
Try fixing DB name discrepancy
Twixes Jan 20, 2021
3f5222a
Make some env vars common
Twixes Jan 20, 2021
f0cf916
Debug Postgres better
Twixes Jan 20, 2021
974327d
Remove Postgres debug code
Twixes Jan 20, 2021
b8adacb
Fix inserting
Twixes Jan 20, 2021
3fc0b8d
Fix posthog_team.app_urls
Twixes Jan 20, 2021
171a691
Catch insertRow errors
Twixes Jan 20, 2021
3f3f440
Add plugin.organization_id in base tests
Twixes Jan 21, 2021
d37c485
DELETE FROM posthog_organization
Twixes Jan 21, 2021
59692a4
Rework CI to use Django everywhere
Twixes Jan 21, 2021
4dff30e
Reorder tests for readability
Twixes Jan 21, 2021
1af9230
Fix missing KAFKA_HOSTS in CI
Twixes Jan 21, 2021
cebddb4
Optimize createPosthog
Twixes Jan 21, 2021
986c37d
Start separating Postgres- and ClickHouse-based suites
Twixes Jan 21, 2021
4df3b3c
Fix regexes possibly
Twixes Jan 21, 2021
2a260fb
Fix regexes actually possibly
Twixes Jan 21, 2021
e0000f3
Improve fatal error handling
Twixes Jan 21, 2021
7778de2
Merge branch 'master' into ingestion-save
Twixes Jan 21, 2021
8800967
Fix type
Twixes Jan 21, 2021
ffe1977
Fix import
Twixes Jan 21, 2021
bc832b7
Debug Kafka queue crash
Twixes Jan 21, 2021
5164d18
Debug consumer
Twixes Jan 21, 2021
b0e5ba5
Fix organizationId
Twixes Jan 21, 2021
77c0c41
Make some more suites Postgres-specific
Twixes Jan 21, 2021
99d3715
Merge branch 'master' into ingestion-save
Twixes Jan 21, 2021
76ea34e
Check out master branch of main repo of Django server in CI
Twixes Jan 21, 2021
b08d847
Merge branch 'master' into ingestion-save
Twixes Jan 22, 2021
0abb0ea
Start schedule before queue
Twixes Jan 22, 2021
8d0187e
Clean up logging
Twixes Jan 22, 2021
db20056
Merge branch 'master' into ingestion-save
Twixes Jan 22, 2021
4acac58
Update Dockerfile
Twixes Jan 22, 2021
6982d46
Merge branch 'master' into ingestion-save
Twixes Jan 25, 2021
6ada689
Refactor Postgres processing to DB class
Twixes Jan 25, 2021
13f5e31
Use more of DB methods
Twixes Jan 25, 2021
07fb5e1
Quit Redis
Twixes Jan 25, 2021
19c8f7e
Update test database name
Twixes Jan 25, 2021
cc094c4
Debug consumer
Twixes Jan 25, 2021
c139cf1
Don't mock KafkaJS!
Twixes Jan 25, 2021
958f24c
Add new Kafka testing system incomplete
Twixes Jan 26, 2021
9d52684
Clean up new testing system
Twixes Jan 26, 2021
242d3d0
Make prettier compatible with ESLint
Twixes Jan 26, 2021
21dc1a9
Add compatibility with Plugin.latest_tag in test
Twixes Jan 26, 2021
99cc356
Merge branch 'master' into ingestion-save
Twixes Jan 26, 2021
c759e42
Fix minor issues
Twixes Jan 26, 2021
85b4462
Try not terminating program on Kafka consumer crash
Twixes Jan 26, 2021
c2901db
Change KAFKA_ADVERTISED_HOST_NAME to localhost
Twixes Jan 26, 2021
9d3c72e
Address feedback
Twixes Jan 26, 2021
e344542
Separate Postgres and DB classes
Twixes Jan 26, 2021
0b0ba88
Consume from kafka_events topic in KafkaObserver
Twixes Jan 26, 2021
f583448
Fix process-event test file name
Twixes Jan 26, 2021
b02c08a
Check for UUID in handed off events
Twixes Jan 26, 2021
e9000d0
Return from EventsProcessor.processEvent
Twixes Jan 26, 2021
2199a79
use `db.postgresQuery` instead of vague `db.query`
mariusandra Jan 26, 2021
510b2d7
Run the plugins suite universally
Twixes Jan 26, 2021
18e58ef
Fix closeServer
Twixes Jan 26, 2021
ccf31bc
javaScriptVariableCase
mariusandra Jan 26, 2021
2dd58ef
Capture handleTimestamp error with Sentry
Twixes Jan 26, 2021
c6cedd2
Hand off message in test
Twixes Jan 26, 2021
ec8ebb5
Fix plugins suite imports
Twixes Jan 26, 2021
966056f
Run the vm suite universally
Twixes Jan 26, 2021
0eed9c2
more javaScriptVariableCase
mariusandra Jan 26, 2021
9accf49
Merge branch 'ingestion-save' of github.com:PostHog/posthog-plugin-se…
mariusandra Jan 26, 2021
e9f6134
disconnect without waiting for pending replies (.diconnect() instead …
mariusandra Jan 26, 2021
e064580
dot quit seems to work better?
mariusandra Jan 26, 2021
4297552
Add sanitizeSqlIdentifier
Twixes Jan 27, 2021
381dfff
Fix updating person properties
Twixes Jan 27, 2021
b4e66c5
Fix problems
Twixes Jan 27, 2021
53bfc07
Don't use status in piscina.js
Twixes Jan 27, 2021
076700a
Revert "Run the vm suite universally"
Twixes Jan 27, 2021
e3b8350
Fix sanitizeSqlIdentifier test
Twixes Jan 27, 2021
6baed18
Use waitForProcessedMessages
Twixes Jan 27, 2021
43515af
Optimize updatePersonProperties
Twixes Jan 27, 2021
12af463
Rework DummyPostHog to capturing internal server events efficiently
Twixes Jan 27, 2021
42124f4
Fix nested test files not being ran
Twixes Jan 27, 2021
30f08b6
Run prettier over Markdown
Twixes Jan 27, 2021
8b4a905
Fix mock paths
Twixes Jan 27, 2021
839ff1e
Fix issues
Twixes Jan 27, 2021
0de3ebb
Fix some
Twixes Jan 27, 2021
25035c8
Don't truncate Kafka tables
Twixes Jan 27, 2021
b443240
Start kafkaObserver inside test
Twixes Jan 27, 2021
ba2b3bc
Support Team.is_demo
Twixes Jan 27, 2021
64ba573
Increase process-event tests timeout to 60 s
Twixes Jan 27, 2021
816c727
Cache Python location in ClickHouse CI
Twixes Jan 27, 2021
438fa3b
Debug KafkaObserver
Twixes Jan 27, 2021
f9364ad
Cache pip in all CI jobs
Twixes Jan 27, 2021
99afcf5
Add bash script for running tests locally
Twixes Jan 27, 2021
f7fe1f4
Try out a different way of watching Kafka messages
Twixes Jan 27, 2021
6449873
Simplify DummyPostHog back again
Twixes Jan 28, 2021
68ce77e
Use posthog-js-lite in EventsProcessor
Twixes Jan 28, 2021
f12419c
Sanitize SQL identifiers more strictly
Twixes Jan 28, 2021
a662dd7
Don't resolve KafkaObserver start before connection
Twixes Jan 28, 2021
9c60fa9
Add ee.tasks.webhooks_ee.post_event_to_webhook_ee
Twixes Jan 28, 2021
52dc915
Expect Client to have been called twice
Twixes Feb 1, 2021
5b291b7
Adjust resetTestDatabase for Organization.personalization
Twixes Feb 1, 2021
9856cd4
Update Cliient call asserts
Twixes Feb 1, 2021
3090e4a
Postgres ingestion + process event tests (#116)
mariusandra Feb 1, 2021
186fe41
Merge branch 'master' into ingestion-save
Twixes Feb 1, 2021
5a1e69e
postgres e2e ingestion test (#120)
mariusandra Feb 1, 2021
1efbc9b
Kafka e2e tests (#121)
mariusandra Feb 3, 2021
cbcc66a
Merge branch 'master' into ingestion-save
Twixes Feb 3, 2021
345c275
Update README.md with PLUGIN_SERVER_INGESTION
Twixes Feb 3, 2021
15903a9
rename CLICKHOUSE_USERNAME --> CLICKHOUSE_USER for consistency with t…
mariusandra Feb 3, 2021
bde20a7
Delete run-tests-locally.sh
Twixes Feb 3, 2021
b15c61a
Resolve all kafka offsets (#124)
mariusandra Feb 4, 2021
8001e2c
Add KAFKA_INCOMING_TOPIC and clean up unused code (#125)
mariusandra Feb 4, 2021
bec6bfb
Postgres parity tests (#126)
mariusandra Feb 4, 2021
947c8ba
Remove "_handoff" from Kafka topic (#127)
mariusandra Feb 4, 2021
5a177d0
User merge test (#129)
mariusandra Feb 4, 2021
34de94e
remove "_HANDOFF"
mariusandra Feb 4, 2021
daa2875
small comment
mariusandra Feb 4, 2021
94d622c
Merge branch 'ingestion-save' of github.com:PostHog/posthog-plugin-se…
mariusandra Feb 4, 2021
849bbd4
Switch ClickHouse driver (#128)
Twixes Feb 4, 2021
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
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: ['plugin:@typescript-eslint/recommended', 'prettier/@typescript-eslint'],
extends: ['plugin:@typescript-eslint/recommended', 'prettier', 'prettier/@typescript-eslint', 'prettier/react'],
ignorePatterns: ['bin', 'dist', 'node_modules'],
rules: {
'@typescript-eslint/no-unused-vars': 'off',
Expand Down
109 changes: 107 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,15 @@ jobs:
with:
node-version: 14

- uses: actions/cache@v2
with:
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ hashFiles('posthog/requirements.txt') }}

- name: Install requirements.txt dependencies with pip
run: python -m pip install --upgrade pip && python -m pip install -r posthog/requirements.txt
run: |
pip install --upgrade pip
pip install --upgrade --upgrade-strategy eager -r posthog/requirements.txt

- name: Set up databases
env:
Expand All @@ -93,6 +100,97 @@ jobs:
REDIS_URL: 'redis://localhost'
run: cd plugin-server && yarn test:postgres

tests-clickhouse:
name: Tests / ClickHouse + Kafka
runs-on: ubuntu-20.04

services:
postgres:
image: postgres:12
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test_posthog
ports: ['5432:5432']
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
redis:
image: redis
ports:
- '6379:6379'
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5

env:
REDIS_URL: 'redis://localhost'
CLICKHOUSE_HOST: 'localhost'
CLICKHOUSE_DATABASE: 'posthog_test'
KAFKA_ENABLED: 'true'
KAFKA_HOSTS: 'kafka:9092'

steps:
- name: Check out Django server for database setup
uses: actions/checkout@v2
with:
repository: 'PostHog/posthog'
path: 'posthog/'

- name: Check out plugin server
uses: actions/checkout@v2
with:
path: 'plugin-server'

- name: Fix Kafka Hostname
run: |
sudo bash -c 'echo "127.0.0.1 kafka zookeeper" >> /etc/hosts'
ping -c 1 kafka
ping -c 1 zookeeper

- name: Start Kafka, Clickhouse, Zookeeper
run: |
cd posthog/ee
docker-compose -f docker-compose.ch.yml up -d zookeeper kafka clickhouse

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Set up Node 14
uses: actions/setup-node@v2
with:
node-version: 14

- uses: actions/cache@v2
with:
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ hashFiles('posthog/requirements.txt') }}

- name: Install requirements.txt dependencies with pip
run: |
pip install --upgrade pip
pip install --upgrade --upgrade-strategy eager -r posthog/requirements.txt

- name: Set up databases
env:
SECRET_KEY: 'abcdef' # unsafe - for testing only
DATABASE_URL: 'postgres://postgres:postgres@localhost:5432/posthog'
PRIMARY_DB: 'clickhouse'
TEST: 'true'
run: python posthog/manage.py setup_test_environment

- name: Install package.json dependencies with Yarn
run: cd plugin-server && yarn

- name: Test with Jest
env:
# Below DB name has `test_` prepended, as that's how Django (ran above) creates the test DB
DATABASE_URL: 'postgres://postgres:postgres@localhost:5432/test_posthog'
REDIS_URL: 'redis://localhost'
run: cd plugin-server && yarn test:clickhouse

benchmarks-postgres:
name: Benchmarks / Postgres + Redis
runs-on: ubuntu-20.04
Expand Down Expand Up @@ -141,8 +239,15 @@ jobs:
with:
node-version: 14

- uses: actions/cache@v2
with:
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ hashFiles('posthog/requirements.txt') }}

- name: Install requirements.txt dependencies with pip
run: python -m pip install --upgrade pip && python -m pip install -r posthog/requirements.txt
run: |
pip install --upgrade pip
pip install --upgrade --upgrade-strategy eager -r posthog/requirements.txt

- name: Set up databases
env:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ yarn-error.log
dist/
.yalc/
yalc.lock
src/idl/protos.*
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ FROM node:14
WORKDIR /code

COPY package.json yarn.lock .eslintrc.js .prettierrc ./
COPY src/idl/ src/idl/
RUN yarn install --frozen-lockfile

COPY ./ ./
RUN yarn compile
RUN yarn compile:typescript

CMD [ "node", "dist/src/index.js" ]
56 changes: 32 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,38 @@ Let's get you developing the plugin server in no time:

There's a multitude of settings you can use to control the plugin server. Use them as environment variables.

| Name | Description | Default value |
| ----------------------------- | ---------------------------------------------------------- | ------------------------------------- |
| DATABASE_URL | Postgres database URL | `'postgres://localhost:5432/posthog'` |
| REDIS_URL | Redis store URL | `'redis://localhost'` |
| BASE_DIR | base path for resolving local plugins | `'.'` |
| WORKER_CONCURRENCY | number of concurrent worker threads | `0` – all cores |
| TASKS_PER_WORKER | number of parallel tasks per worker thread | `10` |
| SCHEDULE_LOCK_TTL | How many seconds to hold the lock for the schedule | `60` |
| CELERY_DEFAULT_QUEUE | Celery outgoing queue | `'celery'` |
| PLUGINS_CELERY_QUEUE | Celery incoming queue | `'posthog-plugins'` |
| PLUGINS_RELOAD_PUBSUB_CHANNEL | Redis channel for reload events | `'reload-plugins'` |
| KAFKA_ENABLED | use Kafka instead of Celery to ingest events | `false` |
| KAFKA_HOSTS | comma-delimited Kafka hosts | `null` |
| KAFKA_CLIENT_CERT_B64 | Kafka certificate in Base64 | `null` |
| KAFKA_CLIENT_CERT_KEY_B64 | Kafka certificate key in Base64 | `null` |
| KAFKA_TRUSTED_CERT_B64 | Kafka trusted CA in Base64 | `null` |
| DISABLE_WEB | whether to disable web server | `true` |
| WEB_PORT | port for web server to listen on | `3008` |
| WEB_HOSTNAME | hostname for web server to listen on | `'0.0.0.0'` |
| LOG_LEVEL | minimum log level | `LogLevel.Info` |
| SENTRY_DSN | Sentry ingestion URL | `null` |
| STATSD_HOST | StatsD host - integration disabled if this is not provided | `null` |
| STATSD_PORT | StatsD port | `8125` |
| STATSD_PREFIX | StatsD prefix | `'plugin-server.'` |
| Name | Description | Default value |
| ----------------------------- | ------------------------------------------------------------------- | ------------------------------------- |
| DATABASE_URL | Postgres database URL | `'postgres://localhost:5432/posthog'` |
| REDIS_URL | Redis store URL | `'redis://localhost'` |
| BASE_DIR | base path for resolving local plugins | `'.'` |
| WORKER_CONCURRENCY | number of concurrent worker threads | `0` – all cores |
| TASKS_PER_WORKER | number of parallel tasks per worker thread | `10` |
| SCHEDULE_LOCK_TTL | How many seconds to hold the lock for the schedule | `60` |
| CELERY_DEFAULT_QUEUE | Celery outgoing queue | `'celery'` |
| PLUGINS_CELERY_QUEUE | Celery incoming queue | `'posthog-plugins'` |
| PLUGINS_RELOAD_PUBSUB_CHANNEL | Redis channel for reload events | `'reload-plugins'` |
| PLUGIN_SERVER_INGESTION | Whether the plugin server should put events right into the database | `false` |
| CLICKHOUSE_HOST | ClickHouse host | `'localhost'` |
| CLICKHOUSE_DATABASE | ClickHouse database | `'default'` |
| CLICKHOUSE_USER | ClickHouse username | `'default'` |
| CLICKHOUSE_PASSWORD | ClickHouse password | `null` |
| CLICKHOUSE_CA | ClickHouse CA certs | `null` |
| CLICKHOUSE_SECURE | Secure ClickHouse connection | `false` |
| KAFKA_ENABLED | use Kafka instead of Celery to ingest events | `false` |
| KAFKA_HOSTS | comma-delimited Kafka hosts | `null` |
| KAFKA_CONSUMPTION_TOPIC | Kafka consumption topic override | `null` (automatic) |
| KAFKA_CLIENT_CERT_B64 | Kafka certificate in Base64 | `null` |
| KAFKA_CLIENT_CERT_KEY_B64 | Kafka certificate key in Base64 | `null` |
| KAFKA_TRUSTED_CERT_B64 | Kafka trusted CA in Base64 | `null` |
| DISABLE_WEB | whether to disable web server | `true` |
| WEB_PORT | port for web server to listen on | `3008` |
| WEB_HOSTNAME | hostname for web server to listen on | `'0.0.0.0'` |
| LOG_LEVEL | minimum log level | `LogLevel.Info` |
| SENTRY_DSN | Sentry ingestion URL | `null` |
| STATSD_HOST | StatsD host - integration disabled if this is not provided | `null` |
| STATSD_PORT | StatsD port | `8125` |
| STATSD_PREFIX | StatsD prefix | `'plugin-server.'` |

## Questions?

Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module.exports = {
testEnvironment: 'node',
clearMocks: true,
coverageProvider: 'v8',
setupFilesAfterEnv: ['./jest.setup.kafka-mock.js', './jest.setup.fetch-mock.js'],
setupFilesAfterEnv: ['./jest.setup.fetch-mock.js'],
testMatch: ['<rootDir>/tests/**/*.test.ts', '<rootDir>/benchmarks/**/*.benchmark.ts'],
}
1 change: 0 additions & 1 deletion jest.setup.kafka-mock.js

This file was deleted.

27 changes: 19 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,29 @@
"types": "dist/src/index.d.ts",
"main": "dist/src/index.js",
"scripts": {
"test": "jest --runInBand tests/*.test.ts",
"test:postgres": "yarn test --testPathIgnorePatterns '.*/clickhouse'",
"test:clickhouse": "yarn test --testPathIgnorePatterns '.*/postgres'",
"test": "jest --runInBand tests/**/*.test.ts",
"test:postgres": "jest --runInBand tests/postgres/*.test.ts tests/*.test.ts",
"test:clickhouse": "jest --runInBand tests/clickhouse/*.test.ts",
"benchmark": "node --expose-gc node_modules/.bin/jest --runInBand benchmarks/",
"start": "yarn start:dev",
"start:dist": "node dist/src/index.js --base-dir ../posthog",
"start:dev": "ts-node-dev --exit-child src/index.ts --base-dir ../posthog",
"start:dev:ee": "KAFKA_ENABLED=true KAFKA_HOSTS=localhost:9092 yarn start:dev",
"build": "yarn clean && yarn compile",
"clean": "rimraf dist/*",
"compile": "tsc -p .",
"compile:protobuf": "cd src/idl/ && rimraf protos.* && pbjs -t static-module -w commonjs -o protos.js *.proto && pbts -o protos.d.ts protos.js && eslint --fix . && prettier --write .",
"compile:typescript": "tsc",
"compile": "yarn compile:protobuf && yarn compile:typescript",
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"prettier": "prettier --write .",
"prettier:check": "prettier --check .",
"prepublishOnly": "yarn build"
"prepare": "yarn compile:protobuf",
"prepublishOnly": "yarn build",
"setup:dev:clickhouse": "cd ../posthog && export DEBUG=1 PRIMARY_DB=clickhouse && source env/bin/activate && python manage.py migrate_clickhouse",
"setup:test:ee": "yarn setup:test:postgres && yarn setup:test:clickhouse",
"setup:test:postgres": "cd ../posthog && (dropdb test_posthog || echo 'no db to drop') && createdb test_posthog && source env/bin/activate && DATABASE_URL=postgres://localhost:5432/test_posthog DEBUG=1 python manage.py migrate",
"setup:test:clickhouse": "cd ../posthog && export TEST=1 PRIMARY_DB=clickhouse CLICKHOUSE_DATABASE=posthog_test && source env/bin/activate && python manage.py migrate_clickhouse"
},
"bin": {
"posthog-plugin-server": "bin/posthog-plugin-server"
Expand All @@ -29,9 +37,9 @@
"license": "MIT",
"dependencies": {
"@google-cloud/bigquery": "^5.5.0",
"@posthog/clickhouse": "^1.7.0",
"@sentry/node": "^5.29.0",
"@sentry/tracing": "^5.29.0",
"@types/luxon": "^1.25.0",
"adm-zip": "^0.4.16",
"fastify": "^3.8.0",
"hot-shots": "^8.2.1",
Expand All @@ -42,6 +50,8 @@
"node-schedule": "^1.3.2",
"pg": "^8.4.2",
"piscina": "^2.1.0",
"posthog-js-lite": "^0.0.5",
"protobufjs": "^6.10.2",
"redlock": "^4.2.0",
"tar-stream": "^2.1.4",
"uuid": "^8.3.1",
Expand All @@ -53,10 +63,11 @@
"@babel/core": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-typescript": "^7.8.3",
"@posthog/plugin-scaffold": "0.2.6",
"@posthog/plugin-scaffold": "0.2.8",
"@types/adm-zip": "^0.4.33",
"@types/ioredis": "^4.17.7",
"@types/jest": "^26.0.15",
"@types/luxon": "^1.25.0",
"@types/node": "^14.14.6",
"@types/node-fetch": "^2.5.7",
"@types/node-schedule": "^1.3.1",
Expand Down Expand Up @@ -95,6 +106,6 @@
},
"lint-staged": {
"*.{js,ts}": "eslint --fix",
"*.{js,ts,css,scss,json,yml}": "prettier --write"
"*.{js,ts,css,scss,json,yml,md}": "prettier --write"
}
}
4 changes: 2 additions & 2 deletions src/celery/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,14 @@ export class Worker extends Base implements Queue {
throw new Error(`Missing process handler for task ${taskName}`)
}

console.info(
console.debug(
`celery.node Received task: ${taskName}[${taskId}], args: ${args}, kwargs: ${JSON.stringify(kwargs)}`
)

const timeStart = process.hrtime()
const taskPromise = handler(...args, kwargs).then((result) => {
const diff = process.hrtime(timeStart)
console.info(
console.debug(
`celery.node Task ${taskName}[${taskId}] succeeded in ${diff[0] + diff[1] / 1e9}s: ${result}`
)
this.activeTasks.delete(taskPromise)
Expand Down
Loading