0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-12-01 12:21:02 +01:00
Commit Graph

148 Commits

Author SHA1 Message Date
Michael Matloka
313226838c
revert: revert: Revert person properties updates refactor (#10349)
* Revert "revert: Revert person properties updates refactor (#10348)"

This reverts commit 6b3c4691b3.

* sanitizeEvent -> normalizeEvent

* Ensure we handle property updates from within plugins, test

Co-authored-by: Karl-Aksel Puulmann <oxymaccy@gmail.com>
2022-06-20 09:49:11 +03:00
Neil Kakkar
6b3c4691b3
revert: Revert person properties updates refactor (#10348) 2022-06-17 17:48:20 +02:00
Karl-Aksel Puulmann
faa425e991
fix(data-integrity): race condition merging people (#10340)
Issue: https://github.com/PostHog/posthog/issues/10337

Previously when emitting an $identify event which would result in a
merge and would have with $set/$set_once, plugin-server would:
1. Merge the two peoples properties
2. Update person properties separately

This causes a race as a single event-pipeline flow would emit two
different person update rows to clickhouse, with no guarantees which one
would win due to identical _timestamps.

We eliminate the need to double-update in a single message and add
tests.
2022-06-17 14:29:28 +03:00
Karl-Aksel Puulmann
c00e81fc88
fix(data-integrity): race condition when creating users with $identify events (#10328)
* Update person-state to return person

* Add personState#update for joint updates

* Create personManager on hub

* Fix bug when $identify is the first user event

Bug was this:
1. We tried to create person with blank properties, later update the
properties separately.
2. This resulted in two kafka messages with identical _timestamps due to
batching
3. There was a 50/50 chance that the event would not be handled properly

We now don't create multiple messages if not needed. I also added tests
to person-state, but not exhaustive ones.

Also fixed an issue with `setIsIdentified` being called too many times

Main issue: https://github.com/PostHog/posthog/issues/10208

* Fixup - avoid errors

* Set time limit

* Re-add distinct_id as argument to fix tests

* Remove unneeded .toString()

* Fix is_identified as identified by tests

* Bump testTimeout
2022-06-17 11:30:10 +03:00
Karl-Aksel Puulmann
d6ec3aedc6
refactor(plugin-server): person state updating (#10321)
* Remove some excessive call signatures

* refactor: move property sanitization outside of .capture

* Move event sanitization into event sanitization logic

* Move person creation/updating logic outside of capture/createSnapshot

* refactor: remove personManager from arguments

* refactor: remove various properties from arguments

* Update `handleIdentifyOrAlias` signature

* refactor: inline timeoutGuard into personStateManager

* refactor: prefix pipeline steps with indexes

* Extract timestamp parsing logic from process-event.ts

* refactor: move timestamp tests over from process-event.ts

* refactor: update process-event.test.ts

* refactor: person-state-manager -> person-state

* Move sanitizeEvent to a more suitable module

* Fix some process-event tests
2022-06-17 09:17:08 +03:00
Michael Matloka
20fcf3cd3f
feat(apps): Support retries with RetryError in onEvent, onSnapshot, and onAction (#10285)
* Combine `runOnEvent` and `runOnSnapshot`

* Commoditize `RetryError` handling and use it in `on*` functions

* Fix names of custom errors

* Fix `runProcessEvent` signature

* Separate `runOnEvent` and `runOnSnapshot` again

* Fix `runRetriableFunction`

* Refactor `getPluginsForTeam` into `getPluginMethodsForTeam`

* Create retries.test.ts

* Remove debug code

* Fix formatting

* Put `runRetriableFunction` and `getNextRetryMs` in `retries.ts`

* Rework `runRetriableFunction` to void subsequent retries

* Capture `iterateRetryLoop` exceptions

* Fix total timing

* Fix an import

* Remove useless `teamIdString`

* Fix another import

* Revert small refactor

* Add `getNextRetryMs` tests

* Use `PromiseManager`
2022-06-16 15:24:59 +02:00
Michael Matloka
6da951d2d1
fix(apps): Avoid zombie plugin VMs (#10299)
* fix(apps): Avoid zombie plugin VMs

* Add `plugin_disabled_by_system` metric
2022-06-15 14:55:45 +02:00
Karl-Aksel Puulmann
b4fee54222
refactor(plugin-server): extract person creation/handling logic from EventsProcessor (#10271)
* refactor: Start with PersonStateManager

* refactor: move createPerson to new service

* refactor: move team fetching before aliasing

* refactor: move `createPersonIfDistinctIdIsNew`

* refactor: move `updatePersonProperties`

* refactor: move `handleIdentifyOrAlias`

* refactor: `createPerson` to private

* Fix an import

* Remove weird mocking in an e2e integration test
2022-06-14 11:51:58 +03:00
Karl-Aksel Puulmann
c51a2f7bc1
fix(plugin-server): use histogram in metrics properly (#10276) 2022-06-13 16:48:57 +03:00
Karl-Aksel Puulmann
ebfc8251a7
fix(plugin-server): Properly set version in deletePerson (#10207)
* Use correct style for querying postgres

* Add test showing problems with deletePerson logic

* Fix deleting persons from clickhouse

* Fix concurrent tests

* Version + 100

* Fixup FINAL

* Remove console.log
2022-06-13 12:58:44 +03:00
Michael Matloka
a2a3944881
feat(apps): Make setupPlugin errors RetryError-only and send "fatal app error" email (#10187)
* Reorder blocks in `member_join.html` to make sense

* Add Celery task to send "fatal app error" email

* Add fallback to `Plugin.__str__` if `name` is empty

* Add lightweight `celeryApplyAsync` to `DB`

* Refactor `LazyPluginVM` to send "fatal app error" email

* Add tests

* Update email punctuation

* Update comment to be accurate

* Address feedback

* Add comment
2022-06-09 12:55:28 +00:00
Tiina Turban
569b50b4ec
feat(plugin-server): batching ingestion events to single process per distinct id (#10071) 2022-06-08 19:20:40 +02:00
Yakko Majuri
004ba66349
fix: pass ISO timestamp to onAction/onEvent (#10178)
* fix: pass ISO timestamp to onAction/onEvent

* fix prettier

* fix import

* update timestamps
2022-06-08 11:05:54 +00:00
Karl-Aksel Puulmann
6a6faf600e
fix(plugin-server): chain-to-elements regular expression behavior (#10170)
* refactor tests to be more extensible

* Move elements-related code to separate file

* Copy over tests for element chain

* Handle `undefined` match group

As this test from python indicates, the right-most match group may be
empty. In javascript the behavior for this is different from python and
the match group may be `undefined`

* Update import

* Fix http capabilities
2022-06-07 15:13:25 +03:00
Karl-Aksel Puulmann
44c6eaa368
refactor: simplify current env checks (#10162)
I was seeing a lot of repeated code so decided to clean it up
2022-06-07 13:07:13 +02:00
Karl-Aksel Puulmann
c3c5eaad02
fix(plugin-server): properly unparse event.properties when PLUGIN_SERVER_MODE=async (#10156)
* Handle string properties in plugin-server convertToIngestionEvent

* Update typing

* fix: Add multi-server process event test

This got accidentally yeeted from my previous PR. Shame!

* Improve tests

* Update test to reflect reality
2022-06-07 13:42:07 +03:00
Karl-Aksel Puulmann
59797efce8
refactor(plugin-server): yeet element-group related postgres code (#10161) 2022-06-07 12:23:20 +03:00
Tiina Turban
95c9045cc1
fix: Postgres and CH Person version across other columns to match (#10135) 2022-06-06 17:57:03 +02:00
Tiina Turban
26435cb70d
feat: Add version column to person in CH (#10117) 2022-06-06 13:42:39 +02:00
Yakko Majuri
1947fc11b8
perf: remove redlock from job queues (#10126)
This reverts commit 4455b87dcc.
2022-06-06 10:03:35 +00:00
Michael Matloka
64317238e6
refactor: Eliminate the KAFKA_ENABLED setting (#10059)
* refactor: Eliminate the `KAFKA_ENABLED` setting

* Remove dead code

* Consolidate plugin server test scripts and CI

* Fix CI command

* Remove Celery queues

* Rearrange test directories

* Update import paths
2022-05-30 18:39:33 +00:00
Tiina Turban
735ceb33a5
refactor(plugin-server): yeet postgres plugin logs (#9881)
* refactor(plugin-server): yeet postgres plugin logs

* forgotten usage

* Remove more Postgres `PluginLogEntry` code

* Modernize tests

* Wait for `KafkaEngine` in `console.test.ts`

* Fix formatting

* Add `resetKafka`

* Update console.test.ts

* Update style

* Use `delayUntilEventIngested` and improve its ergonomics

* Fix tests

* Refactor `test:postgres:2` away

* Fix and optimize `console.test.ts`

* Rearrange things a little bit

* Revert "Fix and optimize `console.test.ts`"

This reverts commit 273dbc1244.

* Rework `console` test to avoid Kafka

* Update `vm.test.ts` to spy on `queueSingleJsonMessage`

* Improve `.queueSingleJsonMessage()` typing

* Try to fix `moveDistinctIds & deletePerson`

Co-authored-by: Michael Matloka <dev@twixes.com>
2022-05-30 13:09:13 +03:00
Yakko Majuri
4455b87dcc
Revert "perf: remove redlock from job queues (#10033)" (#10046)
This reverts commit bc58936af9.
2022-05-27 16:09:42 +02:00
Yakko Majuri
bc58936af9
perf: remove redlock from job queues (#10033)
* fix: remove redlock from job queues

* bring back the error handling

* update tests

* fixes
2022-05-27 12:57:17 +02:00
Yakko Majuri
7e3c47ed7c
refactor: can not -> cannot (#10034) 2022-05-27 12:11:31 +02:00
Karl-Aksel Puulmann
5557b386b1
fix: node-js warning in plugin-server tests (#10007)
This code was causing warnings to be logged in the test suite
2022-05-26 13:40:09 +03:00
Karl-Aksel Puulmann
77c40da0a6
feat: track event pipeline entry points (#10004) 2022-05-26 09:12:12 +00:00
Karl-Aksel Puulmann
cb5e2b2643
fix(persons): properly update and unset properties (#9974)
* Remove test logging

* Support unsetting person properties in the plugin server

* Update persons via clickhouse

Note that this doesn't support deleting person properties yet due to
limitations on CH side.

https://github.com/PostHog/posthog/issues/9856

* Separate endpoint for deleting user properties

* Tests for person property updating/unsetting

* Fix eslint

* Fix a previous test

* Fixup

* dont update postgres for property updates

* Add toast
2022-05-26 09:07:59 +03:00
Michael Matloka
143e8e31c3
style: Reduce ESLint false positives (#9964)
* style: Make JS linting more accurate

* Don't lint autogenerated code
2022-05-25 14:38:44 +00:00
Karl-Aksel Puulmann
8f8ae3674f
fix(plugin-server): make console.log e2e test not racy (#9988) 2022-05-25 15:52:54 +02:00
Karl-Aksel Puulmann
f2ddc532d3
feat(plugin-server): Allow running plugin server in a different mode (#9946)
* Add PLUGIN_SERVER_MODE

* Make capabilities dependent on PLUGIN_SERVER_MODE

* Subscribe to kafka-events topic

* runAsyncHandlersEventPipeline

* Test fixup: fix typing error

* Test fixup: flush right after queueing message

* Parse clickhouse event correctly

* Different consumer group ids for kafka queue based on mode

* Set different prompts for different modes

* Capability for http, disabled in tests

* Elements chain handling in async ingestion

* Test for runner.test.ts

* Update a snapshot

* Update plugin-server/README.md

Co-authored-by: Yakko Majuri <38760734+yakkomajuri@users.noreply.github.com>

* Solve review-related issues

* Fix a test

* Fix imports

* Capabilities test fix

* Update tests

Co-authored-by: Yakko Majuri <38760734+yakkomajuri@users.noreply.github.com>
2022-05-25 14:50:36 +03:00
Karl-Aksel Puulmann
b7c045117e
fix(plugin-server): make e2e clickhouse ingestion › console logging is persistent not flaky (#9981)
* fix(plugin-server): try make console logging test more reliable

* Make test not flaky
2022-05-25 13:41:37 +02:00
Yakko Majuri
36c2f0835c
fix: do not return methods and tasks if setupPlugin failed (#9943)
* fix: do not return methods and tasks if setupPlugin failed

* fixes
2022-05-25 09:57:44 +00:00
Karl-Aksel Puulmann
f7d6d2ab5f
fix(plugin-server): Run all plugin server tests (#9942)
* Fix(plugin-server): run all plugin-server tests

* Broken test fixes

* Fix integration test suite issue

* Remove dead vars

* Fixup package.json

* Fix a test
2022-05-24 16:41:06 +03:00
Yakko Majuri
c9f9c60164
feat(plugin-server-split): only setup plugins the server has a use for (#9917)
* feat(plugin-server-split): only setup plugins the server has a use for

* fix tests

* Update plugin-server/tests/worker/vm/capabilities.test.ts

Co-authored-by: Karl-Aksel Puulmann <macobo@users.noreply.github.com>

* address review

Co-authored-by: Karl-Aksel Puulmann <macobo@users.noreply.github.com>
2022-05-24 13:18:11 +00:00
Michael Matloka
1f267708aa
style(plugin-server): Ban unused vars (#9922)
* Update .eslintrc.js

* Remove unused vars

* Add `eslint-plugin-prettier`

* Fix missing import
2022-05-24 13:44:42 +02:00
Yakko Majuri
8afe7e859d
refactor(plugin-server): yeet all celery code (#9936)
* refactor(plugin-server): yeet all celery code

* more yeeting
2022-05-24 13:34:24 +02:00
Karl-Aksel Puulmann
dba7d20619
feat(plugin-server-split): run async handlers processing off clickhouse ingestion topic (#9930)
* Add processAsyncHandlers capability

* Add conversion method from ClickHouseEvent to PreIngestionEvent

* Work with IngestionEvent in async handlers step

* feat(plugin-server-split): run async handlers processing off clickhouse ingestion topic

* updates

* fixes

* update

* add unit tests for eachBatchX

* fix

* Add conversion method from ClickHouseEvent to PreIngestionEvent

* test fixes

* Fix mock

Co-authored-by: yakkomajuri <yakko.majuri@gmail.com>
2022-05-24 13:09:12 +03:00
Karl-Aksel Puulmann
af0e81d956 Fix mock 2022-05-24 10:57:07 +03:00
Tiina Turban
d4e4c26d39
refactor(plugin-server): yeet redis queue (#9865)
* refactor(plugin-server): yeet redis queue

* fix

* Remove unused imports

* Adjust tests to new reality

* Refactor `queue.test.ts` away

Co-authored-by: Michael Matloka <dev@twixes.com>
2022-05-24 10:10:52 +03:00
Yakko Majuri
5168d720ff
refactor: yeet handleAlert (#9918)
* refactor: yeet handleAlert

* YEET
2022-05-23 18:09:06 +00:00
Karl-Aksel Puulmann
c23108adad
feat(plugin-server): Manage webhook SITE_URL logic via instance settings (#9895)
* SiteUrlManager

* Update site_url

* Update imports

* Use SiteUrlManager with webhooks

* Remove most siteUrl usecases from preIngestionEvent

* Run onEvent even if action lookup fails

* Add tests

* Re-add some null guards

* Add missing test file

* Missing await
2022-05-23 15:53:30 +03:00
Tiina Turban
ae674ee7af
refactor(plugin-server): move non postgres ingestion related tests out of postgres folder (#9872)
* refactor(plugin-server): move non postgres ingestion related tests out of postgres folder

* revert plugin logs move

* paths

Co-authored-by: Michael Matloka <dev@twixes.com>
2022-05-23 13:16:13 +02:00
Michael Matloka
29ef62f33d
refactor(plugin-server): Move vm.* tests over to ClickHouseLand (#9874)
* refactor(plugin-server): Move `vm.*` tests over to ClickHouseLand

* Don't expose injected dependencies of `KafkaProducerWrapper`

* Rework `KafkaProducerWrapper` and Celery `Client` mocking

* Add `rawSendMessage` to `KafkaProducerWrapper`

* Update kafka-health-check.test.ts

* Address feedback

* Address feedback more

* Don't clear mocks explicitly
2022-05-23 11:27:51 +02:00
Michael Matloka
6c4049afcb
refactor(plugin-server): Require clickhouse, kafka, kafkaProducer (#9873)
* refactor(plugin-server): Require `clickhouse`, `kafka`, `kafkaProducer`

* Update Redis status log

* Don't use `kafkaProducer` as a proxy for `KAFKA_ENABLED`

* Delete file that's not in `master`

* Fix bad text replacement

* Fix more bad text replacement

* Apply suggestions from code review

Co-authored-by: Tiina Turban <tiina303@gmail.com>

* Fix imports

* Fix passing config in tests

Co-authored-by: Tiina Turban <tiina303@gmail.com>
2022-05-20 16:39:30 +00:00
Karl-Aksel Puulmann
18535faef7
refactor(plugin-server): refactor the event pipeline (#9829)
* Start refactoring event pipeline

* Add some initial metrics

* Handle DLQ error messages in pipeline runner

* Add public functions for the pipeline

* Tests for runner.ts

* Tests for every step in event pipeline

* yeet some now-unneeded worker code

* Add timeoutGuard

* Emit to DLQ from buffer

* Move some tests to a separate file

* fix internal metrics

* Refactor method location, WIP

* Fix code determining if user is a recent person or not

* Update tests to deal with new pipeline

* Rename methods for consistency

* Remove now-dead test

* Update process-event.test.ts

* Update DLQ test

* Ignore test under yeet

* Remove mocked

* Remove dead code

* Update naming
2022-05-20 13:05:32 +03:00
Karl-Aksel Puulmann
3c2f9aa9b5
fix: make kafka health check timeout test reliable (#9857)
* fix: make kafka health check timeout test reliable

This was reported to be flaky. I believe the issue might be related to
pausing not being immediate and it causing timing-related issues.

* Try again for more reliability
2022-05-20 11:35:22 +03:00
Tiina Turban
4e1bf03d2c
refactor(plugin-server): e2e timeout test to be CH backed (#9871) 2022-05-19 15:48:54 -07:00
Tiina Turban
a6f8b0497a
refactor(plugin-server): merge e2e tests (#9869) 2022-05-19 21:02:54 +02:00
Michael Matloka
faf75ebb5e
refactor(ingestion): Make KAFKA_ENABLED true by default and set KAFKA_HOSTS default (#9844)
* refactor(ingestion): Make `KAFKA_ENABLED` true by default

* Sync `KAFKA_HOSTS` defaults too

* Update snapshots

* Update "kafka" to "kafka:9092"

* Revert "Update "kafka" to "kafka:9092""

This reverts commit d954ac6fa6.

* Update some tests

* Revert "Revert "Update "kafka" to "kafka:9092"""

This reverts commit 07edfa6c5e.

* Update test_0004_replicated_schema.ambr

* Remove `KAFKA_ENABLED` and `KAFKA_HOSTS` from places

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2022-05-19 19:18:15 +02:00