Commit Graph

92 Commits

Author SHA1 Message Date
Ben White
fdb2c71a39 feat: S3 backed recording ingestion (take 2) (#14864) 2023-04-25 09:43:07 +00:00
Harry Waye
a40f01138e revert(recordings): use cooperative-sticky rebalance strategy (#15211)
Revert "chore(recordings): use cooperative-sticky rebalance strategy (#15197)"

This reverts commit 3eddb96b9b.
2023-04-24 15:06:33 +00:00
Harry Waye
3eddb96b9b chore(recordings): use cooperative-sticky rebalance strategy (#15197)
* chore(recordings): use cooperative-sticky rebalance strategy

This should make rebalances and lag during deploys a little less
painful. I'm setting this as the globally used strategy, when we e.g.
want to use another strategy for a specific consumer group, we can make
this configurable.

* disable rebalance_callback

* use node-rdkafka-acosom fork instead, for cooperative support
2023-04-24 13:25:24 +00:00
Xavier Vello
05a8d1f302 chore(plugin-server): collect prometheus metrics from piscina workers (#15002) 2023-04-11 13:27:07 +02:00
Harry Waye
a26a87cf40 chore: add profiler to session recordings load test (#14649)
chore: add profiler to session recordings load test
2023-03-09 14:07:54 +00:00
Harry Waye
a4a3a0c902 test(plugin-server): use librdkafka for functional tests (#14468)
* test(plugin-server): use librdkafka for functional tests

While trying to port the session recordings to use node-librdkafka I
found it useful to first implement it in the functional tests.

* use obj destructuring to make calls more self explanatory
2023-03-01 11:03:13 +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
be607d50ad chore: add plugin-server prom metrics 1/n (#14014)
* update prom-client
* add kafka error and instrumentation function metrics
2023-01-31 14:58:14 +01:00
Xavier Vello
77d0125138 feat: set export batch size based on plugin settings (#13559) 2023-01-26 16:31:02 +01:00
timgl
d4f9790234 chore(plugin-server): Upgrade jsonwebtoken to 9.0.0 (#13900) 2023-01-26 15:27:02 +01:00
Guido Iaquinti
19d65fb005 chore(dockerfile): switch base image to non alpine (#13314) 2022-12-16 11:12:11 +01:00
Harry Waye
1e82569bbb chore(plugin-server): Add metrics for time of last processed message (#13350)
* chore(plugin-server): Add metrics for time of last processed message

Previously we have been alerting on Kafka consumer group offset lag.
However, really we care about the delay between messages being written
to Kafka and being processed by the plugin server.

By adding the last processed timestamp, as a gauge, we can then alert on
if that time and now is greater than a threshold.

This alert would not require the plugin-server to be up to trigger, just
that there be some time registered so it handles complete failure also.

For the case that there are no messages past the committed offsets, we
will end up triggering the alert if we do not also take into
consideration the production rate into the topic.

* wip

* wip

* fix imports order

* fix group id

* Add and use waitForExpect instead

* remove yarn.lock

* move comment

* wip
2022-12-15 18:28:43 +00:00
Thomas Obermüller
4a30e78b22 chore: use pnpm to manage dependencies (closes #12635) (#13190)
* chore: use pnpm to manage dependencies

* Fix CI errors

* Don't report Docker image size for external PRs

* Fix pnpm-lock.yaml formatting

* Fix module versions

* Ignore pnpm-lock.yaml

* Upgrade Cypress action for pnpm support

* Set up node and pnpm before Cypress

* Fix typescript issues

* Include patches directory in Dockerfile

* Fix Jest tests in CI

* Update lockfile

* Update lockfile

* Clean up Dockerfile

* Update pnpm-lock.yaml to reflect current package.json files

* remove yarn-error.log from .gitignore

* formatting

* update data exploration readme

* type jest.config.ts

* fix @react-hook issues for jest

* fix react-syntax-highlighter issues for jest

* fix jest issues from query-selector-shadow-dom

* fix transform ignore patterns and undo previous fixes

* add missing storybook peer dependencies

* fix nullish coalescing operator for storybook

* reorder storybook plugins

* update editor-update-tsd warning to new npm script

* use legacy ssl for chromatic / node 18 compatibility

* use pnpm for visual regression testing workflow

* use node 16 for chromatic

* add @babel/plugin-proposal-nullish-coalescing-operator as direct dependency

* try fix for plugin-server

* cleanup

* fix comment and warning

* update more comments

* update playwright dockerfile

* update plugin source types

* conditional image size reporting

* revert react-native instructions

* less restrictive pnpm verions

* use ref component name in line with style guide

Co-authored-by: Jacob Gillespie <jacobwgillespie@gmail.com>
2022-12-12 10:28:06 +01:00
Harry Waye
8018aa7244 chore(ingestion): set ingested_event before delaying anon. events (#13236)
* chore(ingestion): set ingested_event before delaying anon. events

Now that we delay anonymous events, we end up having a delay in the
onboarding flow where we need to wait for he flag to be set before
informing the user that an event has successfully been captured.

This is a lesser cousin of
https://github.com/PostHog/posthog/pull/13191 which offers the added
feature of informing the user of the capture date of the latest event,
but has some more work to do re. performance. I would like to get this
in first to unblock the person-on-events re-enabling for new customers.

* Move call to only run when buffering
2022-12-09 14:38:16 +00:00
Xavier Vello
c0702b8b19 fix(ingestion): fix noisy 'Invalid unit value NaN' errors (#13027) 2022-11-30 15:46:42 +01:00
James Greenhill
696028e800 feat: simplify the docker-compose setup so we do less version coordinations (#12998)
* feat: remove version from docker compose to support new spec

* feat: simplify the docker-compose setup so we do less version coordinations

* update hobby bin

* bump docker-compose version for hobby for extends compat

* move ci to ubuntu-latest

* Revert "move ci to ubuntu-latest"

This reverts commit a0462adfecf182ca7398d809ebb49fac36110d63.

* use docker compose for github ci

* correct comments on base
2022-11-29 20:50:42 +00:00
Harry Waye
b010073ec4 test(plugin-server): add functional tests for property definitions (#12659)
* refactor(plugin-server): separate api from functional_tests

This just moves the api helpers to a separate file, such that we can
import from other files.

* test(plugin-server): add functional tests for property definitions

I was going to take a stab at
https://github.com/PostHog/posthog/issues/12529 but I wasn't sure how
the definition bits worked, so thought I'd add some tests first.

This doesn't just add tests but also:

 1. starts demonstrating how we can split up the tests into
    different files, thereby also allowing jest test isolation.
 2. removes --runInBand, such that isolated tests can run in parallel
2022-11-08 06:56:19 +00:00
Harry Waye
aa5231307e ci(plugin-server): add coverage for functional_tests (#12593)
* ci(plugin-server): add coverage for functional_tests

Now I've completely separated out the test runner from the running
server (i.e. they are in completely separate processes), we can pull out
a coverage report using `c8` (which is using node v8 built in coverage
tooling and outputing to an istambul compatible html format).

* wip

* wip

* wip

* wip

* wip
2022-11-03 13:06:12 +00:00
Harry Waye
fff4483ff2 chore(plugin-server): add perf test using HedgeBox Matrix (#12392)
* chore(plugin-server): add perf test using generate_demo_data

Uses generate_demo_data as a basic per test. Not perfect but it's a
start. Still need to consider:

 1. buffer functionality
 2. testing specifically without the buffer functionality, there's
    something around using graphile worker directly to dely events from
    the managemenet script but we shouldn't need to do this to provide
    correctness of ingestion imo, rather only the order of events.

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* push events through plugin-server

* build plugin server dist

* run gen demo data earlier

* add timer

* change debug/print to logger debug/info

* update logs, remove workflow
2022-10-25 10:48:11 +00:00
Harry Waye
cb771f10d3 ci(plugin-server): add coverage output to plugin-server functional tests (#12361)
Doesn't try to do any comparison to base yet although that would be
great, but as it stands it offers some useful insights into where we
might be missing coverage.
2022-10-20 11:11:05 +01: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
c47a73165a feat(plugin-server): use graphile-worker crontab (#12242)
* yeet references to redlock

* rename jobs/ to graphile-worker/

* feat(plugin-server): use graphile-worker crontab

* remove debugging

* yeet redlock dependency

* remove legacy test

* Update comment

* Update plugin-server/src/main/pluginsServer.ts

Co-authored-by: Harry Waye <harry@posthog.com>

* address review, update tests

* fix old tests

* testing, testing

* maybe fix sigterm

Co-authored-by: Harry Waye <harry@posthog.com>
2022-10-18 11:44:41 -03:00
Karl-Aksel Puulmann
4d1c0e45fb feat(app-metrics): Gather and show information on errors (#12250)
* Add dependencies

* WIP: Gather error context

* Downgrade package

* Update tracking logic

* Query errors along with app metrics/export metrics

* last_seen

* Fetch and show errors table underneath metrics

* Sorting order

* Endpoint for fetching sample error details for an error

* Render error details drawer

* Render tabs in ErrorDetailsDrawer

* Tests for AppMetricsErrorsQuery

* Tests for AppMetricsErrorDetailsQuery

* Tests for historical_export_metrics

* Update existing app metrics API tests

* /error_details endpoint tests

* Update retries tests

* Update v2 historical exports tests

* Tests for app-metrics.ts

* run prettier

* Avoid reloading data on table sorting

* Fix fat-finger
2022-10-18 09:58:08 +03:00
dependabot[bot]
933cebb1b3 chore(deps): bump vm2 from 3.9.6 to 3.9.11 in /plugin-server (#12013)
Bumps [vm2](https://github.com/patriksimek/vm2) from 3.9.6 to 3.9.11.
- [Release notes](https://github.com/patriksimek/vm2/releases)
- [Changelog](https://github.com/patriksimek/vm2/blob/master/CHANGELOG.md)
- [Commits](https://github.com/patriksimek/vm2/compare/3.9.6...3.9.11)

---
updated-dependencies:
- dependency-name: vm2
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-10-07 09:39:09 -03:00
Harry Waye
8118ded811 refactor(plugin-server): use JSON logs when not in dev (#11330)
* refactor(plugin-server): use JSON logs when not in dev

To improve observability of the plugin-server, for instance easily being
able to view all error logs, we enable JSON logs in production. This
should enable us to, for instance easily parse for KafkaJS events like
GROUP_JOIN but initially we can just use for filtering down on log
level.

In development we will still get a plain text log line.

* ensure stderr goes through pino-pretty as well

* output log level names not number

* update versions
2022-09-20 11:49:52 +01:00
Karl-Aksel Puulmann
514c0caea5 chore(plugin-server): Historical exports fixes (#11464)
* chore(historical-exports): Dont call exportEvents if no events to export

* Make historical export logging more accurate

* Give a progress percentage for export

* Only log & exportEvents if there is events to export

* Track voided promises

* Add more typing to vm upgrade

* Add first test for upgrades

* Test setupPlugin()
2022-08-25 08:58:43 +03:00
Neil Kakkar
7356da1c94 chore: bump posthog-node version (#11435) 2022-08-24 11:55:54 +01:00
Karl-Aksel Puulmann
c52261b4cf chore(plugin-server): Update @maxmind/geoip2-node to 3.4.0 (#11285)
* update scaffold

* fix yarn.lock
2022-08-22 11:09:00 +03:00
Karl-Aksel Puulmann
8ac5fc592d chore(plugin-server): Bump kafkajs to 2.2.0 (#11364)
Changelog: https://github.com/tulios/kafkajs/releases
2022-08-19 09:10:54 +03:00
Karl-Aksel Puulmann
51874c390a chore(plugin-server): Update babel, typescript related dependencies (#11309)
Babel changelog: https://github.com/babel/babel/blob/main/CHANGELOG.md
Typescript changelog: https://github.com/Microsoft/TypeScript/releases
Ts-node changelog: https://github.com/TypeStrong/ts-node/releases
2022-08-18 09:35:18 +03:00
Tiina Turban
7c11dac3e5 chore: error for .only usage in tests in plugin-server (#11357) 2022-08-17 18:46:28 +01:00
Neil Kakkar
5440a29cf5 chore(plugin-server): Update posthog-node version (#11343) 2022-08-17 12:10:29 +00:00
Karl-Aksel Puulmann
8b0056192d chore(plugin-server): Update prettier and eslint to latest (#11288)
* chore(plugin-server): bump prettier and eslint

* Solve new warnings/errors
2022-08-16 09:44:52 +03:00
Karl-Aksel Puulmann
4332c15e4b chore(plugin-server): Update node-schedule to 2.1.0 (#11286)
Changelog: https://github.com/node-schedule/node-schedule/blob/master/CHANGELOG.md
2022-08-16 09:44:44 +03:00
Karl-Aksel Puulmann
2c19a62d67 chore(plugin-server): Update sentry packages to 7.1.0 (#11284)
* chore(plugin-server): Update sentry packages to 7.1.0

Changelog can be found at https://github.com/getsentry/sentry-javascript/blob/master/CHANGELOG.md

* Update imports
2022-08-16 09:44:31 +03:00
Karl-Aksel Puulmann
9429235fc1 chore(plugin-server): Update hot-shots library to latest (#11203)
Changelog: https://github.com/brightcove/hot-shots/blob/master/CHANGES.md

Doesn't seem like TCP reconnections affect us in negative ways
2022-08-09 14:53:27 +03:00
Tiina Turban
49f3311a65 chore: nuke protobuf fully (#10932) 2022-08-03 15:41:44 +02:00
Ben White
f0f0cd4e15 feat: Testing alpha releases of JS libs (#11011)
* feat: Updated to alpha version of posthog-js
* Swap to alpha versions of other libs
2022-07-28 11:19:56 +00:00
Karl-Aksel Puulmann
156fa2353f feat(plugin-server): Use Snappy compression codec for kafka production (#10974)
* feat(plugin-server): Use Snappy compression codec for kafka production

This helps avoid 'message too large' type errors (see
https://github.com/PostHog/posthog/pull/10968) by compressing in-flight
messages.

I would have preferred to use zstd, but the libraries did not compile
cleanly on my machine.

* Update tests
2022-07-28 11:58:33 +03:00
Harry Waye
e7a9b7de79 fix(autocapture): ensure $elements passed to onEvent (#10880)
* fix(autocapture): ensure `$elements` passed to `onEvent`

Before calling `onEvent` the plugin does, amoung other things, a delete
on `event.properties` of the `$elements` associated with `$autocapture`.
This means that for instance the S3 plugin doesn't include this data in
it's dump.

We could also include other data like `elements_chain` that we also
store in `ClickHouse` but I've gone for just including `elements` for
now as `elements_chain` is derived from `elements` anyhow.

* revert .env changes, I'll do that separately

* run prettier

* update to scaffold 1.3.0

* fix lint

* chore: update scaffold to 1.3.1

* update scaffold
2022-07-20 14:33:32 +01:00
Yakko Majuri
47fc0052ce chore: bump graphile-worker to v0.13.0 (#10876) 2022-07-19 15:26:52 +00:00
Guido Iaquinti
cda6b83148 chore(Dockerfile): remove dev.Dockerfile (#10529) 2022-06-28 13:50:57 +02: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
PostHog bot
49433b24da chore(deps): Update plugin-scaffold to 1.1.0 (#10473)
Co-authored-by: posthog-bot <posthog-bot@users.noreply.github.com>
2022-06-24 17:10:36 +02:00
Yakko Majuri
7c9744ac8b chore: bump @google-cloud/pubsub and protobufjs (#10443) 2022-06-23 16:45:12 +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 180ed228b8cc59875ac426783a2f46e57eb1e69c.

* 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
0774c4e542 chore(ci): Speed up plugin server tests (#10341)
* Use built-in sharding for jest

* Set up caching for plugin server CI

Note caching scheme is reused from backend tests for python

* Upgrade jest to 28

* Cache yarn cache in plugin-server tests

* Test removing SAML for plugin-server dependencies

* Run docker-compose in background
2022-06-20 16:04:20 +03:00
Karl-Aksel Puulmann
f2f4e5d561 Revert "chore(plugin-server): update hot-shots (statsd library) to latest, use globalTags (#10237)" (#10249)
This reverts commit d9dfb85c2b.
2022-06-10 15:56:24 +03:00
Karl-Aksel Puulmann
d9dfb85c2b chore(plugin-server): update hot-shots (statsd library) to latest, use globalTags (#10237)
* chore: Update hot-shots to latest

Changelog: https://github.com/brightcove/hot-shots/blob/master/CHANGES.md

Nothing drastic here

* add global tag for plugin server mode
2022-06-10 14:23:25 +03:00
PostHog bot
6d2f388d2f chore(deps): Update plugin-scaffold to 1.0.4 (#10212) 2022-06-09 11:59:49 +01:00