0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-30 19:41:46 +01:00
Commit Graph

70 Commits

Author SHA1 Message Date
Michael Matloka
d801027fb2
refactor(ingestion): Make group type project-based (read/write) (#25876) 2024-11-12 14:35:47 +01:00
Michael Matloka
bfceab6b45
feat(plugin-server): project_id in clickhouse_events_json (#25873) 2024-11-04 23:39:30 +01:00
Michael Matloka
12ff477551
refactor(group-analytics): Add project field to group type (#25600)
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2024-11-01 00:12:28 +01:00
Marius Andra
44e67095a0
feat(hog): save function telemetry (#25093)
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2024-09-24 15:06:29 +02:00
Ben White
7fd0fbb207
feat(cdp): Use cyclotron part 2 (#24746) 2024-09-10 09:05:30 +02:00
Oliver Browne
7207da93e9
feat: Inline plugins (plugins without running VM2) (#23443)
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Ben White <ben@posthog.com>
2024-07-24 14:49:31 +03:00
Ben White
595bae0081
feat(cdp): HogWatcher (#23286) 2024-06-27 17:25:26 +02:00
Bianca Yang
6acfaf55f5
feat: Final piece of deprecating available features, DB references (#22402)
* remove db ref

* update the migration

* remove referencess from test fixture jsons

* some more removals

* Update UI snapshots for `chromium` (1)

* Update UI snapshots for `chromium` (2)

* Update query snapshots

* Update query snapshots

* Update query snapshots

* Update query snapshots

* Update UI snapshots for `chromium` (1)

* Update query snapshots

* fix migration

* add reverse sql

* fix the migration

* Update UI snapshots for `chromium` (2)

* Update query snapshots

* Update UI snapshots for `chromium` (2)

* Update UI snapshots for `chromium` (2)

* Update UI snapshots for `chromium` (1)

* Update UI snapshots for `chromium` (2)

* Update query snapshots

* Update UI snapshots for `chromium` (1)

* Update UI snapshots for `chromium` (2)

* Update UI snapshots for `chromium` (2)

* Update query snapshots

* Update UI snapshots for `chromium` (2)

* Update UI snapshots for `chromium` (2)

* Update UI snapshots for `chromium` (2)

* Update query snapshots

* Update UI snapshots for `chromium` (2)

* Update query snapshots

* Update UI snapshots for `chromium` (2)

* Update query snapshots

* Update query snapshots

* i think i finally fixed the migration issue

* Update UI snapshots for `chromium` (2)

* Update query snapshots

* Update UI snapshots for `chromium` (2)

* Update UI snapshots for `chromium` (2)

* update migration post merge

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2024-05-30 16:41:22 +00:00
Bianca Yang
9dd22a3757
feat: Deprecate available_features pt 2 (#22373)
* everything except plugin server and sync_available_features

* sync_available_features_done, some plugin_server done?

* and a tiny bit more

* linting

* try to fix some tests

* more test fixes/

* clean up typos

* weed wacking bugs

* more test shenanigans

* fix plugin server

* actually fix plugin server test?

* still fixing tests

* another attempt

* some pr feedback

* small fix

* fix database query accessor

* fix functional tests

* fix tests

* Update query snapshots

* Update query snapshots

* Update query snapshots

* update some comments and fxn names

* fix plugin server test

* Update query snapshots

* Update query snapshots

* Update query snapshots

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2024-05-28 17:29:24 -07:00
Ben White
224a5d5d0c
feat: Action steps refactor (part 2) (#22092) 2024-05-08 09:46:52 +02:00
Brett Hoerner
ddd0a05884
feat(plugin-server): lazy distinct_id/person row creation (#21670)
* split out InternalPerson and Person types

* disable old backfill code

* add lazy person env var setting

* lazily create person/distinct_id rows

* remove backfill.ts

* drop properties after person lookup

* remove leftover backfill bit
2024-04-23 10:39:40 -06:00
Michael Matloka
f02d045bf9
chore(environments): Add migration to backfill projects (#20887)
* chore(environments): Add migration to backfill projects

* Fix `noop`

* Add `project_id` to plugin server test setup

* Fix `project_id`

* Also add `posthog_project` to plugin server tests

* Update `createTeam`

* Fix func tests
2024-03-14 13:45:28 +01:00
ted kaemming
e5e803aa4c
refactor(plugin-server): Add deferred person override writer (#19007) 2023-12-05 13:34:41 -08:00
ted kaemming
9299aa09e5
fix(plugin-server): Remove Postgres-based plugin error logging in favor of existing ClickHouse-based approaches (#18764) 2023-11-27 10:41:36 -08:00
Paul D'Ambra
31c1cdf301
chore: yeet CH recordings ingestion (#17572)
Removing ClickHouse based recordings

One big yeet for a man, a great yeet for humanity
2023-10-11 14:23:41 +01:00
Xavier Vello
1b6628055d
feat(plugin-server): allow to use several PG connection pools (#17001)
Co-authored-by: Tiina Turban <tiina303@gmail.com>
2023-08-24 11:09:10 +02:00
Harry Waye
9f0cf9f40f
chore: make attachement test less flakey
We do this by making sure the plugin config and the attachement are
committed together.
2023-07-11 14:08:29 +00:00
Tiina Turban
d78680c976
chore: Remove lazy person container (#15286) 2023-05-22 13:51:07 +02:00
Harry Waye
7ba6fa7148
chore(plugin-server): remove piscina workers (#15327)
* chore(plugin-server): remove piscina workers

Using Piscina workers introduces complexity that would rather be
avoided. It does offer the ability to scale work across multiple CPUs,
but we can achieve this via starting multiple processes instead. It may
also provide some protection from deadlocking the worker process, which
I believe Piscina will handle by killing worker processes and
respawning, but we have K8s liveness checks that will also handle this.

This should simplify 1. prom metrics exporting, and 2. using
node-rdkafka.

* remove piscina from package.json

* use createWorker

* wip

* wip

* wip

* wip

* fix export test

* wip

* wip

* fix server stop tests

* wip

* mock process.exit everywhere

* fix health server tests

* Remove collectMetrics

* wip
2023-05-03 14:42:16 +00:00
Xavier Vello
25cb653c1b
feat(ingestion): run all analytic events through populateTeamDataStep (#14341)
* team-manager: expire negative lookups after 5 minutes, improve docs
* populateTeamDataStep: don't drop token, keep team_id from capture if present, report results
* ingestEvent: run all analytic events through runLightweightCaptureEndpointEventPipeline
* continue accepting events with no token but a team_id
2023-02-22 14:24:05 +01:00
Harry Waye
ed876aa40e
fix: for empty group props (#14243)
* fix: for empty group props

We were failing if the props were empty.

* refactor: make property definitions db dependencies explicit

We were relying on implicit details setup via `resetTestDatabase` which
makes it hard to reason about what's going on. It also uses hard coded
ideas which limits our ability to isolate tests properly, which would
help both for writing tests with confidence that they are correct, and
for adding for example parallelism.

* add test
2023-02-15 15:39:20 +00:00
Harry Waye
ac6b863c73
refactor: remove timekeeper, use jest fake timers, create hub once (#14166)
This removes the timekeeper library and uses jest fake timers instead.
This also creates the hub once and reuses it for all tests, which is
faster than creating a new hub for each test.
2023-02-09 11:30:41 +00:00
Xavier Vello
c2550fc76b
chore: use pod name as kafka client ID (#13737)
* chore: use pod name as kafka client ID

* update resetKafka test helper too
2023-01-30 14:08:03 -08:00
Michael Matloka
a26cbeaeff
refactor(plugin-server): Don't print debug logs in dev by default (#13821) 2023-01-20 14:08:26 +01:00
Paul D'Ambra
27c69225ec
feat: add the performance events clickhouse schema (#13441)
* feat: add the performance events clickhouse schema

* add support for replication being off

* move and refactor performance events sql file

* with the same kafka columns as other tables

* don't account for replication settings in migration

* update snapshots

* kafka table doesn't have explicit kafka columns

Co-authored-by: Ben White <ben@posthog.com>
2022-12-22 14:01:35 +00:00
Yakko Majuri
90f1b16285
feat(ingestion): remove postgres dependency from capture endpoint (#12802)
* add support for token field in kafka message

* formPipelineEvent

* rename pipeline files according to new order

* wip team_id and anonymize ips

* conditional handlers and tests

* some plugin server fixes

* fix capture bug

* fix

* more fixes

* fix capture tests

* pipeline update

* fix + investigate database resets

* fix import order

* testing and typing updates

* add test for capture endpoint

* testing

* python typing

* plugin server test

* functional test

* fix test

* another fix

* make sure no team ids clash in tests

* fix

* add more metrics and logs

* cache nulls

* updates

* add more metrics
2022-11-23 09:55:26 -03:00
Tiina Turban
41c983cc93
chore: throw when we ran out of wait time waiting for CH ingestion (#12126) 2022-11-09 15:26:52 +01:00
Harry Waye
cc2f424452
chore(plugins-server): use Kafka to buffer app jobs requests (#12345)
* chore(plugins-server): use Kafka to buffer app jobs requests

To remove the dependency on the Graphile Worker database on things that
may be requesting app job runs we push the jobs to a Kafka topic.

* chore: use KAFKA_JOBS instead of string literal `'jobs'`

* chore: rename startJobsBufferConsumer -> startJobsConsumer

* avoid checking eventId

* fix lint

* fix producer wrapper tests

* fix retries test

* handle offset sync

* wip

* wip

* remove exports

* do better

* use Producer not wrapper

* reset db

* mock once

* Add test for raising to the consumer

* Update plugin-server/tests/main/ingestion-queues/run-async-handlers-event-pipeline.test.ts

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

* and in the darkness bind them

* fix tests

* don't forget the name update!

* rename DependencyError to DependencyUnavailable

* separate dlq

* update comment

Co-authored-by: Yakko Majuri <38760734+yakkomajuri@users.noreply.github.com>
2022-10-28 11:05:15 +01:00
Harry Waye
62d9c20a90
chore(plugin-server): use DELETE instead of TRUNCATE (#12393)
* chore(plugin-server): use DELETE instead of TRUNCATE

Truncate seems a little slow. Other options to consider:

 1. PostgreSQL fsync settings in tests
 2. using tmpfs for "persistence"
 3. use transaction/rollback: not totally sure we'd be able to do this
    in our tests but may be worth a try.

* wip

* wip

* set fsync=off

* Delete all tables in current schema

* don't bother with fsync=off
2022-10-25 09:15:53 +00:00
Harry Waye
d3f9d865f5
refactor(plugin-server): split out plugin server functionality (#12191)
* refactor(plugin-server): split out plugin server functionality

To get better isolation we want to allow specific functionality to run
in separate pods. We already have the ingestion / async split, but there
are further divides we can make e.g. the cron style scheduler for plugin
server `runEveryMinute` tasks.

* split jobs as well

* Also start Kakfa consumers on processAsyncHandlers

* add status for async

* add runEveryMinute test

* avoid fake timers, just accept slower tests

* make e2e concurrent

* chore: also test ingestion/async split

* increase timeouts

* increase timeouts

* lint

* Add functional tests dir

* fix

* fix

* hack

* hack

* fix

* fix

* fix

* wip

* wip

* wip

* wip

* wip

* fix

* remove concurrency

* remove async-worker mode

* add async-handlers

* wip

* add modes to overrideWithEnv validation

* fix: async-handlers -> exports

* update comment
2022-10-20 09:22:46 +00:00
Yakko Majuri
b89a2f8e28
refactor: rename Graphile to Graphile Worker (#12324)
* refactor: rename Graphile to Graphile Worker

* revert env var changes

* one more

* format readme

* add changed files
2022-10-19 11:38:25 -03:00
Harry Waye
7f6f9d5e90
test(plugin-server): run same tests for single and multi process modes (#12220)
* tests(plugin-server): run same tests for single and multi process modes

Previously we were running different tests, now we run the same.

* exclude async on ingestion capability

* fix typing

* do not test for onSnapshot

* fix autocapture test
2022-10-12 16:21:16 -03:00
Harry Waye
21bc4b01ca
refactor(e2e): make e2e tests 4x faster (#12214)
* refactor(e2e): make e2e tests 4x faster

I'm a little scared to make changes to the pluginsServer without having
some way to test that is close to production. I started changing some of
the internals in https://github.com/PostHog/posthog/pull/12191 but
started to see test failures for internals that I'm not confident in
handling without having some higher level tests testing the
pluginsServer functionality as a whole, so I started looking at the e2e
tests which are very slow and look like they don't have great coverage.

Rather than restarting the pluginsServer each time, we can use the
feature of partitioning by teamId to run multiple tests against the same
server.

To do this I've added a few helper functions for pulling out of
ClickHouse which enforce that you include a filter on teamId. It's a
little more verbose but also hopefully serves as good documentation for
how e.g. plugins work and are loaded.

I've also avoided reaching into the internals of the pluginsServer as
much as possible, only doing so to reload the plugins. Ideally we'd also
handle the reload via the PubSub which would allow us to, for example,
run the e2e tests against a separate pluginsServer process thereby
getting more confidence, but that's a stretch and maybe something we can
do without. This would however make it easy, for instance to:

 1. make big refactors without fear of breaking things
 2. swap out, e.g. the anonymous consumer to use instead something
    written in bash or maybe something not quite as absurd.

* enable buffer, remove random teamId
2022-10-12 16:14:46 +01:00
Karl-Aksel Puulmann
1c96763bf0
feat(app-metrics): Set up schema and data gathering of app metrics (#12143)
* Add new app_metrics feature available on scale and enterprise

* chore(ingestion): cache available_features for a longer period in OrganizationManager

This will come in handy for app metrics and is generally a performance win

* Add service to track app metrics

* refactor(historical-exports): Move retry limit handling code to same place as other error handling

* Track app metrics in processEvent/onEvent/exportEvents and historical exports

* Add mising app-metrics file

* Add missing __init__.py module

* Use correct topic + columns for app metrics

* Add a placeholder schema

* Set timestamp correctly

* Fix a typeerror in organization-manager.ts

* Schema fixup

* Add test showing read-own-writes logic

* Remove unneeded TODO

* Add missing constant

* Simplify flushing logic

* Stabilize VM tests

* Use correct sharding key

* Revert hooks changes
2022-10-12 11:30:58 +03:00
Marius Andra
2c2e9ce48e
feat(apps): rename web.ts to site.ts (#12179)
* site.ts

* Update snapshots

* fix file in test archive

* Update snapshots

* more renames

* plugin source file updated at

* fix test

* last renames

* add null

* blank

* remove what we don't need

* get test to pass

* use new posthog-js

* new version

Co-authored-by: mariusandra <mariusandra@users.noreply.github.com>
2022-10-11 10:27:21 +00:00
Karl-Aksel Puulmann
30f59dfef2
feat(historical-exports): Include historical exports finishing in activity log (#12068)
* Add a is_system flag to activity logs

* Allow writing activity logs from within plugin-server

* Make changes object non-required

* Render system user information

* Log when export finishes or fails in plugin activity log

* Update activityLogLogic.plugin.test.tsx
2022-10-07 13:25:16 +03:00
Marius Andra
c42c2c1879
feat(apps): inject code to posthog-js (#12003)
* support adding custom files

* compile web.ts

* add injected code into /decide

* transpile better

* add id and payload stub to injected code

* skip backend if web only

* more web source

* add payload to default demo

* values list and inline for

* revert

* simpler query

* reload plugin if source changed

* pass on config that has "web":true

* add a bootloader for scripts larger than 1kb

* rename payload to config

* access posthog also in injected script

* cleanup

* pass meta object to inject

* split web_js code

* List

* add a web token for plugin configs

* test for web.ts

* use WEB_APP_INJECTION env to enable/disable injection

* fix types

* remove instance setting

* add inject_web_apps on team

* track installed web apps on team

* refresh from db

* enabling web apps makes an extra query

* null true

* clean imports

* null check

* fix migration

* fix noise in tests

* test web app injection

* update Team without going through a signal loop

* update plugin test

* update plugin test

* typo

* Update snapshots

* typing

* inject only via external scripts

* enable injection in the app

* update posthog-js

* blank source files when updating

* url dataclass

* comment

* add and remove files

* not users

* only show button to add files if there are files to add

* update in bulk

* TYPE_CHECKING

* abstract transpilation just a bit

* feedback and bug

* we're down under

* errors if failed

* raise on 404

* clean up more

* refactor

* add updated_at to list

* no need to check code equality

* remove australia ip override

* test

* remove support for random files

Co-authored-by: mariusandra <mariusandra@users.noreply.github.com>
2022-10-05 17:29:45 +02:00
Karl-Aksel Puulmann
d421458fb1
feat(ingestion): Create separate schema for ingestion warnings (#11991)
* Initial schema for new ingestion_warnings table

* Update and test ingestion_warnings API endpoint with new table

* Add captureIngestionWarning function

* Update variable name

* Reformat with black

* Remove ver

* Include partition

* Update test_schema snapshots

* Solve weird mypy error

* Update docs around function
2022-09-28 10:01:30 +03:00
Tiina Turban
49f3311a65
chore: nuke protobuf fully (#10932) 2022-08-03 15:41:44 +02:00
Karl-Aksel Puulmann
c9f05fdaf1
chore(plugin-server): support tracing in plugin-server (#11029)
* Experimental tracing support for plugin server

* Add tag to postgresTransaction

* Track event pipeline steps as separate spans

* Track kafka queueMessage?

* Tracing for processEvent, onEvent, onSnapshot

* plugin.runTask

* Move sentry code

* Make tracing rate configurable
2022-07-28 15:05:00 +03:00
Karl-Aksel Puulmann
612d62610e
perf(plugin-server): speed up getPluginConfigRows (#10952)
This is currently one of our slowest queries. The query itself is fine
but the amount of data returned is causing issues.

`error` column constitutes >80% of data stored in the column - by
removing it in the query we should see significant speedups.

pganalyze page: https://app.pganalyze.com/databases/-675880137/queries/5301003665?t=7d
2022-07-25 16:27:18 +03:00
Yakko Majuri
a8687f896e
fix: don't pull unnecessary plugin data in the plugin server (#10909)
* fix: don't pull unnecessary plugin data in the plugin server

* fix tests

* fix test 2

Co-authored-by: Tiina Turban <tiina303@gmail.com>
2022-07-21 16:47:55 +00:00
Yakko Majuri
985148ee7e
feat: buffer 2.0 (#10653)
* feat: buffer 2.0 proposal

* add tests

* prevent infinite retrying

* perf

* updates

* tweaks

* Update latest_migrations.manifest

* Update plugin-server/src/main/ingestion-queues/buffer.ts

* update

* updates

* fix migrations issue

* reliability uopdates

* fix tests

* test fix

* e2e test

* test

* test

* ??

* cleanup
2022-07-08 10:48:25 +00:00
Michael Matloka
b04015f25e
chore(plugin-server): Consume from buffer topic (#10475)
* chore(plugin-server): Consume from buffer topic

* Refactor `posthog` extension for buffering

* Properly form `bufferEvent` and don't throw error

* Add E2E test

* Test buffer more end-to-end and properly

* Put buffer-enabled test in a separate file

* Update each-batch.test.ts

* Test that the event goes through the buffer topic

* Fix formatting

* Refactor out `spyOnKafka()`

* Ensure reliability batching-wise

* Send heartbeats every so often

* Make test less flaky

* Commit offsets if necessary before sleep too

* Update tests

* Use seek-based mechanism (with KafkaJS 2.0.2)

* Add comment to clarify seeking

* Update each-batch.test.ts

* Make minor improvements
2022-06-28 13:30:10 +02:00
Neil Kakkar
9712fd9bb5
chore(feature-flags): Upsert hash key overrides on people merges (#10418) 2022-06-24 10:58:42 +01:00
Michael Matloka
3578a0c1c2
perf(apps): Only load PluginSourceFiles instead of Plugin.archive (#10374)
* perf(apps): Cache app code at install instead of fetching `archive` blob

* Fix typing

* Add migration

* Use `cast()` instead of `assert`

* Update plugin test helpers

* Restore `reload_plugins_on_workers()`

* Save plugin source file rows separately from plugin rows

* Fix migration

* Update latest_migrations.manifest

* Update plugins.test.ts

* Separate `plugin60WithSource` from `plugin60`

* Handle `PluginSourceFile` at `insertRow()` level

* Unify `plugin60WithSource` and `plugin60` again

* Update sql.test.ts

* Fix and simplify reading files in `loadPlugin()`

* Update plugins.test.ts

* Update more tests

* Clean code up

* Specify `json_parse=True` in lower-level function tests

* Add tests for `update_or_create_from_plugin_archive()`

* Update migration with updated function

* Update plugin `upgrade` endpoint

* Remove leftover `print()`

* Add error handling to `0243_unpack_plugin_source_files`

* Add `upgrade` assertions

* Revert plugin server changes

* Fix typing

* perf(apps): Only load `PluginSourceFile`s instead of `Plugin.archive`

This reverts commit 180ed228b8.

* Update logging level and message

* Refactor `find_index_ts_in_archive()` and `extract_plugin_code()` out

* Don't select `latest_tag` and `latest_tag_checked_at`

* Use kwargs in logging

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

* Fix missing comma

* Only throw if `plugin_json_parsed` is `None`

* Fix `reverse_func`

* Accept empty files

* Make sure files which are deleted between version are gone

* Update 0243_unpack_plugin_source_files.py

* Update 0243_unpack_plugin_source_files.py

* Explain query counts

* Use `@snapshot_postgres_queries` instead of `assertNumQueries()`

Co-authored-by: Karl-Aksel Puulmann <macobo@users.noreply.github.com>
2022-06-22 16:33:23 +02: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
59797efce8
refactor(plugin-server): yeet element-group related postgres code (#10161) 2022-06-07 12:23:20 +03: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
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