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

400 Commits

Author SHA1 Message Date
Eric Duong
fd20a81891
Index the cohort params (#5049)
* index the cohort params

* remove extra condition
2021-07-08 19:00:15 -04:00
Michael Matloka
a599056234
Handle Action.DoesNotExist more (#5028)
* Handle `Action.DoesNotExist` more

* Reuse try-except logic for `Action.DoesNotExist`

* Fix circular import

* Add `test_funnel_invalid_action_handled`
2021-07-08 21:47:14 +00:00
Michael Matloka
d655ca7c8d
Fix some insights query building 500s (#4971)
* Fix handling of cohort without match groups

* Fix bug with CH precalculated cohort query building

* Fix `get_person_ids_by_cohort_id`
2021-07-05 11:49:55 +02:00
Michael Matloka
a5cc8d36df
Handle cohort being filtered on not existing (#4961)
* Raise 400 instead of 500 if filter cohort does not exist

* Actually return empty 200 results instead of 400

Co-authored-by: eric <eeoneric@gmail.com>
2021-07-01 13:30:18 -04:00
Karl-Aksel Puulmann
ec5d839337
Proposal: Use ValidationError over ValueError in views (#4917)
* Proposal: Use `ValidationError` over `ValueError` in views

This generates a nicer exception for our users (400 response instead of
500) and we cut down on 500 errors for things that are not expected to
work.

* Capitalization

Co-authored-by: Michael Matloka <dev@twixes.com>
2021-07-01 18:48:09 +03:00
Karl-Aksel Puulmann
7f33dcd9cb
Don't error if trying to filter by person_id which does not exist (#4916)
Sentry error: https://sentry.io/organizations/posthog/issues/2240057229/?project=1899813&query=is%3Aunassigned+is%3Aunresolved
2021-06-29 19:30:34 +02:00
Michael Matloka
5394533bde
Don't fire webhooks and Zapier in case of PLUGIN_SERVER_ACTION_MATCHING (#4794)
* Don't fire webhooks and Zapier in case of PLUGIN_SERVER_ACTION_MATCHING

* Add PLUGIN_SERVER_ACTION_MATCHING to settings

* Add PLUGIN_SERVER_ACTION_MATCHING to ECS task defs

* Remove leftover print

* Update `AsyncActionMappingNotice`

* Remove stale import
2021-06-18 16:32:29 +02:00
Tim Glaser
1da9084e83
Closes #4679 fix deleting persons (#4734) 2021-06-14 10:17:38 -04:00
Eric Duong
bb9b6b42f2
Engagement cohorts (#4510)
* add migration

* add fields

* remove comment

* change to is_deleted

* Update migration to work

* Update tests

* initial functions

* fix params

* add migration

* add named param

* working test

* update person prop and cohort tests

* use var

* move sql and fstring

* remove get inside django signal

* just create the table

* add replication logic

* add param

* change replacing name

* refactor and add event based cohorts

* add type

* add to model

* add test for event_id

* move sql

* add sql

* make sure actions work too and add test

* add ability to create cohort by event count

* glob match cypress cache

* fix type

* fix type

* refactor and add datetime support

* fix ordering issue in test

* add timestamp test

* fix type

* fix more types

* use var resolution

* add operators

* add necessary filter and test

* add call for calculating cohort on create

* add triggers to oncreate and onupdate

* breakup test and remove repeated subquery

Co-authored-by: Karl-Aksel Puulmann <oxymaccy@gmail.com>
Co-authored-by: Michael Matloka <dev@twixes.com>
2021-06-11 13:59:57 -04:00
Eric Duong
3fe1d29ca6
Event query class (#4649)
* first try

* add entity query

* fix type issues

* used in trends

* fix test

* change select format

* change var

* add cohort filter

* add cohort conditions

* change pdi to distinct_ids
2021-06-10 14:47:33 -04:00
Eric Duong
8cc90dff67
make sure to add table name to prop clauses on breakdown query (#4607)
* make sure to add table name to prop clauses so that event/person properties column isn't vague

* pass table name when formatting breakdown query

* add test
2021-06-08 13:45:55 -04:00
Eric Duong
3eeb770e0b
Use cohortpeople table for queries (#4622)
* use cohortpeople table for queries

* add check

* make sure timestampe is offset aware
2021-06-07 19:16:03 -04:00
Eric Duong
ff43c9f0aa
Collapsing table cohortpeople (#4428)
* add migration

* add fields

* remove comment

* change to is_deleted

* Update migration to work

* Update tests

* initial functions

* fix params

* add migration

* add named param

* working test

* update person prop and cohort tests

* use var

* move sql and fstring

* remove get inside django signal

* just create the table

* add replication logic

* add param

* change replacing name

* make sure actions work too and add test

* add necessary filter and test

* add triggers to oncreate and onupdate

Co-authored-by: Karl-Aksel Puulmann <oxymaccy@gmail.com>
Co-authored-by: Michael Matloka <dev@twixes.com>
2021-06-07 10:16:21 -04:00
Michael Matloka
8ef727634e
Syncing action definition changes with plugin server (#4436)
* Save Organization.available_features as a DB column

* `update_available_features()` before an organization is created too

* Run the task half past the hour

* Adjust tests and fix available_features sync on start

* Improve action and property TS types

* Use plugin server ActionManager pubsub

* Use better pubsub channel names for plugin server ActionManager

* Fix PubSub's lack of teamId

* Use f-strings for property CH SQL formatting
2021-05-31 11:10:36 +02:00
Yakko Majuri
a16af1aeaf
Fix CH event getter API endpoint (#4161)
* Fix CH event getter API endpoint

* fix mypy

* add test

* update test

* update handling

* satisfy mypy

* add new tests

* code quality

* fix foss test
2021-05-21 14:02:19 -03:00
Eric Duong
85bc250dac
Prune unused ee code (#4410)
* prune model functions

* prune more misc
2021-05-20 10:15:03 -04:00
Eric Duong
84d20f436b
add support for comparing floats (#4381) 2021-05-18 15:43:25 -04:00
Tim Glaser
99cdd640d3
Rename is_ee_enabled to is_clickhouse_enabled (#4216)
* Rename is_ee_enabled to is_clickhouse_enabled

* Do frontend as well

* Fix import

* fix
2021-05-13 16:56:54 +02:00
Karl-Aksel Puulmann
008ee1f04c
Include more clickhouse query metrics (#4256)
* Use `statshog` over python-statsd

More support for tags!

* Include custom tags for every query + add annotation to query

After this we can:
- Figure out from query logs where queries are coming from (speeding up debugging)
- Break down query speeds by user queries vs others (e.g. celery) --
better represents overall speed
- Can figure out how fast queries are on average for various teams

* Use tags in more queries over interpolation

This way we can set up more interesting graphs \o/

* Solve mypy error

* Fix a flaky test (due to ordering)
2021-05-10 10:47:54 +03:00
Tim Glaser
9d62061107
Simplify query (#4228) 2021-05-07 15:56:29 +03:00
Michael Matloka
e96f95ef5a
Plugin log entries (#3482)
* Add Postgres model PluginLogEntry

* Add equivalent PluginLogEntry to Kafka+ClickHouse

* Add migration

* Add PluginLogEntry.Type.LOG & make PluginLogEntry.message a TextField

* Update 0130_pluginlogentry.py

* Add PluginLogEntry.instance_id

* Update migration

* Update migration

* Add plugin log entries API

* Test plugin log entries DB fetching

* Add PluginLogs component prototype

* Fix API

* Improve PluginLogs component

* Remove almost unused plugin Feedback button

* Update migration

* Fixed typing

* Fix org permission error test asserts

* Fix plugin log entry tests

* Fix CH plugin log entry timestamp string

* Update CH test_plugin_log_entry.py

* Fix plugin log entry tests across PG/CH

* Satisfy mypy

* Add search and limit to plugin log entry API

* Send team_id in plugin config API

* Rework plugin logs UI

* Add plugin config team ID in tests

* Add plugin config team ID in tests actually

* Fix code quality

* Make logs plugin config-based

* Fix CH queries

* Fix typing

* Improve UX and fix things

* Polish plugin logs logic

* Update migration

* Add Celery task to delete old plugin logs

* Fix UX bug with loading more plugin logs

* Fix missing import

* Remove OrganizationMemberPermissions message change

* Make mypy happy

* Add PluginLogEntry.is_system

* Optimize CH plugin_log_entires PARTITION/ORDER

* Increment migration

* Adjust plugin logs drawer display

* Fix plugin_log_factory_ch

* Fix plugin_log_factory_ch fix

* Replace PluginLogEntry.is_system with source

* Adjust PluginLogEntrySerializer

* Update CH fetch_plugin_log_entries

* Make kea-typegen happy
2021-05-06 10:54:32 +03:00
Tim Glaser
0bfa2784cb
Fix action error with gt (#4209)
* Fix action error with gt

Closes #4195

* fix type
2021-05-04 19:37:29 +02:00
Eric Duong
954069b00d
Swap out person_distinct_id in queries with subquery (#3828)
* swap out distinct_id table in queries with a subquery that will only consider latest distinct_ids

* wrong import

* fix missin params

* more missing params
2021-04-01 12:56:42 -04:00
Paolo D'Amico
29bf59cc2b
Backend tests refactor (#3774) 2021-03-31 19:00:58 -07:00
Eric Duong
1768b89ea8
change created_at to _timestamp (#3820)
* change created_at to _timestamp

* remove test
2021-03-30 17:37:53 -04:00
Marius Andra
90d16b24a7
Support multiple entries for selector and tag_name filter for EE (#3766)
* support multiple entries for selector and tag_name filter for EE

* improve support for multiple selector matches

* test for multiple selectors and tag names
2021-03-30 10:56:22 +02:00
Tim Glaser
80216306a7
Fix multiple people same distinct id (#3768) 2021-03-29 11:56:12 +02:00
Eric Duong
c59f8b7739
Add element matching for multiple values on text/href (#3739)
* fix element matching for multiple values on text/href

* pg implementation

* use diff solution

* fix smell

* none check

* move function

* remove circular import
2021-03-25 11:00:49 -04:00
Paolo D'Amico
6cc09eaef7
Support custom identifier for person name (#3581) 2021-03-23 15:40:37 -07:00
Tim Glaser
bf2c4429b5
Auto filter test accounts (#3492)
* WIP auto filter test accounts

* finish off

* Fix tests

* Non generic emails

* add list of generic emails

* Move location to below property filters

* Fix typescript errors

* as any

* fix tests

* filters

* fix tests

* Featureflag doesn't really makes sense for this feature

* fix tests

* fix test

* Add clickhouse + tests for each insight

* Fix lifecycle and paths

* Fix sessions

* Fix session tests

* fix sesisons test

* fix migrations

* fix migration chain

* refactor path & remove stale console.log

* adjust useAnchor & minor copy

* rename to avoid confusion with inline component

* test account filter tweaks

* fix filters

* hardcode

* Add tests for funnel trends

* Make generic emails super fast

* Fix migrations

* Default to false for now

* Default to false, remember a user's preference

Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com>
2021-03-11 18:16:38 +01:00
Karl-Aksel Puulmann
a96d682ca1
Fix getting earliest timestamp on EE with no events (#3501)
Sentry error: https://sentry.io/organizations/posthog/issues/2236839278/?project=1899813&query=is%3Aunassigned+is%3Aunresolved
2021-02-26 15:31:22 +02:00
Karl-Aksel Puulmann
828c301299
Fix filtering sessions by action with property filters (#3500)
Fixes #3499
2021-02-26 11:24:31 +02:00
Karl-Aksel Puulmann
f36495bec6
Filters: Select multiple for equality/inequality (#3422)
* Don't colorize sql for output

* Handle setting array props as values

* Handle arrays exact/is_not property filters

Also updates tests to use parameterization

* Avoid autoclosing PropertyFilter popup

As key changes, old one got removed from DOM

* Improve filter UX

Don't allow filter to become multi-line and keep inputs the same size.

Previous flex={1} was doing flex: 1 1 auto which was messing things up

* Fix typescript issue

* Handle array lookups in postgres

* Update types

* Fix fixture to recreate tables

* Make replace spaces logic consistent with what was there before

* Handle list filtering better in postgres

* Update frontend tests

* Handle edge case: Switching between multi operator and single operators
2021-02-25 16:54:55 +02:00
PostHog bot
146469770b
Update plugin server to 0.9.24 (#3445)
* Update plugin server to 0.9.24

* Add more hook metrics in Python

Co-authored-by: posthog-bot <posthog-bot@users.noreply.github.com>
Co-authored-by: Michael Matloka <dev@twixes.com>
2021-02-23 18:07:06 +01:00
Karl-Aksel Puulmann
07d6974d08
Add some missing team_id filters (#3372)
Tested out a solution for #3085 - result is super noisy but helped me
find some bad queries.
2021-02-19 08:49:09 +02:00
Michael Matloka
33838a188c
Prefilter post_event_to_webhook_ee more (#3368) 2021-02-17 19:59:28 +01:00
Tim Glaser
68d335ca22
Fix filtering on elements clickhouse (#3354)
* Fix filtering on elements clickhouse

* fix typing

* fix
2021-02-17 13:48:45 +01:00
Karl-Aksel Puulmann
95630f7a6b
Return no data for invalid regexes (#3248)
* Return no data if invalid regular expression

This currently returns a 500. Fixes 3191 together with frontend
validation.

* Add browser validation

* Typing errors
2021-02-11 21:53:58 +02:00
Tim Glaser
cf2cdb0c58
Fix ints saved as strings clickhouse (#3289)
* Fix ints saved as strings clickhouse

* remove ipdb
2021-02-10 19:59:30 +01:00
Michael Matloka
78d39741ed
Use elements_chain in EE webhook (#3273) 2021-02-09 18:56:42 +01:00
Michael Matloka
828770f48b
REST/webhook optimizations (#3267)
* Ignore erroneous webhook firing prefiltering

* Optimize EE web/RESThook firing
2021-02-09 18:31:50 +01:00
Karl-Aksel Puulmann
259a2290b4
Serialize/deserialize elements_chain on webhooks_ee (#3262)
Solves https://sentry.io/organizations/posthog/issues/2207757069/?project=1899813&query=is%3Aunassigned+is%3Aunresolved
2021-02-09 13:54:02 +01:00
Michael Matloka
62846fd565
Capture EE webhook task sending error (#3254) 2021-02-09 11:25:52 +01:00
Michael Matloka
973769340a
Revert "Revamp and optimize hooks on EE (#3119)" (#3249)
This reverts commit 5485fb058d.
2021-02-09 10:16:38 +01:00
Michael Matloka
5485fb058d
Revamp and optimize hooks on EE (#3119)
* Revamp and optimize hooks on EE

* Improve retry strategy

* Improve some minor things

* Cache available_features in memory

* Address feedback
2021-02-09 09:52:19 +01:00
Tim Glaser
bd068e96db
Simplify cohort queries (#3165) 2021-02-02 19:45:11 +01:00
Tim Glaser
108a50264f
Remove emails from csv (#3115)
* Add team filter to cohort query to speed up

* Fix querying

* Remove emails from CSV upload

* fix clickhouse email
2021-01-28 11:43:46 +01:00
Karl-Aksel Puulmann
dba58f4467
Hotfix for missing session recording events (#3069)
* Hotfix for missing session recording events

Temporarily solves https://github.com/PostHog/posthog/issues/2927,
though the error will rear it's head again with plugin-based ingestion.

Opened https://github.com/PostHog/posthog/issues/3068 for long-term
solution.

* kwargs everywhere

* use settings over kwargs
2021-01-27 13:12:55 -08:00
Eric Duong
2fef10315b
Add missing logic for action days in cohort calculating (#3056)
* add missing logic

* add test

* fix type
2021-01-26 13:26:32 +01:00
Eric Duong
cba416b9de
add try statement for deleting persons incase the table is dsitrbuted (#3042) 2021-01-21 15:30:09 -05:00
Tim Glaser
62c5e18358
Fix multiple actions in funnel (#3011) 2021-01-20 15:53:34 +01:00
Tim Glaser
02044c616f
Denormalize clickhouse props (#2903)
* Denormalize clickhouse props

* Add allow_denormalized_props option

* Use funnels

* fix funnel query

* Add more denormalized props

* Fix comma

* Use materialized columns instead of mat views

* duplicate ,'s

Co-authored-by: James Greenhill <fuziontech@gmail.com>
2021-01-20 12:38:27 +01:00
Karl-Aksel Puulmann
9354b7ce64
Highlight filtered events in events table and in session recording (#2954)
* Highlight rows from sessions which are matched by the filter

* Send start_time of recording to frontend

This helps us calculate offsets a bit better

* Use timestamp by server for date shown

* Load session events via kea logic

* Update rrweb, rrweb-player

* Highlight events user is filtering for in sessions player

* Handle empty case properly

* Add positive test

* Order session recording events in query

* Fix filtering by multiple events with differing names

previously only the first would have been used due to overlapping
params.

* Return all highlighted times as action_filter_times

* Send back ids not timestamps

This avoids weird rounding errors causing issues

* Show skeleton for longer

* update typing

Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com>
2021-01-19 21:16:42 -06:00
Karl-Aksel Puulmann
3009e0aa2e
Support multiple action filters in sessions (#2946)
* Make it possible to filter by (multiple) action filters in postgres

Session will now contain "action_filter_times" key which lists when each
action filter occurred for the first time within the session.

This will be used to highlight rows/show special values in sessions
player.

* Clickhouse: support multiple action filters

* Remove dead code
2021-01-15 11:28:46 +01:00
Tim Glaser
1a6207d791
Upload static cohort csv (#2932)
* Upload static cohort using CSV, closes #2868

* fix tests

* Fix tests

* Fix e2e test

* Avoid double inserts

* Speed up query

* Move to params

* fix tests

* Use JSON instead of protobuf

* unused import

* produce instead of produce_proto

* Insert directly into clickhouse, no need for kafka

* a few quick fixes

* insert in batch to clickhouse

* test SQLi since we can't really trust what we are inserting

* Extra check for duplicates

Co-authored-by: James Greenhill <fuziontech@gmail.com>
2021-01-15 11:19:31 +01:00
Michael Matloka
5d5ede19e4
Fix REST hook firing (#2894)
* Fix REST hooks being only fired if project has webhook

* Fix firing more

* Actually still filter but also for Zapier

* Don't .only() Team in EE process_event to optimize REST hook firing

* Fix REST hook duplication in EE

* Update test_process_event.py

* Debug

* Revert "Debug"

This reverts commit 6d4c9f754d.

* Fix organization-less teams partly

* Fix more organization-less teams

* Fix moar organization-less teams

* Explicitly bootstrap org without user in tests

* Fix org bootstrap

* Fix typing

* Fix bootstrap usage

* Update test_process_event.py

* Fix num queries

* Add test_action_on_perform_hook_fired_once

* Fix Action.objects.create call

* Don't test hook firing as it's offloaded to worker
2021-01-12 13:09:27 +01:00
Tim Glaser
40f121deb1
Limit events correctly (#2867)
* Only grab recent events in Events list

* Limit events from clickhouse with fallback

* fix events

* Remove ipdb

* Fix
2021-01-06 18:35:27 +01:00
Karl-Aksel Puulmann
bcffd30092
Allow going from insights -> sessions (on cloud) (#2790)
* extract code to format entity filter

* make it possible to filter by action

* Hack to make filtering by actions subfilters possible

Example url:
http://localhost:8000/api/event/sessions?date_from=2020-12-10&date_to=2020-12-10&action_filter={%22type%22:%22events%22,%22id%22:%22test-event%22,%22properties%22:[{%22key%22:%22email%22,%22value%22:%22example.com%22,%22operator%22:%22icontains%22,%22type%22:%22person%22}]}

Not sure if the team filtering is legit here

* Use discriminated union in types

* Add kludge support for action_filter on sessions via url

* Reduce code in buildURL

* Add link to sessions page from persons modal

* Add muted overview of the invisible filter

* Add link to cohort sessions from persons page

* drop irrelevant test code

* Test clickhouse filtering by action filter

* put filter behind a cloud-only conditional

* remove dead import

* Add icons/data-attr to sessions links

* Appease linter gods
2021-01-06 12:59:52 +02:00
Eric Duong
6241a2b8a3
Quick fix to limit time range on event prop query (#2844)
* add range limit on props

* add exception handler

* fix time limit
2021-01-04 14:02:38 -05:00
Karl-Aksel Puulmann
4a3b154909
Allow * in action selector (#2820)
* Refactor filtering by selector tests

* Support action selector * in clickhouse actions

Fixes https://github.com/PostHog/posthog/issues/2819
2021-01-04 11:35:23 +02:00
Tim Glaser
3f7e95d14a
Improved insights history (#2745)
* Deprecate dashboard item type and move to display

* Mypy rerors

* fix test

* fix

* Fix test

* Fix another test

* WIP save history refactor

* Remove determineInsightType

* Progress

* Get rid of RetentionTable display types

* Sync all together

* Fix update dashboard

* Improved saving

* More bugfixes

* Fix insight caching and filters

* Fix insights

* Fix tests

* Fix import

* Fix saving issues

* Don't duplicate

* fix

* Use session instead of session_type everywhere for consistency

* Remove prints

* Use get_filter

* Fix retention filters

* Fix UI issues

Co-authored-by: Michael Matloka <dev@twixes.com>
2020-12-16 16:37:55 +01:00
Eric Duong
25d60bf839
Fix prop filtering when action has props (#2711)
* add prepend clause to prop filtering

* add defaults and parametrize an event field

* add test and make the fix generalized
2020-12-09 13:19:58 -05:00
Tim Glaser
adcf493202
Fix ee webhook (#2664)
* Fix ee webhook

* Get rid of warnings

* Add webhooks
2020-12-04 16:43:22 +01:00
Tim Glaser
d60799c4f8
Fix nan values (#2665)
* Fix nan values

* unused imports
2020-12-04 16:27:08 +01:00
Eric Duong
997ec36916
Lifecycle Graph (#2460)
* intial working

* intial working with test

* return tests

* fix interval and add monthly test

* add in person_id join

* small restyle

* postgres lifecycle working

* add action handling to postgres query

* add action handling and tests

* fix typing

* visualizing with temp params and added negatives for dormant

* frontend

* fix intervals

* remove unnecessary import

* add person enppoint

* add person endpoint and tests

* add next

* add pagianted test

* fix types

* add frontend logic'

* fixed date range

* disable compare filter on lifecycle

* add diasbled to chartfilter

* return class to personviewset

* added constant

* fix distinct_id and new event within period condition

* replace people queries and fix ch query too

* DRY

* fix null states

* comparefilter nullstate

* add wrapper back to endpoint

* fix datetime formatting

* remove extra stack flag

* reduce filters when it's lifecycle and replace constants

* add default for lifecycle into trendlogic
2020-12-02 16:53:06 +01:00
Eric Duong
98932d0c3a
1936 retention graph (#2578)
* intiial graph on PG

* initial frontend

* fix filtering and types

* clickhouse working

* change reference date

* fix label and defaults

* fix multiple event retention

* working clickhouse and postgres for multiple events

* remove final

* remove sql parse

* add inital person query

* working clickhouse person query and return testrunner

* implement postgres retrieve person

* add endpoint and pagianted test

* click on datapoint works

* fix params

* fix action handling

* people paginated backend

* finished paginatino frontend logic

* fix variable naming for pg

* working first time persons for clickhouse

* first time people working for pg

* dont replace if recurring

* run again

* fix import

* refactor filter to retention specific and move postgres

* convert clickhouse to use new filter

* move imports

* fix types

* fix types

* fix initial load

* adding to dashboard works

* fixed defaults

* add test for dates

* fix insight panel

* add seert

* fix import

* fix date select for people

* fix chartfilterlogic

* remove unneded comment and import

* split up retention query
2020-12-01 10:15:50 -05:00
Eric Duong
5ddfe6c30d
Revert "Retention graph and multiple event fix (#2534)" (#2577)
This reverts commit bb076eedad.
2020-11-30 16:40:22 -05:00
Eric Duong
bb076eedad
Retention graph and multiple event fix (#2534)
* intiial graph on PG

* initial frontend

* fix filtering and types

* clickhouse working

* change reference date

* fix label and defaults

* fix multiple event retention

* working clickhouse and postgres for multiple events

* remove final

* remove sql parse

* add inital person query

* working clickhouse person query and return testrunner

* implement postgres retrieve person

* add endpoint and pagianted test

* click on datapoint works

* fix params

* fix action handling

* people paginated backend

* finished paginatino frontend logic

* fix variable naming for pg

* working first time persons for clickhouse

* first time people working for pg

* dont replace if recurring

* run again

* fix import

* refactor filter to retention specific and move postgres

* convert clickhouse to use new filter

* move imports

* fix types

* fix types

* fix initial load

* adding to dashboard works

* fixed defaults

* add test for dates

* fix insight panel

* add seert

* fix import

* fix date select for people

* fix chartfilterlogic
2020-11-30 16:09:23 -05:00
Tim Glaser
260b999093
Revert "Retention graph and multiple event fix (#2405)" (#2532)
This reverts commit e90857900e.
2020-11-26 15:52:45 +01:00
Eric Duong
e90857900e
Retention graph and multiple event fix (#2405)
* intiial graph on PG

* initial frontend

* fix filtering and types

* clickhouse working

* change reference date

* fix label and defaults

* fix multiple event retention

* working clickhouse and postgres for multiple events

* remove final

* remove sql parse

* add inital person query

* working clickhouse person query and return testrunner

* implement postgres retrieve person

* add endpoint and pagianted test

* click on datapoint works

* fix params

* fix action handling

* people paginated backend

* finished paginatino frontend logic

* fix variable naming for pg

* working first time persons for clickhouse

* first time people working for pg

* dont replace if recurring

* run again

* fix import

* refactor filter to retention specific and move postgres

* convert clickhouse to use new filter

* move imports

* fix types

* fix types

* fix initial load

* adding to dashboard works

* fixed defaults

* add test for dates

* fix insight panel

* add seert

* fix import

* fix date select for people
2020-11-26 15:18:37 +01:00
Eric Duong
ec45964d0a
Fix prop filter not formatting properly (#2386)
* force parsed

* robust fix

* remove sql parse
2020-11-26 13:48:17 +01:00
Michael Matloka
96e4ee8512
Nest endpoints of project-based models under /api/project/ – LITE (#2485)
* Nest endpoints under /project/ with StructuredViewSetMixin

* Rewrite URLs

* isort

* Update utils.py

* Fix errors

* Fix almoast all the errors

Last left to do: shared dashboards and permission classes.

* isort

* Adjust for master

* Add compatbility with shared dashboards

* Debug ClickHouse

* Remove some # type: ignores

* Simplify CursorPagination

* Move test base from posthog.api.test to posthog.test

* Improve API structure

* Bring back legacy endpoints

* Fix legacy compatibility

* Fix bugs and typing

* isort

* Fix hooks test

* Try fixing errors

* Fix oversight

* isort

* Fix problems

* isort

* Be more tolerant

* Fix naming and remove redundant code

* Fix imports

* Update deleteWithUndo

* Roll back

* Roll back more

* Update .gitignore

* Rollll back

* Rollllllll

* back

* Betterify

* Address feedback
2020-11-24 23:26:28 +01:00
Tim Glaser
78c2ae74ac
Fix filtering is not bool (#2435)
* Fix filtering is not bool

* don't commit settings
2020-11-18 19:30:16 +01:00
Tim Glaser
b41381c149
Fix empty actions in cohorts (#2411)
* Fix empty actions in cohorts

* Dont show calculating in clickhouse

* Fix
2020-11-18 16:30:29 +01:00
Paolo D'Amico
9ad483064b
Refactor people & users to persons (#2413) 2020-11-17 08:40:48 -06:00
Eric Duong
fdaba70781
remove test for now (#2383) 2020-11-13 14:30:10 -05:00
Eric Duong
b68b4397ed
remove webhooks ee (#2373) 2020-11-13 10:52:41 -05:00
Eric Duong
fae9fe5238
Fix doubled up slack hook (#2340)
* fix doubled up and change name

* Fix test

Co-authored-by: Tim Glaser <tim@glsr.nl>
2020-11-12 08:31:32 -05:00
Eric Duong
92b41eeaff
Trends consolidation (#2339)
* inital consolidation

* split out result processing

* restore alltime for pg

* prune unsed imports and fix empty state

* reduce param logic

* initial reduction

* move cumulative

* improve reuse

* handle empty action

* more consolidation

* fix types
2020-11-12 12:54:45 +01:00
Karl-Aksel Puulmann
a3f055429a
Cache cohorts from clickhouse / make /decide fast (#2316)
* Cache cohorts in clickhouse

This fixes #2306

* Calculate celery

* Schedule cohorts recalculation once per hour

* Run cohort calculations each in separate task

* Fix max age in cohort recalculation

* Simplify

Co-authored-by: Tim Glaser <tim@glsr.nl>
2020-11-12 12:58:35 +02:00
Eric Duong
7bcbd44ca3
fix queries (#2299) 2020-11-09 18:17:46 -05:00
Eric Duong
3ba655fbb9
Revert "Revert "Fix person created at (#2288)" (#2293)" (#2297)
This reverts commit e38da34a40.
2020-11-09 17:36:44 -05:00
Eric Duong
e38da34a40
Revert "Fix person created at (#2288)" (#2293)
This reverts commit 5b75520b7d.
2020-11-09 15:43:45 -05:00
Tim Glaser
5b75520b7d
Fix person created at (#2288) 2020-11-09 20:43:26 +01:00
Tim Glaser
7d0b983505
Fix actions grouping by OR (#2276) 2020-11-09 10:40:16 +00:00
Tim Glaser
efc62e1999
Fix feature flags clickhouse (#2170)
* remove person properties up to date

* remove person props mv

* move latest person

* prune rest of person materialized

* missing parenth

* add type

* remove migration

* Fix feature flags clickhouse

* Fix feature flags clickhouse

* Fix types

* Fix stuff

* Silly me

Co-authored-by: Eric <eeoneric@gmail.com>
2020-11-05 16:01:32 +01:00
Eric Duong
7a5bcab99e
Restore slack hook (#2186)
* add back hook

* add back hook

* filter event matcher

* create artificial event to query for actions

* fix test

* possible solution

* remove printer

* reformat

* remove test_event temp

* comment out tests

* comment out

* uncomment

* patch another

* reduce var

* fix timestamp
2020-11-05 14:40:30 +01:00
Michael Matloka
76307429d2
Fix Sentry issue POSTHOG-13K (#2180)
* Fix Sentry issue POSTHOG-13K

* Ignore typing on line

* Black
2020-11-04 11:08:28 +01:00
Tim Glaser
a07eed7d2e
Simplify action queries (#2167)
* Simplify funnel and action query

* Fix type errors

* Update test_action.py

* Move more over to avoid_loop

* Simplify query everywhere

* Fix black

* Fix

* Fix everything

* Fix black

* Fix filtering

* Move or join
2020-11-03 16:06:25 +01:00
Eric Duong
96a614ee25
Prune person materialized (#2166)
* remove person properties up to date

* remove person props mv

* move latest person

* prune rest of person materialized

* missing parenth

* add type

* remove migration
2020-11-02 15:44:38 -05:00
Tim Glaser
119a3e7a9a
Fix elements chain with bad classes (#2133) 2020-11-02 19:24:02 +01:00
Paolo D'Amico
066721e3c1
Stability & dev experience improvements (#2152) 2020-11-02 14:55:20 +00:00
Karl-Aksel Puulmann
6b4889ebf1
Make DELETE synchronous in clickhouse tests / make tests less flaky (#2116)
* Make DELETE synchronous in clickhouse tests

This avoids some flaky behavior, example:
- https://github.com/PostHog/posthog/pull/2110/checks?check_run_id=1327279229

Documentation:
- https://clickhouse.tech/docs/en/operations/settings/settings/#mutations_sync

Tested it out by running the following test 1000 times - before change
it fails every ~50 runs locally.

```
         def test_delete_person(self):
-            person = person_factory(
-                team=self.team, distinct_ids=["person_1", "anonymous_id"], properties={"$os": "Chrom
e"},
-            )
-            event_factory(event="test", team=self.team, distinct_id="person_1")
-            event_factory(event="test", team=self.team, distinct_id="anonymous_id")
-            event_factory(event="test", team=self.team, distinct_id="someone_else")
-
-            response = self.client.delete(f"/api/person/{person.pk}/")
-            self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
-            self.assertEqual(response.data, None)
-            self.assertEqual(len(get_people()), 0)
-            self.assertEqual(len(get_events()), 1)
-
-        def test_filters_by_endpoints_are_deprecated(self):
+            for index in range(1000):
+                print([index])
+                person = person_factory(
+                    team=self.team, distinct_ids=["person_1", "anonymous_id"], properties={"$os": "Chrome"},
+                )
+                event_factory(event="test", team=self.team, distinct_id="person_1")
+                event_factory(event="test", team=self.team, distinct_id="anonymous_id")
+                event_factory(event="test", team=self.team, distinct_id="someone_else")
+
+                response = self.client.delete(f"/api/person/{person.pk}/")
+                self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
+                self.assertEqual(response.data, None)
+                self.assertEqual(len(get_people()), 0)
+                self.assertEqual(len(get_events()), 1)
```

* Add a if not TEST clause to deleting from materialized view

This blew up clickhouse when we try to force the delete to happen sync.
Created an upstream issue: https://github.com/ClickHouse/ClickHouse/issues/16548
2020-10-30 19:38:55 +01:00
Tim Glaser
f150cd2256
Clickhouse move to JSON extract for all filters (#2056)
* Clickhouse move to JSON extract for all filters

* fix test

* Fix ordering
2020-10-29 20:49:44 +01:00
James Greenhill
01099a5ffd
Provide required proto message length for our clickhouse overlords (#2087) 2020-10-28 16:48:05 -07:00
James Greenhill
83b5273113
Protobufize events to protect from malformed JSON (#2085)
* Protobuf all the things

* oops

* Protobufize events to protect from malformed JSON

* format the generated files (will need to remember this for future)

* format

* clean up kafka produce serializer

* fixes
2020-10-28 15:18:52 -07:00
Karl-Aksel Puulmann
e3bf0cb31d
Session recording on clickhouse, separate tables and retention cronjob (#2051)
* Add scheduled task to wipe session recordings

* Create a new table for session recording

* Save snapshot events to different table

* Use SessionRecordingEvent over Events everywhere

We can remove a ton of cruft this way as well

* Add missing signature

* Extract util from models/event

* Attempt to update ingest side of clickhouse session recording events

Note that it's using main kafka topic - not sure if a good idea.

* Get separate table in ch working for session recording events

* WIP: query sessions

* Make both session recording queries work

* Make linter happy

* Rebase migration

* Make tests work

* Apply a TTL to session recordings and other configuration:

- toYYYYMMDD partitioning should be smoother with TTL setup
- TTL achieves not needing to archive the data ourselves
- index_granularity will enable smaller reads per session_id
- ORDER BY clause is to make single session as well as time range query
  reasonable

* Convert retention cronjob to new model

* Add tests to process_event changes

* Add test for ee_capture change

* Fixup migration

* Make clickhouse tests drop/create session recording tables

* Make TTL not be there in tests

Otherwise writes get eaten by it during tests when mocking time

* Fix retention task

Co-authored-by: Tim Glaser <tim@glsr.nl>
2020-10-28 21:22:16 +01:00
Eric Duong
a3239921f3
Fix loading people and stickiness (#2067)
* don't use person_up_to_date_view and fix entity timestamp

* add test

* remove broken statement

* add test
2020-10-28 19:08:37 +01:00
Tim Glaser
c8bf1d0a37
Fix cohorts clickhouse (#2052)
* use json extract inside steps for funnelq eury

* remove print

* fix broken query and add person prop filtering in funnel with test

* Fix cohorts in clickhouse

* Fix types

* Fix funnels

* fix tests

* Fix tests

* Fix cohorts breakdown

* Remove unused code

* Update description

* Remove negation

Co-authored-by: Eric <eeoneric@gmail.com>
2020-10-27 21:43:38 +01:00
Eric Duong
5bb713626b
Use jsonextract for steps in funnel query (#2040)
* use json extract inside steps for funnelq eury

* remove print

* fix broken query and add person prop filtering in funnel with test
2020-10-27 17:52:12 +01:00
Eric Duong
3b217c3bcc
Update person property filtering (#2024)
* change person prop base and fix cohort query

* try clear signal

* remove signal
2020-10-26 08:00:23 -04:00
Tim Glaser
21d240df30
[Clickhouse] Fix grabbing by person (#1960)
* Use postgres to grab person

* Fix type

* Fix grabbing by person id

* Fix type

* WIP people from clickhouse

* Fix person delete etc

* fix test

* Fix tests
2020-10-23 17:30:12 +02:00
Eric Duong
d226b4b5b4
Add tests to important query builders (#2006)
* add default tests

* add action filter_event test

* add test to parse_prop_clauses

* add ordering to session list

* fix tests and funnel

* run again
2020-10-23 08:39:41 -04:00
Eric Duong
51105ace47
Add new person matieralized (#1944)
* add new table migrations and change table names

* include necessaray config for new tables in tests

* fix tests and table

* fix table name param

* add populate clause

* added table for key value person props

* adjust person filtering to use new table

* .

* add ordering on updated_at

* add back all the condition handling on persons filtering endpoint

* fix typgin

* remove print

* re-order sort key for persons_up_to_date

Co-authored-by: James Greenhill <fuziontech@gmail.com>
2020-10-22 13:22:43 -07:00
Eric Duong
cecb7510b8
General Reorganization (#1981)
* small tweaks and reorganize session queries

* move all queries to query folder
2020-10-22 07:35:57 -04:00
Eric Duong
17a46f7193
Revert "Revert "Use postgres to grab person"" (#1971)
* Revert "Revert "Use postgres to grab person (#1957)" (#1963)"

This reverts commit 94f44bdf46.

* Filter by team_id

Co-authored-by: Tim Glaser <tim@glsr.nl>
2020-10-22 11:05:37 +02:00
Michael Matloka
533c7df105
Organization<>Team<>User structure (closes #1540) (#1562)
* Backend changes to implement #1461

* Added the missing migration files

* Fixes Typecheck errors

* Refactor request.user.team_set.get() to use request.user.team

* Updated user patch method to change current_team on team id instead of name

* Merged migration file

* Changes team property to return first item in queryset

* Fixes failing tests

* Changed User api to return the ids of the teams they are currently part of

* Frontend for changing teams

* Update and simplify migrations

* Improve team and user buttons

* Make team changing backend more logical

* Improve current_team mechanics

* Update test_team.py

* Fix Team.objects.create_with_data

* Update migration

* Update tests

* Make setup_review more convenient

* Add Organization and OrganizationMembership

* Replace is_admin with level

* Extend API

* Update team.py

* Improve modeling

* Improve handling of new mechanics

* Add proper migration

* Remove _ensure_organization_and_team

* Update 0084_org_team_user.py

* Improve user, org and team creation

* Make MembershipLevel more flexible for the future

* Add member deletion

* Fix naive datetime warnings

* Update setup_review.py

* Update API route

* Make PersonalAPIKey changes

* Update models and migrations, fix typing

* Fix typing

* Use MAC-less UUID v1 instead of v4 for better performance

* Add abstract UUIDModel

* Update utils.py

* Update utils.py

* Fix multi/unicast bit

* Update APIs, frontend and tests

* Update pull_request_template.md

* Fix comment

* Fix migration error

* Compress migrations

* Updates with minimal renaming

* More updates

* Make further updates

* Update test_team_user.py

* Fix issues

* Add migration

* Satisfy mypy

* Remove Signup redirect on logged in

* Use uuid1_macless in Person

* Fix typing

* Update tests

* Update /api/team/signup to /api/organization/signup

* Fix mypy issues and update tests

The remaining failures are actually missing functionality (TDD applied), so filling these in.

* Update 0086_org_live

* Make small improvements

* Implement permissions

* Remove now unneccesary membership check

* Update setup_dev.py

* Make small frontend improvements

* Add drf-nested-routers as requirement

* Remove unused import

* Implemented nested routes

* Remove cruft

* Add relevant org/proj/user name to headings

* Fix imports

* Update migration

* Replace unreliable drf-nested-routers with drf-extensions

* Improve unset team handling

* Make org and team creation proper

* Update migration

* Fix migration

* Update TopContent

* Update command palette for new sidebar structure

* Remove deprecated demo data deletion

* Assume that each org has a project and fix typing

* Require paid plan for multiple orgs and projects

* Make HogFlix demo a separate team

* Update migration

* Slightly improve style

* Adjust page layout bottom padding

* Make user dropdown nicer

* Fix base app tests

* Satisfy mypy

* Fix test_leave_organization

* Improve wording

* Possibly fix import

* Remove misplaced None check

* Enhance org and teams APIs and add tests

* Fix /api/projects for particular Team

* Improve invites and demo data

* Address feedback

* Put everything related to billing on Organization

* Fix minor issues

* Simplify invitation creation

* Update team model

* Make orgs and projects premium only on self-hosted

* Improve testing

* Update migration

* Remove extra License import

* Fix minor issues

* Fix Django tests

* Fix Cypress

* Fix yarn build

* Fix TeamSignupViewset

* Fix posthog-production incompatibility

* Remove extraneous insight endpoint registration

* Adjust tests for posthog-production

* Simplify invitations and fix email validation

* Address all feedback

* Satisfy mypy

* Update migration

* Fix constraint removal in migration

* Update tests

* Fix test creation edge case

* Run posthog-production CI tests against this branch and teams-live

* Ensure that js_posthog_api_key is always passed

* Fix preflight check pre-login

* Update cypress tests

* Update instanceStatus.js

* Bring ee tets up to par

* Bring actions-ux-201012 back

* Cypress retry in cypress.json

* Revert "Run posthog-production CI tests against this branch and teams-live"

This reverts commit d79cb844d8.

Co-authored-by: anna <ms.annaphilips@gmail.com>
Co-authored-by: Anna Philips <aphilips@matmacorp.com>
2020-10-22 10:58:32 +02:00
James Greenhill
7ab30a836c
Remove Omni-Person logic for ee (#1972)
* Remove Omni-Person logic for ee

* remove more omni person references
2020-10-21 14:06:45 -07:00
James Greenhill
b74d06a96a
Create a write ahead log for cloud event processing (#1962)
* Create a write ahead log for cloud event processing

* mypy fix

* if we are on app (ee) don't log to postgres

* don't disable writing to postgres
2020-10-21 20:35:07 +02:00
Tim Glaser
94f44bdf46
Revert "Use postgres to grab person (#1957)" (#1963)
This reverts commit 6d9f4d7f77.
2020-10-21 20:34:49 +02:00
Tim Glaser
6d9f4d7f77
Use postgres to grab person (#1957)
* Use postgres to grab person

* Fix type
2020-10-21 17:11:55 +02:00
Eric Duong
2a7cd8c477
Fix negation operators (#1941)
* fixed negation operators for person and cohorts

* add person negation test

* fix tests

* add leakeage tests

* add space

* add debug statements

* match distinct_id
2020-10-21 07:12:05 -04:00
Eric Duong
44b9ea6b45
Reorganize trends (#1931)
* reorganized trends.py

* reorder functions

* prune unused imports
2020-10-20 04:24:18 -04:00
Eric Duong
8e5347b4e1
Implement property filtering operators (#1886)
* change parsing to include operators'

* make properties test into factory

* add clickhouse test implementation and fix another test

* add custom test to clickhouse filter tests

* all tests besides json filtering

* add json test

* fix tests

* fix type errors
2020-10-19 06:01:01 -04:00
Tim Glaser
cff8cb2134
Fix issues with elements matching (#1918)
* Fix issues with elements matching

* Add correct regex
2020-10-17 16:10:42 +02:00
Eric Duong
1c7db177b7
prune unused action code (#1914) 2020-10-16 21:55:43 +02:00
Tim Glaser
80d20e385b
Clickhouse use elements chain (#1849)
* Clickhouse use elements chain

* Fix stuff

* Add action tests and start regex

* Progress

* Progress part deux

* Fix everything

* Add tag name filtering

* Fix funnels

* Fix tag name regex

* Fix ordering

* Fix type issues

* Fix empty nth-child

* Remove commented code

* Split with semicolon and escaped quotes

* Specify all select columns
2020-10-16 14:07:03 +02:00
Eric Duong
2d60a5b670
Retention date filtering (#1788)
* working date filter

* frontend for period

* remove period

* add params

* add period

* period working

* add test for period

* merge master

* fix test

* add dropdowns for period date filtering

* pass params and handle properly

* fix labels and readjust tests

* test split for retentino period

* make insight retention test just test for response

* add condition

* feature flag the frontend and bring back ff for the ch endpoint

* fix cohort filtering

* fix cohort querying

* remove init

* remove feature flag

* add back featureflag

* block person modal on retention page if clickhouse enabled

* use distinct_id instead of joining for person_id
2020-10-14 10:28:27 -04:00
Eric Duong
0f3969bb53
add check (#1873) 2020-10-14 07:09:16 -04:00
Eric Duong
72fe8fdff9
Trim quotes on event properties (#1852)
* addquote trimmer

* fix tests

* remove unnecessary check
2020-10-13 09:39:24 -04:00
Eric Duong
133620362e
Fill in person filtering and reintegrate tests (#1848)
* add person filtering

* add person prop breakdown

* add tests

* fix padding

* fix tests and aliasing

* fix tests again

* fix filter

* reorder tests

* drop test temp

* add identified

* add test back
2020-10-13 08:33:20 -04:00
Eric Duong
58ecefd9c8
Add per entity filtering (#1838)
* add per entity filtering to breakdown and regular queries on trends page

* add test for per entity filtering on trends
2020-10-13 08:17:24 -04:00
Tim Glaser
c9fc4ac245
Fix clickhouse sessions (#1815) 2020-10-09 17:48:28 +03:00
Tim Glaser
2cad2b16ec
[Clickhouse] fix event filtering (#1804) 2020-10-02 20:31:53 +02:00
Tim Glaser
88c54896d0
Fix person querying (#1797)
* convert sessions table logic to TS

* convert rest of sessions to TS

* sessions table logic refactor, store date in the url

* add back/forward buttons

* load sessions based on the URL, not after mount --> avoids duplicate query if opening an url with a filter

* prevent multiple queries

* throw error if failed instead of returning an empty list

* date from filters

* rename offset to nextOffset

* initial limit/offset block

* indent sql

* support limit + offset

* load LIMIT+1 sessions in postgres, pop last and show load more sign. (was: show sign if exactly LIMIT fetched)

* based offset is always 0

* default limit to 50

* events in clickhouse sessions

* add elements to query results

* add person properties to sessions query response

* show seconds with two digits

* fix pagination, timestamp calculation and ordering on pages 2 and beyond

* mypy

* fix test

* add default time to fix test, fix some any(*) filter issues

* remove reverse

* WIP event list

* Events progress

* Finish off event listing, skip live actions for now

* Fix mypy

* Fix mypy again

* Try fixing mypy

* Fix assertnumqueries

* Fix tests

* Fix tests

* fix test

* Fix tests

* Fix tests

* Fix tests again

* Fix person querying

* Fix flake

* Fix person stuff

* Fix test

Co-authored-by: Marius Andra <marius.andra@gmail.com>
Co-authored-by: Eric <eeoneric@gmail.com>
2020-10-02 19:30:05 +02:00
Tim Glaser
92e8bbd283
[Clickhouse] Event list (#1787)
* convert sessions table logic to TS

* convert rest of sessions to TS

* sessions table logic refactor, store date in the url

* add back/forward buttons

* load sessions based on the URL, not after mount --> avoids duplicate query if opening an url with a filter

* prevent multiple queries

* throw error if failed instead of returning an empty list

* date from filters

* rename offset to nextOffset

* initial limit/offset block

* indent sql

* support limit + offset

* load LIMIT+1 sessions in postgres, pop last and show load more sign. (was: show sign if exactly LIMIT fetched)

* based offset is always 0

* default limit to 50

* events in clickhouse sessions

* add elements to query results

* add person properties to sessions query response

* show seconds with two digits

* fix pagination, timestamp calculation and ordering on pages 2 and beyond

* mypy

* fix test

* add default time to fix test, fix some any(*) filter issues

* remove reverse

* WIP event list

* Events progress

* Finish off event listing, skip live actions for now

* Fix mypy

* Fix mypy again

* Try fixing mypy

* Fix assertnumqueries

* Fix tests

* Fix tests

* fix test

* Fix tests

* Fix tests

* Fix tests again

Co-authored-by: Marius Andra <marius.andra@gmail.com>
Co-authored-by: Eric <eeoneric@gmail.com>
2020-10-01 15:47:35 +02:00
Marius Andra
80a699ef4e
Clickhouse Sessions + Frontend Sessions updates (#1754)
* convert sessions table logic to TS

* convert rest of sessions to TS

* sessions table logic refactor, store date in the url

* add back/forward buttons

* load sessions based on the URL, not after mount --> avoids duplicate query if opening an url with a filter

* prevent multiple queries

* throw error if failed instead of returning an empty list

* date from filters

* rename offset to nextOffset

* initial limit/offset block

* indent sql

* support limit + offset

* load LIMIT+1 sessions in postgres, pop last and show load more sign. (was: show sign if exactly LIMIT fetched)

* based offset is always 0

* default limit to 50

* events in clickhouse sessions

* add elements to query results

* add person properties to sessions query response

* show seconds with two digits

* fix pagination, timestamp calculation and ordering on pages 2 and beyond

* mypy

* fix test

* add default time to fix test, fix some any(*) filter issues

* remove reverse

* fix mypy error, indent SQL

* add pagination test for postgres

* Run insight API tests in Clickhouse

Co-authored-by: Eric <eeoneric@gmail.com>
2020-10-01 05:27:35 -04:00
James Greenhill
379518e285
"Clickhouse Features V2 (#1565)" (#1750)
* initial

* migration command

* migrations working

* add modelless views for clickhouse

* initial testing structure

* use test factory

* scaffold for all tests

* add insight and person api

* add basic readme

* add client

* change how migrations are run

* add base tables

* ingesting events

* restore delay

* remove print

* updated testing flow

* changed sessions tests

* update tests

* reorganized sql

* parametrize strings

* element list query

* change to seralizer

* add values endpoint

* retrieve with filter

* pruned code to prepare for staged merge

* working ingestion again

* tests for ee

* undo unneeded tests right now

* fix linting

* more typing errors

* fix tests

* add clickhouse image to workflow

* move to right job

* remove django_clickhouse

* return database url

* run super

* remove keepdb

* reordered calls

* fix type

* fractional seconds

* fix type error

* add checks

* remove retention sql

* fix tests

* add property storage and tests

* merge master

* fix tests

* fix tests

* .

* remove keepdb

* format python files

* update CI env vars

* Override defaults and insecure tests

* Update how ClickHouse database gets evaluated

* remove bootstrapping clickhouse database routine

* Don't initialize the clickhouse connection unless we say it's primary

* .

* fixed id generation

* remove dump

* black settings

* empty client

* add param

* move docker-compose for ch to ee dir

* Add _public_ key to repo for verifying self signed cert on server

* update ee compose file for ee dir

* fix a few issues with tls in migrations

* update migrations to be flexible about storage profile and engine

* black settings

* add elements prop tables

* add elements prop tables

* working filter

* refactored

* better url handling

* add mapping table

* add processing to worker task

* working cohort with actions

* add cohort property filtering

* add cohort property filtering

* reformat and add cohort processing

* prop clauses

* add util

* add more util

* add clickhouse modifier

* Clickhouse Sessions (#1623)

* sessions sql

* skeleton

* add endpoint

* better tests

* sessions list

* merge clickhouse-actions

* added session endpoint

* sessions sql working again

* add clickhouse modifier

* session avg with props working

* add dist

* tests working (no list)

* list working

* add formatting

* more formatting

* fix tests

* dummy commit

* fix types

* remove unnecessary improt

* ignore type when importing from ee in task

* fix test running

* Clickhouse Trends Base (#1609)

* initial working

* date param almost working

* fix date range and labels

* fixed monthly math

* handle compare

* change table

* using new event ingestion

* direct query actions working

* remove interface

* fix date range

* properties initial working

* handle operator

* handle operator

* move timestamp parse

* move more to util

* inital breaking down working

* working cohort breakdown

* some tests running

* fix sessions

* cohort tests

* action and interval test

* reorder cohort filtering

* rename retention test

* fix inits

* change multitenancy tests

* fix types

* fix optional types

* replace ch_client.execute with sync_execute

* replace ch_client.execute with sync_execute, part 2

* Clickhouse Stickiness + Process Event (#1654)

* generate clickhouse uuid script

* set CLICKHOUSE_SECURE=False by default if running in TEST or DEBUG

* convert person_id to UUID, make adding `person_id` optional, add distinct_ids already in the `create_person` function

* Fix test_process_event_ee.py, remove all calls to Person.objects.*

* add back util

* fix broken imports

* improve process_event test clickhouse queries

* Basic stickiness query

* Clickhouse Stickiness tests

* stickiness test [WIP, actions fail]

* generate clickhouse uuid script

* change default test runner if PRIMARY_DB=clickhouse

* fix stickiness test for actions

* fix merge bug

* remove _create_person stub; cohort person_id is UUID now

* fix typing

* Clickhouse trends process math (#1660)

* most of process math works

* all process math

* fix ordering issue

* unusued imports

* update property comparison for process_event_ee

* indentation wrong missing calls

* demo users and events (#1661)

* finish breakdown filtering tests and reformat label function

* add increment to demo_data

* update demo data populating

* Add people endpoint for ch (#1670)

* add people endpoint for ch

* stickiness people

* fix value padding

* add process math to breakdown and

* add limit

* fix tests

* condensed code

* converted test to factory

* add people tests

* add month handling

* add typing fix

* change people test handling

* fix tests

* Clickhouse funnels 2 (#1668)

* add elements to create_event

* WIP closes #1663 Add funnels to clickhouse

* Make funnels work

* Clean up

* Move filtering around

* Add mypy tests and fix

* Performance improvements

* fix person tests again

* add people for funnel endpoint

* fix prop numbering

Co-authored-by: Marius Andra <marius.andra@gmail.com>
Co-authored-by: Eric <eeoneric@gmail.com>

* merge master

* add retention

* update types

* more typing errors

* fix types

* bug with kafka payload, elements insert, and demo data

* Clickhouse Paths (#1657)

* paths clickhouse test (fails)

* add elements to create_event

* make this fail for clickhouse

* hardcoded query that returns good results for $pageviews, no filters yet

* clean up queries

* bound by time, fix 30min new session boundary

* support screen and custom events

* add properties filter

* paths url

* filter by path start

* better path start test

* even better path start test

* start from the first "path start" in a group

* test for person_id in paths

* partition by person_id for POSTGRES paths

* partition by person_id for Clickhouse paths

* clean up order in paths test

* clean up order in paths test

* join elements

* force element order on element group creation

* remove "order" when creating elements in tests and demo

* get list of elements for paths

* add limit to paths query

* use materialized view

* rename "element_hash" to "elements_hash" (no change in db)

* cull rows that are definitely unused

* simplify query

* New highly optimized paths clickhouse query

* start_point for $autocapture paths

* extract event property values from clickhouse

* prevent crash

* select one element sql

* get elements for event

* remove lodash

* remove host from $pageview path elements if same domain as incoming path

* show metadata based on loaded paths filter, not in flight filter

* fix order (all soures and targets in order, not all sources first, then all targets after) - makes for a better looking graph

* add test that makes the Postgres paths query fail

* fix postgres paths --> no fuzzy matching, breaks "starts with" for urls and gives too many incorrect start points

* create automatic /demo urls that match the real urls (no ending /)

* fix elements queries

* path element joins

* create persons via postgres in paths test

* change serializers back to id

* fix tests with uuid

* fix demo

* more bugs

* fix type

* change now to timezone aware

* [clickhouse] retention filters (#1725)

* implemented target entity and prop filtering

* add insight view override

* fix endpoint and filters

* include tests

* fix tests

* add period filtering

* .

* fix pg param name

* add filtering params to both queries in retention sql

* fix param again

* change to todatetime

* change tz to timezone

* add back timezone in model/event

* [clickhouse] feature flag endpoint requests (#1731)

* add feature flags to endpoints

* add flags to endpoints that check on request

* remove magic strings and fill in missing flags

* fix types

* add missing flag

* change from iso

* fix more timestamps and comparator

* change _people to get_people in actions view

* remove action and cohort populating

* change inheritance

* "Clickhouse Features V2 (#1565)"

This reverts commit 0b371d43ec.

* fix types

* change to super

* change to super x2

Co-authored-by: Eric <eeoneric@gmail.com>
Co-authored-by: Marius Andra <marius.andra@gmail.com>
Co-authored-by: Tim Glaser <tim.glaser@hiberly.com>
2020-09-29 15:17:26 +01:00
Michael Matloka
13e32aaff9
Replace uuid4 and uuid1_macless with UUIDT (#1726)
* Replace uuid1_macless with UUIDT

* Add machine_component

* Update comment

* Remove machine_component in favor of larger time_component

* Update UUIDT docstring
2020-09-29 15:39:18 +02:00
James Greenhill
0b371d43ec
Revert "Clickhouse Features (#1565)" (#1748)
This reverts commit 24713b923d.
2020-09-29 12:11:28 +01:00
Eric Duong
24713b923d
Clickhouse Features (#1565)
* initial

* migration command

* migrations working

* add modelless views for clickhouse

* initial testing structure

* use test factory

* scaffold for all tests

* add insight and person api

* add basic readme

* add client

* change how migrations are run

* add base tables

* ingesting events

* restore delay

* remove print

* updated testing flow

* changed sessions tests

* update tests

* reorganized sql

* parametrize strings

* element list query

* change to seralizer

* add values endpoint

* retrieve with filter

* pruned code to prepare for staged merge

* working ingestion again

* tests for ee

* undo unneeded tests right now

* fix linting

* more typing errors

* fix tests

* add clickhouse image to workflow

* move to right job

* remove django_clickhouse

* return database url

* run super

* remove keepdb

* reordered calls

* fix type

* fractional seconds

* fix type error

* add checks

* remove retention sql

* fix tests

* add property storage and tests

* merge master

* fix tests

* fix tests

* .

* remove keepdb

* format python files

* update CI env vars

* Override defaults and insecure tests

* Update how ClickHouse database gets evaluated

* remove bootstrapping clickhouse database routine

* Don't initialize the clickhouse connection unless we say it's primary

* .

* fixed id generation

* remove dump

* black settings

* empty client

* add param

* move docker-compose for ch to ee dir

* Add _public_ key to repo for verifying self signed cert on server

* update ee compose file for ee dir

* fix a few issues with tls in migrations

* update migrations to be flexible about storage profile and engine

* black settings

* add elements prop tables

* add elements prop tables

* working filter

* refactored

* better url handling

* add mapping table

* add processing to worker task

* working cohort with actions

* add cohort property filtering

* add cohort property filtering

* reformat and add cohort processing

* prop clauses

* add util

* add more util

* add clickhouse modifier

* Clickhouse Sessions (#1623)

* sessions sql

* skeleton

* add endpoint

* better tests

* sessions list

* merge clickhouse-actions

* added session endpoint

* sessions sql working again

* add clickhouse modifier

* session avg with props working

* add dist

* tests working (no list)

* list working

* add formatting

* more formatting

* fix tests

* dummy commit

* fix types

* remove unnecessary improt

* ignore type when importing from ee in task

* fix test running

* Clickhouse Trends Base (#1609)

* initial working

* date param almost working

* fix date range and labels

* fixed monthly math

* handle compare

* change table

* using new event ingestion

* direct query actions working

* remove interface

* fix date range

* properties initial working

* handle operator

* handle operator

* move timestamp parse

* move more to util

* inital breaking down working

* working cohort breakdown

* some tests running

* fix sessions

* cohort tests

* action and interval test

* reorder cohort filtering

* rename retention test

* fix inits

* change multitenancy tests

* fix types

* fix optional types

* replace ch_client.execute with sync_execute

* replace ch_client.execute with sync_execute, part 2

* Clickhouse Stickiness + Process Event (#1654)

* generate clickhouse uuid script

* set CLICKHOUSE_SECURE=False by default if running in TEST or DEBUG

* convert person_id to UUID, make adding `person_id` optional, add distinct_ids already in the `create_person` function

* Fix test_process_event_ee.py, remove all calls to Person.objects.*

* add back util

* fix broken imports

* improve process_event test clickhouse queries

* Basic stickiness query

* Clickhouse Stickiness tests

* stickiness test [WIP, actions fail]

* generate clickhouse uuid script

* change default test runner if PRIMARY_DB=clickhouse

* fix stickiness test for actions

* fix merge bug

* remove _create_person stub; cohort person_id is UUID now

* fix typing

* Clickhouse trends process math (#1660)

* most of process math works

* all process math

* fix ordering issue

* unusued imports

* update property comparison for process_event_ee

* indentation wrong missing calls

* demo users and events (#1661)

* finish breakdown filtering tests and reformat label function

* add increment to demo_data

* update demo data populating

* Add people endpoint for ch (#1670)

* add people endpoint for ch

* stickiness people

* fix value padding

* add process math to breakdown and

* add limit

* fix tests

* condensed code

* converted test to factory

* add people tests

* add month handling

* add typing fix

* change people test handling

* fix tests

* Clickhouse funnels 2 (#1668)

* add elements to create_event

* WIP closes #1663 Add funnels to clickhouse

* Make funnels work

* Clean up

* Move filtering around

* Add mypy tests and fix

* Performance improvements

* fix person tests again

* add people for funnel endpoint

* fix prop numbering

Co-authored-by: Marius Andra <marius.andra@gmail.com>
Co-authored-by: Eric <eeoneric@gmail.com>

* merge master

* add retention

* update types

* more typing errors

* fix types

* bug with kafka payload, elements insert, and demo data

* Clickhouse Paths (#1657)

* paths clickhouse test (fails)

* add elements to create_event

* make this fail for clickhouse

* hardcoded query that returns good results for $pageviews, no filters yet

* clean up queries

* bound by time, fix 30min new session boundary

* support screen and custom events

* add properties filter

* paths url

* filter by path start

* better path start test

* even better path start test

* start from the first "path start" in a group

* test for person_id in paths

* partition by person_id for POSTGRES paths

* partition by person_id for Clickhouse paths

* clean up order in paths test

* clean up order in paths test

* join elements

* force element order on element group creation

* remove "order" when creating elements in tests and demo

* get list of elements for paths

* add limit to paths query

* use materialized view

* rename "element_hash" to "elements_hash" (no change in db)

* cull rows that are definitely unused

* simplify query

* New highly optimized paths clickhouse query

* start_point for $autocapture paths

* extract event property values from clickhouse

* prevent crash

* select one element sql

* get elements for event

* remove lodash

* remove host from $pageview path elements if same domain as incoming path

* show metadata based on loaded paths filter, not in flight filter

* fix order (all soures and targets in order, not all sources first, then all targets after) - makes for a better looking graph

* add test that makes the Postgres paths query fail

* fix postgres paths --> no fuzzy matching, breaks "starts with" for urls and gives too many incorrect start points

* create automatic /demo urls that match the real urls (no ending /)

* fix elements queries

* path element joins

* create persons via postgres in paths test

* change serializers back to id

* fix tests with uuid

* fix demo

* more bugs

* fix type

* change now to timezone aware

* [clickhouse] retention filters (#1725)

* implemented target entity and prop filtering

* add insight view override

* fix endpoint and filters

* include tests

* fix tests

* add period filtering

* .

* fix pg param name

* add filtering params to both queries in retention sql

* fix param again

* change to todatetime

* change tz to timezone

* add back timezone in model/event

* [clickhouse] feature flag endpoint requests (#1731)

* add feature flags to endpoints

* add flags to endpoints that check on request

* remove magic strings and fill in missing flags

* fix types

* add missing flag

* change from iso

* fix more timestamps and comparator

* change _people to get_people in actions view

* remove action and cohort populating

Co-authored-by: James Greenhill <jams@uber.com>
Co-authored-by: Marius Andra <marius.andra@gmail.com>
Co-authored-by: Tim Glaser <tim.glaser@hiberly.com>
2020-09-29 06:36:50 -04:00
James Greenhill
d4b6f38e08
Use Django now for tz aware timestamps (#1728)
* Use Django now for tz aware timestamps

* include datetime for type checking
2020-09-28 06:30:21 -04:00
James Greenhill
82031580b3
Use utcnow(). Always default to UTC (#1727) 2020-09-28 10:26:39 +01:00
James Greenhill
2bb97b8efa
Do not shadow Kafka default columns _timestamp and _offset (#1718)
* Do not shadow Kafka default columns _timestamp and _offset

* drop the columns only on the kafka_ tables

* include data types

* fields cleanups

* datetime -> datetime64

* double import datetime
2020-09-25 16:23:48 +01:00
James Greenhill
1ed6263a71
Create Omni-Person model for managing people in Clickhouse (#1712)
* Create Omni-Person model for managing people in Clickhouse

* type fixes

* rebase all the things

* cleanups

* id -> uuid for events in clickhouse

* cleanups and type checks

* Further cleanups and uuid conversions

* kafka fix

* break out serializer across kafka clients

* fix a few bugs w/ datetime types

* basic fix for people kafka table

* fix migration errors (copy pasta errors)

* Use KafkaProducer for Omni Person emitting

* setup mock kafka producer

* undo some work for inserting

* Test TestKafkaProducer

* change if order, obvious mistake

* remove unnecessary function arg

* Fix getters for new column

* Test fixes

* mirror columns across element queries

* firm up handling of timestamps

* only return timestamps for handle_timestamp

* Correct heroku config for Kafka
2020-09-25 11:05:50 +01:00
Marius Andra
dd7e38c5b5
Clickhouse Elements Dedup (based on master) (#1698)
* Use ReplacingMergeTree for elements, remove element_groups and use elements_hash as a virtual "pk"

* remove unused ELEMENT_GROUP_TABLE_SQL

* merge fixes

* use redis cache to avoid writing duplicate elements to clickhouse

* move fakeredis to requirements.txt

* add team_id to cache key

* remove elements_group kafka table references

* add elements_hash to clickhouse element serializer

* fix cache key

* rename few keys

* add test runner to ease pycharm dev

* fix a some mypy errors

* remove typo

Co-authored-by: Eric <eeoneric@gmail.com>
2020-09-24 06:47:28 -04:00
Marius Andra
1eeed28751
Fix Master EE code (#1701)
* add test runner to ease pycharm dev

* fix broken import

* drop and recreate the clickhouse test db before running tests

* fix person uuid str json serialization issue

* make kafka optional in tests

* fix inits

* remove need for kafka in person.py

* fix a bunch of mypy errors

* fix function and add process_event to pipeline

* fixed missing params and tests

* change uuid and fix types

* types

* optimize for merge prop test

* make ClickhouseProducer to produce to clickhouse one way or another

* annotate types

Co-authored-by: Eric <eeoneric@gmail.com>
Co-authored-by: James Greenhill <fuziontech@gmail.com>
2020-09-24 06:14:17 -04:00
Michael Matloka
8a629179a9
Organizations – models (#1674)
* Update only models

* Bring in line with master and use uuid1_macless

* Update models and annotation scope support

* Delete test_team_model.py

* Update user creation, team retrieval and fix tests

* Make fixes

* Rename migration

* Fix migrating from master

* Bring back previous company_name max_length

* Use get_price_id()

* Temporarily disable team member deletion

* Update user joining and leaving, and billing

* Improve first_name handling

* Update warning

* Update TestTeamUser

* Fix migration

* Update 0085_org_models.py

* Improve bootstrapping

* Move multitenancy price tests to posthog-production

* Update team_user.py

* Update setup_review.py

* Enhance opt_slash_path

* Update team.py

* Fix default test email

* Fix typing
2020-09-24 00:53:51 +02:00
James Greenhill
97a665d277
Leverage Postgres for Persons and reorder order by's on clickhouse" (#1681)
* Query optimizations

* more sql optimizations

* checkpoint

* fix migration

* add UUID field to person

* use django signals to signal that clickhouse needs to be updated

* cleanup person logic

* cleanups

* update migration

* Don't setup the django signals unless we are for sure using ee setup

* expecting back to 30 queries for capturing with new person

* add .venv to .gitignore

* add env back to .gitignore

Co-authored-by: Ubuntu <ubuntu@ip-172-31-73-18.ec2.internal>
2020-09-22 13:41:08 +01:00
James Greenhill
463ce40ba6
Make get_is_identified more tolerant of missing person (#1675)
* Make get_is_identified more tolerant of missing person

* better test of out of range
2020-09-17 09:26:58 -07:00
James Greenhill
adeb7694cc
Publish events to Kafka for consumption (#1644)
* Publish events to Kafka for consumption

* Commit avro idl's for event schemas

* convert client to use github.com/dpkp/kafka-python

* events loaded into clickhouse from Kafka

* remove cruft

* Publish events to Kafka for consumption

* convert client to use github.com/dpkp/kafka-python

* remove cruft

* include kafka migrations

* bugfixes for migrations

* use constants for consistency

* wrap up local migrations

* small fixes

* tune ups
2020-09-15 20:04:38 -07:00
Marius Andra
50c683e691
Clickhouse process event (#1652)
* generate clickhouse uuid script

* set CLICKHOUSE_SECURE=False by default if running in TEST or DEBUG

* convert person_id to UUID, make adding `person_id` optional, add distinct_ids already in the `create_person` function

* Fix test_process_event_ee.py, remove all calls to Person.objects.*

* add back util

* fix broken imports

* improve process_event test clickhouse queries

* change property parsing

* indentation wrong missing calls

* uuid4 instead of call to CH

Co-authored-by: Eric <eeoneric@gmail.com>
Co-authored-by: James Greenhill <fuziontech@gmail.com>
2020-09-15 12:40:35 -07:00
James Greenhill
70868fc7db
Final ClickHouse module before wiring up to Posthog (#1617) 2020-09-08 21:00:37 -07:00
James Greenhill
f2680a61e3
clickhouse models (#1614) 2020-09-08 18:55:01 -07:00
James Greenhill
dedf5582c1
first chunk of clickhouse framework (#1613)
* first chunk of clickhouse framework

* prod, not dev docker-compose.yml

* add clickhouse sql files
2020-09-08 16:12:27 -07:00
James Greenhill
c2e03a3a46
Revert this to bring back the working copy of ee / clickhouse (#1588) 2020-09-04 21:12:07 -07:00
James Greenhill
8e26357770
Async writes to clickhouse (#1585)
* Initial commit async-ing clickhouse

* Async writes to clickhouse

* deconflict master

* sync events listing

* mypy checks
2020-09-04 17:46:02 -07:00
James Greenhill
5506135c3c
Bring back clickhouse changes along with queue size metrics (#1579)
* Revert "Revert "Clickhouse setup (#1463)""

This reverts commit 7f2cab4b93.

* add queue backlog to _stats endpoint

* celery queue length into heartbeat -> statsd

* reformat

* type check fixes

* bump expected number of queries to 8

Co-authored-by: Eric <eeoneric@gmail.com>
2020-09-04 13:44:53 -07:00
James Greenhill
7f2cab4b93 Revert "Clickhouse setup (#1463)"
This reverts commit a0327587cb.
Time to process events shot way up and logs are missing.
2020-09-03 19:27:02 -07:00
Eric Duong
a0327587cb
Clickhouse setup (#1463)
* initial

* migration command

* migrations working

* add modelless views for clickhouse

* initial testing structure

* use test factory

* scaffold for all tests

* add insight and person api

* add basic readme

* add client

* change how migrations are run

* add base tables

* ingesting events

* restore delay

* remove print

* updated testing flow

* changed sessions tests

* update tests

* reorganized sql

* parametrize strings

* element list query

* change to seralizer

* add values endpoint

* retrieve with filter

* pruned code to prepare for staged merge

* working ingestion again

* tests for ee

* undo unneeded tests right now

* fix linting

* more typing errors

* fix tests

* add clickhouse image to workflow

* move to right job

* remove django_clickhouse

* return database url

* run super

* remove keepdb

* reordered calls

* fix type

* fractional seconds

* fix type error

* add checks

* remove retention sql

* fix tests

* add property storage and tests

* merge master

* fix tests

* fix tests

* .

* remove keepdb

* format python files

* update CI env vars

* Override defaults and insecure tests

* Update how ClickHouse database gets evaluated

* remove bootstrapping clickhouse database routine

* Don't initialize the clickhouse connection unless we say it's primary

* .

* fixed id generation

* remove dump

* black settings

* empty client

* add param

* move docker-compose for ch to ee dir

* Add _public_ key to repo for verifying self signed cert on server

* update ee compose file for ee dir

* fix a few issues with tls in migrations

* update migrations to be flexible about storage profile and engine

* black settings

* add elements prop tables

Co-authored-by: James Greenhill <jams@uber.com>
2020-09-03 10:27:45 -07:00