0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-28 09:16:49 +01:00
Commit Graph

1003 Commits

Author SHA1 Message Date
Karl-Aksel Puulmann
cae9b59779
Fix lifecycle rounding logic (#8057) 2022-01-18 09:52:49 +02:00
Paolo D'Amico
eafa0225ce
More pre-instrumentation for collaboration (#8049) 2022-01-17 13:23:45 -08:00
Paul D'Ambra
ac72b61eb0
Auto detect property types when ingesting events (#7923)
* stores numeric type for property definitions

* writes property definition type for strings

* can write dates for simple string cases as property definition type

* simplify property definition types

* can detect unix timestamps

* rewmove a little more from the test duplication

* some more timestamp thinking

* clearer comment

* rename refactor in tests

* more test correction

* address test failure

* another test fix

* property type as enum

* simplify type detection

* apply typing suggestion

* allow property definition type and format to be set if property is present but they are null

* add more date types for property_type_formats

* add more datetime formats that the backend can accept and filter events with

* delete conflicting migration

* add migration for backend datetime formats

* plugin server can auto detect all the types the backend knows about. And the tests are collapsed from twenty five almost identical tests to two different parameterised blocks

* iso 8601 strings can have fractional seconds

* add link to the RFC 822 regex pattern

* capitalise SQL

* capitalise the SQL the mock looks for too

* remove the under-eager cache change that allowed updating existing property definitions

* convert property type formats to enum

* fix test

* try detecting a property type for existing property definitions but don't keep retrying

* use symbols to make cache state clearer

* fix idiocy

* speculative LRU cache usage with measurement

* tag the statsd guages instead of having team id in the name

* don't pre-emptively optimise the cache

* rename migration

* remove spaces from query strings

* separate property definition code from the team manager

* a little tidying

* correct type definition

* correct test params setup
2022-01-14 15:48:20 +00:00
Neil Kakkar
aa7a37c5e2
Fix Experimentation bug (#8061) 2022-01-14 13:08:03 +00:00
Paolo D'Amico
2c5d9997ca
Extra sessions cleanup (#8037) 2022-01-13 19:20:47 -06:00
Paul D'Ambra
1974cbb3d2
Remove hard-coded DateTime knowledge from Property Filter UI (#7892)
* wip

* display known unix timestamps as date strings in property filter select box

* show selected unix timestamp property as a datetime string in the property filter

* remove console.log

* update test to construct property definition correctly

* correct another test

* dates have different operators

* format property filter values for display in Select boxes and the PropertyValue component

* fix typescript error

* it _is_ a type, I don't need to say it is

* don't have before and after for unmatched types of operators

* separate the current applicable operators and the operator to display mapping, and add cypress tests for before and after operator visibility

* correct cypress test

* remove unused method

* remove dangling comment

* why does test fail in CI but not locally

* why does test fail in CI but not locally

* why does test fail in CI but not locally

* log values of operator options, why does this fail in CI but not locally

* why does test fail in CI but not locally

* intercept more decide calls to try and set feature flags from cypress test

* why does test fail in CI but not locally

* Remove cypress install

* add a readme for how to test feature flags so it isn't lost if there are no tests currently testing feature flags
2022-01-13 20:10:39 +00:00
Karl-Aksel Puulmann
39f91a6d82
Drop sessions backend support (#8022) 2022-01-13 11:40:11 -06:00
Karl-Aksel Puulmann
d9bc06b7dd
Speed up lifecycle query (#8021)
* refactor(lifecycle): simplify clickhouse sql logic

This updates the SQL to be comprised of two queries, one for getting
new, returning, and resurrecting periods of activity, one for getting
dormant periods right after periods of activity.

Refers to https://github.com/PostHog/posthog/issues/7382

* refactor(lifecyle): use `ClickhouseEventQuery` to build event query

* format

* Use bounded_person_activity_by_period for both sides of dormant join

* refactor(lifecycle): reduce pdi2 join by one

This means we're now under the current query memory limit for orgs with
around 20m distinct_ids. It does remove some readability though :(

* update snapshot

* Add further comments to query

* Add further comments to query

* Add further comments to query

* Remove dead variables

* Refactor person_query overriding

* Lifecycle refactoring continued

* Update lifecycle tests (except people ones)

* Make lifecycle people endpoint happy

* Remove django lifecycle tests

* Add some edge case tests

* Add missing type

Co-authored-by: Harry Waye <harry@posthog.com>
2022-01-13 16:31:09 +02:00
Marius Andra
066c172c81
Case insensitive property searching (#8020)
* case insensitive searching

* select direct match, even if case is different
2022-01-13 15:16:28 +01:00
Li Yi Yu
c1cd3280e4
Fix experimentation updating (#7986)
Co-authored-by: Neil Kakkar <neilkakkar@gmail.com>
2022-01-13 13:53:43 +00:00
Karl-Aksel Puulmann
d459dc4ca8
Benchmarks: trends breakdown and lifecycle with filtering (#8018)
* Add benchmarks for trends breakdown

* Add lifecycle benchmarks
2022-01-13 11:53:00 +02:00
Eric Duong
836d5609f3
Fix element chain on autocapture (#7992) 2022-01-12 13:38:57 -06:00
Karl-Aksel Puulmann
784c7d3b08
Related groups query refactor (#7978)
* Resolve weird SQL formatting issue

* Use a discriminated union for ActorType

* Use standard response types for related groups

* Update typing

* Always filter related actors by group type index

* Update snapshots & typing
2022-01-12 13:15:43 +02:00
Karl-Aksel Puulmann
1ccb45f678
Allow renaming group types (#7974)
* Migration to add name_singular and name_plural to groups

* Allow modifying group type names

* Use name_plural and name_singular through the app

* Update tab names

* fixup

* Update snapshots
2022-01-12 09:31:43 +00:00
Li Yi Yu
21b52dc98a
Add trends option to experiment (#7947)
* add trends option to experiment

(cherry picked from commit be9b8911f9)

* connect trends experiments

* clean up some stuff

* fix test

* results chart display for trends

* fix some issues with trends

* add in loading states and different insight types results wording

* move experiment results into loader

* add progress bar and clean up loading state

* fix experiment insight type bug

* add text beneath percent bar

* typing..

* single filter hide duplicate row button

Co-authored-by: Neil Kakkar <neilkakkar@gmail.com>
2022-01-11 18:50:35 -05:00
Neil Kakkar
83c1e4c41c
Ensure deleting an experiment deletes the associated FF (#7981)
* ensure deleting an experiment deletes the associated FF

* address comment

* use FF serializer

* ensure FF variants are distributed correctly
2022-01-11 16:39:24 +00:00
Yakko Majuri
7479f141b3
fix tests (#7984) 2022-01-11 12:18:00 -03:00
Yakko Majuri
fb22989e02
show last event ingested timestamp in system status (#7979)
* show last event ingested timestamp in system status

* fix tests
2022-01-11 14:17:10 +00:00
Neil Kakkar
bed26c1c8f
reduce precision on trend experiment result tests (#7982) 2022-01-11 13:51:26 +00:00
Michael Matloka
54716379c3
Clarify PostHog person deletion quirk (#7977)
* Don't delete events from Postgres since we don't do it on CH

* Update frontend for accuracy

* Update test_person.py

* Don't display "ID-less user" as a link
2022-01-11 13:26:46 +00:00
Yakko Majuri
10d8c59146
auto complete non required async migrations at migrate step (#7942) 2022-01-10 15:34:07 -03:00
Guido Iaquinti
b7235282e9
Remove references to 'CLICKHOUSE_INITIAL_MIGRATIONS' (#7960) 2022-01-10 12:14:50 +02:00
Rick Marron
a3906d7f1c
Add recordings to trends person modal (#7852)
* add events for recordings to actor response in trends

* order of events doesnt matter in tests

* fix snapshots

* move to recordings objects

* filter to actual recording

* rename include_matched_recordings to include_recordings

* add benchmarks

* remove benchmark

* materialize window and session_id

* add frontend for recordings in person modal

* run prettier

* fix ff query param

* remove session_id + window_id materialization

* cleanup

* fix ts errors

* update snapshots

* fix tests

* rename TrendsPersonQuery -> ClickhouseTrendsActors

* remove flaky snapshot

* clean up should_include_recordings
2022-01-07 14:51:30 -08:00
Neil Kakkar
9f9b5f3ec3
Switch around experiment calculation methods (#7943)
* switch around experiment calculation methods

* cleanup add new comments
2022-01-07 16:02:52 +00:00
Neil Kakkar
982562db6a
Trend multivariate experiments backend (#7924)
* backend for trend experiment results

* cleanup

* address comment, remove flake

* add deps for docker build

* wip

* wip

* wip

* wip

* funnel multivariate experiments

* cleanup

* clean up

* remove numpy from requirements

* make typing happy until Li fixes this properly

* trend multivariate experiments

* clean
2022-01-06 13:44:18 -05:00
Paolo D'Amico
7ecdade38d
Remove recording retention policy for Postgres (#7925) 2022-01-06 11:12:21 -06:00
Neil Kakkar
b805a7e67f
Funnel multivariate experiment results API (#7922)
* funnel multivariate experiments

* cleanup

* remove numpy from requirements
2022-01-06 15:46:11 +00:00
Eric Duong
34d45e3436
[cohort] insight cohorts (#7569)
* initial working'

* fix tests

* correct tests

* typing

* update snapshot

* add funnel test

* remove unnused

* rest of tests

* function name

* typing

* raise if debugging otherwise send to sentry

* no limit option for cohorts

* remove duplicate

* propogate types correctly

* add param

* cleanup

* update snapshots

* add comment

* change var name

* reverse arg

* use func

* fix tests and types

* add simplify

* move simplification

* adjust checks

* explicit type

* don't init
2022-01-06 10:38:29 -05:00
Paolo D'Amico
a714528c3f
Exception when kafka is down (#7905) 2022-01-06 07:21:37 -06:00
Neil Kakkar
50bbafa33b
Backend for trend experiment results (#7878)
* backend for trend experiment results

* address comment, remove flake

* sort out dependencies
2022-01-05 17:15:12 +00:00
Li Yi Yu
5d12386970
Experiments multivariate support FE (#7865)
* add experiment group variant options

* move integration instructions to view page

* redo experiment group multivariate flags frontend

* spacing

* typing

* move variants under parameters, allow variant deletion, and disable editing for control group variant

* rename control_group

* fix start_date keyerror

* update text

* temporary change

* fix variants limit

* fix start_date conditional again
2022-01-05 11:27:28 -05:00
Karl-Aksel Puulmann
9141996e1c
Proposal: Set time bounds for "all of time" filter (#7849)
* Set time bounds for "all of time" filter

We won't display data points from before 2015 anymore, avoiding
confusion like in https://github.com/PostHog/posthog/issues/7626

* Disable dates before 2015, add tooltip
2022-01-05 14:34:33 +02:00
Karl-Aksel Puulmann
2b58fc3f79
Proposal: Fix performance issues caused by actions page (#7855)
* Remove flipsort related logic

* Only load events from the last 6 months in events table

* Disable customization in actions tab

* Rename prop

* Dont poll events in actions page

* Show a different header above events table in actions page

* Update tests with frozen time

* Decouple months of actions tab with other months

* Calculate action count over 3 months

* Update tests
2022-01-05 13:57:20 +02:00
Karl-Aksel Puulmann
c2bddf09a2
Remove "minute" interval (#7847)
* Remove `minute` interval support from frontend

* Remove minute support from backend, default to hour instead

Also adds tests for interval logic

* Remove now-dead minute support from backend

* revert interval_candidate logic

* Move IntervalMixin to separate file
2022-01-05 13:11:58 +02:00
Karl-Aksel Puulmann
e5ee7b4270
Read from and write to person_distinct_id2 if async migration is done (#7846)
* Run queries against person_distinct_id2 when async migration is done

* Only write to clickhouse_person_unique_id topic if async migration is incomplete

* Update query snapshots

* Update plugin-server

* Adjust caching logic
2022-01-05 13:11:33 +02:00
Karl-Aksel Puulmann
2139a6e204
Add measure.sh helper script to repo (#7877) 2022-01-05 12:46:08 +02:00
Neil Kakkar
8d7614bc7c
Multivariate Experiment backend creation flow (#7884)
* enable creating multivariate experiments
2022-01-04 15:55:58 +00:00
Harry Waye
a819069128
chore(pdi): add data migration for pdi to pdi2 (#7792)
* chore(pdi): add data migration for pdi to pdi2

This adds an async migration to copy the latest non-deleted
`(team_id, person_id, distinct_id)` tuples from `pdi` to `pdi2`.

Note that this has already be performed for tead_id = 2 on posthog,
cloud so we ensure we're maintaining parity with however this
migration was performed. I've done this by running:

```
SELECT * FROM <old_query>
FULL JOIN <new_query> new
    ON old.distinct_id = new.distinct_id
WHERE old.person_id <> new.person_id
```

specifically for team_id = 2.

* Rename migration

* Skip 0003_fill_person_distinct_id2 on fresh installs

* Clarify version requirements

* Run async migrations using a while-loop instead of tail recursion

Python has a stack limit of 1000, which we might easily run into for
0003 migration

* Use built-in progress tracking

* Make description fit into database 400 char limit

* Add correctness test for new async migration

* Migrate person_distinct_id2 team-by-team

* Remove dead code

* Update migration notes

* Fix foss tests

Co-authored-by: Karl-Aksel Puulmann <oxymaccy@gmail.com>
2022-01-04 15:34:12 +02:00
Karl-Aksel Puulmann
3d8bcdfae0
Kill a dead filter type (#7850) 2021-12-29 08:45:37 +02:00
Karl-Aksel Puulmann
f3fc669cda
Add benchmark for earliest timestamp sql (#7848) 2021-12-28 15:16:47 +02:00
Karl-Aksel Puulmann
f7d9c21dcf
Respect person_distinct_id2 in split_person (#7815)
* Keep person_distinct_id2 in sync on split_person

Follow-up to https://github.com/PostHog/posthog/pull/7671, covering a
new corner case.

* Deprecate some methods

* Handle versioning in split_person

* Select for update
2021-12-27 16:25:20 +02:00
Paul D'Ambra
30ba578ea3
Query events by date for properties known to be dates (#7608)
* query events by date for properties known to be dates

* can't currently import journeys_for helper outside of ee folder

* actually remove the EE import

* even though no values of the specified property were not parseable account for unparseable values

* move tests into EE folder cos they're clickhouse only

* remove new line to take this file out of the PR diff

* use more forgiving ClickHouse datetime function

* wip

* add more tests and rename filters

* Adds a broken date picker behind a feature flag

* Revert "wip"

This reverts commit 6ec1da8744.

* add working basic UI for date selection in taxonomic property filter

* add a failing test by writing a unix timestamp the way the SDK does

* obey mypy

* add awareness of type and format so we can query our $time property as a DateTime in the events api

* hard code property definition in the eventsTableLogic

* Revert "obey mypy"

This reverts commit f09ae4369a.

* hold taxonomic property filter open - but with possible kludge in cohortsModel

* remove my edits to settings

* put back materialization of columns that test snapshots are expecting

* let the datepicker hold the taxonomic pop up open

* update snapshot

* simpler datepicker visibility in filter row

* simplify property type format for unix timestamps

* remove the datepicker now button

* Actually delete all of the drop down held open tests

* Remove leftover `console.log`s

Co-authored-by: Michael Matloka <dev@twixes.com>
2021-12-22 13:58:59 +00:00
Paul D'Ambra
bdfe09a06b
Add type and format to property definition (#7804)
* add property type and format and set them for

* add a failing test

* with passing tests on the ee property definition model

* Add a migration to set  as a DateTime

* Clarify in failing test that it's only list lookup failing

* add empty property definition fields to assertions

* fix merge error

* clarify tests

* add more supported types
2021-12-22 10:48:15 +00:00
Marius Andra
51b2940ddd
Event properties in filter (#7718)
* create event property model

* add null

* rename cache vars

* update event properties table on ingestion

* match date formats

* match date formats

* better string handling

* property type can be null too

* pass event timestamp

* update property type later

* perform all updates through a buffer object

* move to EventPropertyCounter

* fix migration

* improve flush last seen at job

* flush job periodically + env

* upsert all event properties in 1 query

* log to statsd

* enable property counter only if experimental mode enabled

* use now() instead of event timestamp

* fix seconds

* add user/pass for default postgres

* add tests

* use big integers

* make query work with 50k props

* processing events saves event properties

* fix script

* test date format detection

* default enabled

* only enable event property counter for specific teams

* eslint fixes

* fix logs double-sync noise in tests

* fix bigint test

* don't do tasks that make no sense

* remove dead code

* proof of concept

* remove old <PropertyFilter> component

* change import paths

* event properties sorted by event names

* get event names from actions if used

* scope event property filters by event names

* fix eslint

* simpler test setup

* different contraint name

* refactor team manager

* greatly simplify the system

* fetch cached event properties

* fix team manager and timestamps

* add cached entry

* also don't cache event properties for teams that have it disabled

* remove indexes that are not going to be used

* remove unused imports

* blacked

* remember event properties with a LRU cache

* fix eslint

* clean up the last bits

* remove fields we no longer have

* add some instrumentation to figure out what services we can connect to (helps debug errors locally with kafka)

* Update frontend/src/types.ts

Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com>

* merge duplicate code

* use the right prop for event names

* mute unseen events, add info icon

* use the event-property tracker also for non-EE clients

* simplify duplicates

* add test for event properties

* add test for non-EE event properties

* add flag

* revert the label and unmute the text

* change the flag to UNSEEN_EVENT_PROPERTIES

* sort by query_usage_30_day again

* Update frontend/src/types.ts

Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com>

* use None if no event_names

* fix type

* improve pagination test

Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com>
2021-12-21 16:27:12 +00:00
Karl-Aksel Puulmann
afce8efafb
Add benchmark for funnel query (#7813)
* Add benchmark for funnel query

Testing new sorting order takes the benchmark from 3.5s -> 1.5s \o/

* Update snapshots
2021-12-21 13:09:00 +02:00
Eric Duong
558559c5c7
[temp] increase timeout execution query check for retention (#7794)
* increase timeout execution query check

* snapshot

* pass as arg
2021-12-20 19:07:55 -05:00
Yakko Majuri
3f6b4ecb76
fix migration details changed but name is the same (#7783) 2021-12-17 10:51:25 -08:00
Yakko Majuri
27ac13bb81
0002_events_sample_by (#7778)
* 0002_events_sample_by

* fix order by

* fix test

* update comment

* fix types

* fix test

* fix snapshot tests
2021-12-17 10:41:15 -08:00
Harry Waye
fdb4255303
chore(lifecycle): add comments and CTEs to clickhouse sql (#7773)
* chore(lifecycle): add comments and CTEs to clickhouse sql

It was really big and confusing, but hopefully this clarifies a little
what is going on. As a followup PR I'll be doing some work to make the
query faster :fingerscrossed: but I think worth at least getting this
in, assuming I haven't broken any tests!

* update snapshots

* remove day references

* update snapshots
2021-12-17 17:09:28 +00:00
Harry Waye
83386a5512
fix(retention): add regression test for not_icontains filter (#7748)
* fix(retention): add regression test for not_icontains filter

Previously if using the not_icontains filter, we were trying to double
substitute a query when fetching persons for retention. This adds a
test (and in the next commit a fix) such that we instead apply the
clickhouse substitute only once to each part of the query.

Resolves https://github.com/PostHog/posthog/issues/7747

* avoid double substitution

* Rework solution to not change ActorBaseQuery interface

* Remove unued import

* fix typing
2021-12-17 10:13:38 +00:00
Harry Waye
5fb811a365
perf(lifecycle): add benchmark for lifecycle (#7753)
* perf(lifecycle): add benchmark for lifecycle

* Add some notes on running benchmarks locally
2021-12-17 09:36:49 +00:00
Paolo D'Amico
2654bb3a34
Release multivariate flags (#7650) 2021-12-16 11:10:29 -06:00
Eric Duong
fd49c6a9cc
[fix] Cohort 0 count bug fix (#7742) 2021-12-16 10:38:41 -06:00
Li Yi Yu
9eb989a473
Experiment create cleanup 2 (#7741)
Co-authored-by: Neil Kakkar <neilkakkar@gmail.com>
2021-12-16 15:09:47 +00:00
James Greenhill
2440f945f1
Use a helper to get env var for saml (#7744) 2021-12-15 21:45:51 -06:00
Rick Marron
f641e6b679
Multiple window_id player (#7564)
* it works...

* clean up server side

* move logic from query to helpers/api

* typing fixes

* add tests to helpers

* test for metadata queries

* api tests

* util tests

* improve some types and move logic to utils

* Get PlayerMeta working

* tests for sessionRecordingPlayerLogic

* fix some more tests

* analytics fix

* name flip

* player util tests

* Add comments + remove logs

* Clean up some comments

* make is_active a bit cleaner

* remove some log statements

* add comment to metadata function

* some cleanup

* typescript fix

* timestamp plays follows scrubbing

* fix bug with hitting 60 seconds

* fix end position bug

* fix bugs with skip ahead

* fix some bugs

* fix white screen on buffer end

* fix buffer scrubbing bugs

* fix skip bug

* fix circular import

* rename start_window_id to last_active_window_id

* fix tests

* bug fix for no window_id case

* fix bug when scrubbing to the end of the player

* rename setBuffer + setScrub to startBuffer + startScrub
2021-12-15 15:17:15 -08:00
Eric Duong
30b5658fb3
[fix] Make sure ordering is consistent (#7738)
* make sure ordering is consistent

* ordering
2021-12-15 15:25:56 -05:00
Harry Waye
c595976779
fix(retention): fix breakdown people urls (#7642)
* fix(retention): fix breakdown people urls

This change returns people_url for each breakdown cohort in the
response. We also merge the initial and returning queries together,
as this makes it easier to align the people query also.

Note that I'm talking about person_id as opposed to actor_type etc.
but perhaps that can be a followup.

* clean up clickhouse params

* tidy up a little

* remove import

* remove non-breakdown specific code

* make cohort by initial event date a special breakdown case

* keep date for backwards compat

* Remove unused sql

* make test stable

* wip

* Get most of the tests working

* test(retention): remove graph retention test

We no longer need this, we have all the information we need from the
table response for retention, and can construct this on the frontend.

* revert any changes to posthog/queries/retention.py

* revert any changes to ee/clickhouse/models/person.py

* Revert posthog/queries/retention.py to merge-base

* Ensure actor id is a str

* Add type for actor serialiser for type narrowing

* run black

* sort imports

* Remove retention_actors.py

* fix typings

* format

* reverse str type

* sort imports

* rename

* split out functions

* remove deuplicate logic

* working

* fix type

* don't stringify

* fix test

* ordering doesn't matter

* trigger ci

Co-authored-by: eric <eeoneric@gmail.com>
2021-12-15 18:20:56 +00:00
Yakko Majuri
574e495b76
Async migration 0001: Change events table SAMPLE BY (#7706)
Co-authored-by: James Greenhill <fuzionech@gmail.com>
2021-12-15 08:29:53 -06:00
Karl-Aksel Puulmann
c2cfcb0db6
Remove hooks for person/person_distinct_id deletion (#7671)
* Make person hooks only happen in tests

* Remove a data script

* Update split_person code to handle hookless life

* Delete clickhouse data async in the background
2021-12-15 15:45:10 +02:00
James Greenhill
ab0c75414b
Make settings dynamic for MATERIALIZED_COLUMNS_ENABLED (#7662)
* Make settings dynamic for MATERIALIZED_COLUMNS_ENABLED

* migrate MATERIALIZED_COLUMNS_ENABLED to this and test

* allow tests that use materialized columns to hit django model for settings

* nicer installed apps config

* update snapshot from test

* make test_property more deterministic

Co-authored-by: James Greenhill <fuzionech@gmail.com>
Co-authored-by: yakkomajuri <yakko.majuri@gmail.com>
2021-12-14 17:56:08 -08:00
Michael Matloka
834661d9c0
Make sure private projects stay secret for those without access (#7688) 2021-12-14 16:41:48 -06:00
Eric Duong
ae40b03932
fix cohort 0 argument (#7699) 2021-12-14 11:02:17 -05:00
Yakko Majuri
3f85aa4c47
special migration -> async migration (#7686)
* special migration -> async migration

* rename frontend dir

* format

* rename SPECIAL_MIGRATION
2021-12-14 11:48:51 -03:00
Neil Kakkar
a78dde851b
Experiment Results Detail Page (#7606)
Co-authored-by: Li Yi Yu <li@posthog.com>
2021-12-14 12:37:36 +00:00
Yakko Majuri
b56b141126
Special Migrations Runner (#7054 pt. 4) (#7446)
* add special migration definition and example

* types

* special migrations runner

* fix tests

* fix tests 2

* add clickhouse runner

* add temp fix for tests

* wip

* add special migrations api (#7448)

* wip new structure

* update example sourcing

* Update .gitignore

* yet another wip structure

* code quality

* cypress

* test docker image build

* implement resumable ops

* code quality

* add comments

* add warning

* add conditional requirements for migration

* add comment on is_required

* add dependency map

* wip dependencies and run migration on startup

* code quality

* fix bugs

* fix more bugs

* format

* types

* remove api from this branch

* types

* types

* update clickhouse script

* add is_migration_in_range util

* fix type

* fix runner

* add AUTO_START_SPECIAL_MIGRATIONS env var

* reset migration on start

* cleanup

* wip per op rollback

* prevent accidental status rollback

* add utils and definition test

* update example with rollback per op

* wip test special migration

* add first runner tests

* add runner tests

* add util for code paths

* fix test

* fix types

* fix types again

* cleanup

* cleanup

* add periodic healthcheck task tests

* remove unused imports

* safer row updates

* fix coalescing none checks

* code quality

* add docstrings

* fix

* fix deploys issue

* update scripts

* add delay

* address reviews

* address review comments

* address review comments

* address final comments

* fix import error

* fix tests

* remove unused imports

* fix tests

* fix task test

* remove unused return value

* remove unused special migrations code from migrate_clickhouse

* tweaks to support fresh deployments
2021-12-13 13:00:27 -03:00
Karl-Aksel Puulmann
75a508b4a3
Resolve another insights N+1 issue (#7628)
* Resolve another insights N+1 issue

Using `prefetch_related` to avoid loading the same dashboard/user
multiple times if referred to by different insights. More queries _can_
be better! :)

* Improve the test

* Get test stable, add created_by user
2021-12-10 14:57:05 +01:00
Marius Andra
1696ed5950
Update mypy and typed-ast, fail early if db version not in range (#7599)
* error if unsupported db version

* upgrade mypy

* fix various types for mypy

* you can have it in any color you want, as long as it's black

* fix mypy

* Update `kafka-python`

* Format with Black

* Fix mypy after merge

Co-authored-by: Michael Matloka <dev@twixes.com>
2021-12-10 09:29:04 +01:00
Karl-Aksel Puulmann
0cc07ab581
Groups: Improve list experience (#7600)
* Order by created_at over id in groups list, similar to persons

* Change table column name to be consistent with persons

* Default to `.name` property if one is passed for groups

This improves a usability issue with groups temporarily
2021-12-10 00:28:35 +02:00
Neil Kakkar
ea361bab9d
Experimentations List view (#7584) 2021-12-09 15:25:26 +00:00
Eric Duong
a051f7ee1f
[actors] retention actors (#7495)
* convert to actor form

* change var name

* remove unused imports

* typing issue

* use subquery

* bad import

* groups for general retention query

* actor in period

* update imports

* update test

* remove comment
2021-12-09 10:11:21 -05:00
Karl-Aksel Puulmann
c32f214d63
Track organization groups usage (#7597) 2021-12-09 15:51:24 +02:00
Neil Kakkar
c32b3a88c8
Experimentation backend (#7492) 2021-12-09 10:24:03 +00:00
Karl-Aksel Puulmann
d8a3b9e89f
Groups: Introduction banner and empty state in persons page (#7520)
* Add group analytics to list of paid features

* Add team-level property for if any group types exist

* WIP: Groups introduction page

* Finish initial empty state page

* Hide upsell if not CH or flag not live

* Extract upsell-related logic into a separate logic to avoid loading data unless needed

* Extract upgradeLink

* Extract announcement logic

* Overcomplicate announcements

* Show initial groups announcement.

* Vary banner content according to groups access status

* Clean up access logic

* Misc announcements improvement

* Add a feature flag for groups announcement given docs are not yet ready

* Keep color for visited button links

* Get groupsList logic tests working

teamLogic <-> userLogic test connection needed to be severed alongside
this
2021-12-09 08:37:39 +02:00
Paolo D'Amico
73809d54b1
Fix EE serializer for EventDefinition (last seen at) (#7580) 2021-12-08 09:03:34 -07:00
Karl-Aksel Puulmann
78a787bc3b
Create and populate person_distinct_id2 table, add versioning to person_distinct_id (#7576)
* Migration to add version to person_distinct_id

* Update plugin-server type

* Use queueMessages instead of for loops

* Update distinct id versions in postgres

* Add commented out new query

* Add person_distinct_id2 table setup/migration

This will be used for more efficient person_distinct_id queries

* Avoid sharding person_distinct_id2 on cloud

* Write to new distinct ids topic

* Attempt to use version in tests

* Tests attempt 2

* Fixup version - dont send with all messages

* Flush kafka more frequently

* Actually fix tests

* Add another await

* Add partition to person_distinct_id2 table
2021-12-08 16:47:57 +02:00
Karl-Aksel Puulmann
ba405c823c
Add snapshot tests for clickhouse table schemas (#7572)
* Add a comment to keep topics in sync

* Clean up code relating to table engines

* Add snapshots for table creation queries

* Remove optional import

* Add snapshot tests for CLICKHOUSE_REPLICATION schemas

Note that these are out of sync with cloud in most cases

* Add another warning comment

* Improve naming
2021-12-08 16:07:34 +02:00
Karl-Aksel Puulmann
3a4beda2ad
Speed up person_distinct_id queries for select clients (#7577)
* Create a new way to get distinct id queries thats gated by team_id

* Update most cases to use the new query

* Convert EVENT_JOIN_PERSON_SQL to new query

* Mostly convert GET_DISTINCT_IDS_BY_PERSON_ID_FILTER

* Mostly convert GET_DISTINCT_IDS_BY_PROPERTY_SQL

* Convert GET_PERSON_IDS_BY_FILTER

* Flag benchmarks

* Resolve circular imports

* Update a snapshot test

* Add a test for the new query logic
2021-12-08 15:59:41 +02:00
Eric Duong
cb470c160e
Change timeout to check execution time to 60 seconds (#7562)
* change timeout to 60 seconds

* update snapshots
2021-12-07 18:23:39 +00:00
Tim Glaser
180be54132
Don't capture error messages for trends (#7557) 2021-12-07 16:55:33 +00:00
Karl-Aksel Puulmann
882d26f4f0
Add daily active users benchmarks (#7556) 2021-12-07 18:17:03 +02:00
Harry Waye
b94d02bc10
test(retention): add test for retention breakdown with materialized property (#7505)
* test(retention): add test for retention breakdown with materialized property

* remove unused imports

* Join tables based on breakdowns properties
2021-12-07 15:05:03 +00:00
Eric Duong
110aa9460b
[actor] Funnel correlation actor (#7456)
* match filter var name

* temp

* working tests

* wrong param

* types

* funnel correlation groups working

* typing

* funnel_people -> funnel_actors

* change naming of people -> actors

* update snapshots

* remove dirty change

* typing

* add check and types

* compare with master

* trigger tests
2021-12-06 09:43:58 -05:00
James Greenhill
2fab8bfafa
Fix issue blocking clickhouse migrations on new installs (#7516)
Co-authored-by: James Greenhill <fuzionech@gmail.com>
2021-12-03 15:42:19 -08:00
James Greenhill
b7df925186
Revert "Add logging to all postgresql queries with query context (#7486)" (#7512)
This reverts commit 3287c48f53.
2021-12-03 12:07:19 -08:00
Eric Duong
4e0e69ac91
[actors] Stickiness actor pattern (#7440)
* separate class

* filter typing

* remove repeat

* refactor test

* add limits

* remove ee

* working tests

* working group tests for stickiness

* remove inits

* suggested changes

* typing

* adjust typing

* add correct params

* remove repeat
2021-12-02 11:43:20 -05:00
Karl-Aksel Puulmann
3287c48f53
Add logging to all postgresql queries with query context (#7486)
* Add logging to all postgresql queries with query context

Uses the exact same pattern as we do currently for clickhouse, just
hooking in there differently

* Support psycopg2.sql.SQL

* Better docs

* update a test
2021-12-02 16:08:26 +02:00
Harry Waye
79816a9715
feat(retention): add support for multiple breakdown props (#7431)
* test(retention): add http api tests for retention breakdowns

This just adds tests for person and event property breakdowns

* Add helper function for substituting clickhouse sql params

* feat(retention): add support for multiple breakdown props

This just reuses the work done for funnel multiple breakdown values. I
haven't tested this with anything other than person or event properties.
Rather than try to get it working for all the other property types.

The change adds a new `breakdowns` parameter to the retention endpoint,
that is the same as for funnels, e.g. it looks like:

```
{
    ...
    "breakdowns": [{"type": "person", "property": "os"}, ...]
    ...
}
```

The return structure is the same as the non-breakdown version, except we
also include a `breakdown_values` property that is e.g. `["Chrome",
"95"]`, and the `label` attribute for this case would be "Chrome::95".

* fix typing

* update query snapshots

* remove unused imports

* use `self.assertEqual` instead of `assert`

* Remove explicit should_join_persons

* Revert limit by changes, use breakdown_type

* update snapshots

* fix typing

* use json_encode_request_params in retention test requests

* update json_encode_request_params to encode_get_request_params to better reflect purpose

* perf(retention): add benchmark query for retention with breakdown

* no materialize
2021-12-02 13:35:33 +00:00
Karl-Aksel Puulmann
55d5c6faa0
Groups: Show "related groups" under group and person pages. (#7461)
* Use GroupTypeIndex type in BE

* Consistent ordering for group types

* Better BE type for group type index

* Handle non-url safe keys in groups

Previously this would crash due to never decoding the url and not
handling it in the backend

* Allow fetching related groups from the API

* Solve minor type errors

* Add a tooltip

* data-attr for tracking links

* Add related groups onto person page

* Fix an import

* Kill useEffect
2021-12-02 15:21:15 +02:00
Tim Glaser
7fe96b813d
Fix error too deep recursion (#7445)
* Fix error too deep recursion

* Add space

* space no 'AND'

* update snapshots

* fix test

* fix test

* Remove team_id from prop_clause
2021-12-02 12:12:14 +01:00
Harry Waye
eed62dad9f
perf(retention): add benchmark cases for retention (#7483)
This was pretty much as copy paste job from the stickiness cases. I'm
going to be merging in some changes to retention so I want to get this
in first such that we can see if it affects the perf of these queries at
all. I don't think it touches them, as seen by the snapshot queries
generated by the retention tests not changing in
https://github.com/PostHog/posthog/pull/7431 but better safe than sorry.

Addresses [this comment](https://github.com/PostHog/posthog/pull/7431#pullrequestreview-820773405)
2021-12-02 10:38:49 +00:00
Eric Duong
37031228d2
[group actors] Trends and funnels actors UI (#7298)
* add actors pattern to trends ui

* funnels

* fix typing

* fix types

* don't show modal actions on group modal

* change name

* fix backend target entity logic

* fix types

* run again

* make defaults correct

* restore func

* typing

* missing imports

* fix merge conflicts

* types

* typing

* fix utils

* minor adjustments

* group type index

* undo accidental changes

* add comment
2021-12-02 10:02:23 +02:00
Paolo D'Amico
c90c4a4d05
Update drf-exceptions-hog (#7417) 2021-12-01 17:19:51 -05:00
Karl-Aksel Puulmann
4e23358e28
Fix typeerror with path_actors query (#7464)
Fixes
> ee/clickhouse/queries/paths/paths_actors.py:30: error: Incompatible types in assignment (expression has type "PathFilter", base class "ActorBaseQuery" defined the type as "Filter")

Caused by parallel merges & weird typing-related issues.
2021-12-01 14:10:29 +02:00
Eric Duong
f6b300b1be
[actors] convert paths to actor pattern (#7437)
* convert paths to actor pattern

* used serialized result
2021-12-01 08:46:14 +02:00
Eric Duong
056c3b1973
match filter var name (#7455) 2021-12-01 08:45:04 +02:00
Rick Marron
6fc64efafa
Only include events in session recording query when needed (#7248)
* query for events with matching session_id if possible

* move test to clickhouse

* move event list to list instead of set for flaky test snapshot

* join events only when needed

* trigger benchmarking

* typo
2021-11-30 09:33:41 -08:00
Harry Waye
f914e77f4f
refactor(stickiness): refactor one stickiness test to use api (#7398)
* refactor(stickiness): refactor one stickiness test to use api

This change demonstrates how to migrate a `Query` object level test to
an api based test. It purely focuses on the method of action invocation
and not on any of the e.g. setup or assertions. The StickinessQuery
object is only used by the REST API (and benchmarking), where as the
REST stickiness API is used by external users including our own frontend
developers, so makes sense to test at this level.

* Migrate stickiness query tests to api

This doesn't touch the stickiness people API however

* Migrate clickhouse specific stickiness tests

* Migrate stickiness people query tests to http api level

NOTE! This isn't just a straight migration, but also makes one important
change to application code that would otherwise result in a test
failure. Specifically, when trying to find an action based on the
`entity_id` query param, we need to consider that the entity_id is a
string. This is fine for when trying to find events, as we are comparing
event ids which are strings, but for actions the id is an int, so we
need to ensure we cast the action id to a string before comparison.

* Move stickiness query tests to api tests location

* make stickiness tests stable across postgres/clickhouse

* Add comment regarding casting action ids to strings
2021-11-30 13:40:15 +00:00
Karl-Aksel Puulmann
fd6980d96a
Groups: Refactor endpoints, single group page (#7399)
* Update wording

* Update view to use postgres tables

We keep these in sync now

* Add retrieve endpoint

* Link to a (blank) groups page

* Show events table and properties under group

* Update pagination for groups

* update testing utils

* Update tests

* Patch tests relying on returned models

* Remove duplicated line
2021-11-30 13:47:45 +02:00
Karl-Aksel Puulmann
7de761dff0
Update BE tracking to use groups (#7355)
* Update some posthoganalytics.capture calls

* Update report_user_logged_in tracking

* Update report_team_member_invited

* Update report_bulk_invited

* Update report_org_usage

* Update AnalyticsDestroyModelMixin

* Update action creation/updating tracking

* Update annotations tracking

* Update cohort tracking

* Update dashboards tracking

* Update feature flags tracking

* Update imports, sessions tracking

* More typeignores

* Default properties blank

* update metadata default

* Stringify

* Fix some tests

* Kill debug code

* Update FF tests

* Update test_organization

* Update test_organization_invites

* Update test_user

* Fix org usage report

* update test_send_license_usage

* Update organization tests

* Respect dry-run on errors as well, log

* Update organization properties on report

* Assert organization props

* Remove dead imports

* Fix test
2021-11-30 10:58:37 +02:00
Paolo D'Amico
87e91e1352
Remove legacy sessions (#7401)
Co-authored-by: Rick Marron <rcmarron@gmail.com>
2021-11-29 21:11:10 -08:00
Rick Marron
fd150761ec
Materialize has_full_snapshot in session_recording_events (#7281)
* materialize has_full_snapshot

* add basic backfill command

* some clean up

* bug fix

* use comment function

* remove unneeded column check

* add to test for get_materialized_columns

* update test

* ClickhouseDestroyTablesMixin resets session_recording_events

* remove backfill command
2021-11-29 16:18:08 -08:00
Yakko Majuri
aedb28f12a
support uuid in event payloads (#7226)
* support uuid in payloads

* typing shenanigans

* add statsd metric
2021-11-29 13:12:51 +00:00
Karl-Aksel Puulmann
065947877e
Groups: Make test_account_filters work with groups (sessions, lifecycle support) (#7387)
* Extract common subquery into a variable

* BE: handle group properties in more cases

* Add tests for lifecycle and sessions query changes

* Better docs

* Stable date range
2021-11-29 14:41:10 +02:00
Paul D'Ambra
3ceb234e37
938 wire in the FE for multi property breakdown funnels (#7353)
* wip

* normalise to breakdown and breakdowns on the way out of the API

* read from breakdowns or breakdown property of filters

* wip

* wip

* delete a console.log

* remove console.log and speculative multi breakdown changes

* remove empty test

* remove console log

* more tidying

* more tidying

* more tidying

* simplify funnel logic slightly

* a test for the data transformations with no breakdown

* can test data transformation with a single property breakdown

* keep expanding the test to see why multi prop doesn't display

* don't throw key error if there is no breakdown property to pop from the multi property API response

* funnel step table can detect breakdown without relying on filter

* try to highlight the differences in the paths through TaxonomicBreakdownFilter

* better behaviour when adding and removing multi property breakdowns

* displays multi property breakdown in old style steps funnel views

* it is safe to always show breakdown in new vertical layout

* resolve multi property breakdown typehinting

* updates comment

* updates comment

* don't print breakdown value twice

* tooltip for long values and prettier pill

* convert tests to journeys_for

* fix multi breakdown helper

* better behaviour when navigating between trends and funnels

* Refactor the multi property breakdown helper to calm the mypy type checker down

* safer access to dict in multi property helper

* makes clean filters feature flags aware and keeps breakdown values when switching between trends and funnels

* test fix

* remove overly verbose data tests

* add some more specific tests to multi prop breakdown

* obey mypy

* remove the breakdown type from the backend which was causing serialization issues
2021-11-26 15:42:33 +00:00
Karl-Aksel Puulmann
82bb4797a5
Groups: Hide some property definitions from the API (#7328)
* Hide some property definitions from the API

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

* Update the test
2021-11-25 14:17:57 +02:00
Karl-Aksel Puulmann
55bf75a40a
Make KAFKA_EVENTS_PLUGIN_INGESTION_TOPIC configurable (#7349)
This is for razorpay - they're planning to hook into this with spark
2021-11-25 11:47:20 +01:00
Neil Kakkar
12a2804ee9
Make cohorts filtering with funnels work again (#7324)
* Make cohorts filtering with funnels work again

* rm unused import
2021-11-24 13:34:25 +00:00
Eric Duong
976e49053a
[groups persons] Funnels groups persons query backend 2 (#7194)
* working for unique_groups math

* fix types

* add null check

* update snapshots

* update payload

* update snapshots

* use constructor

* adjust queries

* introduce base class

* consolidate querying

* shared serializer and typed

* sort imports

* snapshots

* typing

* change name

* Add group model

```sql
BEGIN;
--
-- Create model Group
--
CREATE TABLE "posthog_group" ("id" serial NOT NULL PRIMARY KEY, "group_key" varchar(400) NOT NULL, "group_type_index" integer NOT NULL, "group_properties" jsonb NOT NULL, "created_at" timestamp with time zone NOT NULL, "properties_last_updated_at" jsonb NOT NULL, "properties_last_operation" jsonb NOT NULL, "version" bigint NOT NULL, "team_id" integer NOT NULL);
--
-- Create constraint unique team_id/group_key/group_type_index combo on model group
--
ALTER TABLE "posthog_group" ADD CONSTRAINT "unique team_id/group_key/group_type_index combo" UNIQUE ("team_id", "group_key", "group_type_index");
ALTER TABLE "posthog_group" ADD CONSTRAINT "posthog_group_team_id_b3aed896_fk_posthog_team_id" FOREIGN KEY ("team_id") REFERENCES "posthog_team" ("id") DEFERRABLE INITIALLY DEFERRED;
CREATE INDEX "posthog_group_team_id_b3aed896" ON "posthog_group" ("team_id");
COMMIT;
```

* Remove a dead import

* Improve typing for groups

* Make groups updating more generic, avoid mutation

This simplifies using the same logic for groups

Note there's a behavioral change: We don't produce a new kafka message
if nothing has been updated anymore.

* Rename a function

* WIP: Handle group property updates

... by storing them in postgres

Uses identical pattern to person property updates, except we handle
first-seen case within updates as well.

* Get rid of boolean option

* WIP continued

* fetchGroup() and upsertGroup()

* Test more edge cases

* Add tests for upsertGroup() in properties-updater

* Rename to PropertyUpdateOperation

* Followup

* Solve typing issues

* changed implementation to use pg

* unusd

* update type

* update snapshots

* rename and remove inlining

* restore bad merge code

* adjust types

* add flag

* remove var

* misnamed

* change to uuid

* make sure to use string when passing result

* remove from columnoptimizer logic and have group join logic implemented by event query classes per insight

* add flag to funnel event query

* remove unnecessary logic

* typing

* working actors func

* fix typos

* remove unused func

* use serialized result

* wrong var

* use actors

* remove dead imports

* remove verbosity

* update snapshots

* typos

* remove signals

* remove plugin excess

* update typing

* clean up

* use actor func for all funnel persons

* types

* make sure limits are set

* remove functions

* fix limits

* funnel trends

* types

* indexing

* moved basic funnel tests

* unordered test

* remove duplicate test

* check ids

* more test adjustments

* sort

* change class names

* sort

* reformat

* change string to int

* remove duplicate

* update comment

* use actor result to paginate not serialized

* adjust tests after merging

* simplify typing

* don't import removed func

Co-authored-by: Karl-Aksel Puulmann <oxymaccy@gmail.com>
2021-11-23 09:49:52 -05:00
Paul D'Ambra
a710279955
Person URLs in Funnels (#7287)
* don't add leading slash to absolute url with no protocol

* don't add a base uri in only one funnel instantiation - will probably break tests

* remove console logs

* every API verb normalises URLs
2021-11-23 12:25:20 +00:00
Karl-Aksel Puulmann
c7c42b1a64
Groups: feature flag support for aggregating by groups (#7202)
* Tiny rename

* Minor refactor

* Test on FeatureFlagMatcher

* Add a field to feature_flag indicating if aggregating by groups

* Use f-strings

* Handle property filter building for group property

* Rename is_person_query

* Add message

* Tests for property_to_Q changes

* Add tests for groups w/ rollout

* Add comment for my_flags

* Hook up decide with groups

* New test helper for snapshotting pg queries

* Add snapshot tests for feature flags

* More is_simple_flag tests

* Add decide endpoint tests

* move conftest for ee tests to work

* Fix typo

* conftest troubles
2021-11-23 13:18:28 +02:00
Rick Marron
2c417ed1e1
Use session_id in recordings query when possible (#7218)
* query for events with matching session_id if possible

* move test to clickhouse

* move event list to list instead of set for flaky test snapshot

* comment to clarify test
2021-11-22 13:23:08 -08:00
Paul D'Ambra
ab737dcf76
Moves a test to exercise the system under test from a more stable interface (#7263)
* original behaviour was to set breakdown_values regardless of if it was truthy

* add a test for the bug

* ensmallen the test case

* lift tested interface up a level
2021-11-22 20:49:29 +00:00
Karl-Aksel Puulmann
98a58648e2
Add benchmarks for session recording page (#7251) 2021-11-22 20:10:09 +00:00
Neil Kakkar
b76236e25b
Exclude action events from correlation results (#7258)
* Exclude action events from correlation results

* update snapshots

* make test specific
2021-11-22 16:20:30 +00:00
Paul D'Ambra
7881d1ca47
original behaviour was to set breakdown_values regardless of if it wa… (#7260)
* original behaviour was to set breakdown_values regardless of if it was truthy

* add a test for the bug

* ensmallen the test case
2021-11-22 15:37:36 +00:00
Paul D'Ambra
c4bc7d7193
Multi property breakdown for person and event queries on Funnels (#7074)
* implement multi property breakdown as an array from the spike

* correct type hint on method

* really resolve the conflict

* don't break groups

* refactor test assertions for breakdown cases

* adds a test to prove that funnels can receive a string and not an array

* protect saved dashboards from multi property changeover

* WIP

* multi breakdown working with funnel step breakdown

* prove funnel step person breakdown works with multi property breakdown

* don't need to protect cached dashboards from multi property breakdowns when they can't be set from the UI

* capitalise keywords in SQL

* convert a single test to journey helper

* wip

* account for funnel step breakdown sometimes being an array sent as a string

* safer handling of funnel step breakdown

* convert a test

* revert commits that made things worse

* simpler handling of funnel step breakdown

* no need to change funnel step breakdown type hint

* update imports

* guard against integer properties

* compare funnel step breakdown differently now there are arrays involved

* look for strict intersection for funnel step breakdown

* update test snapshots

* need to set breakdown_values earlier in processing

* remove tests that cover speculative functionality

* update snapshot

* move setup of breakdown values back out of update_filters

* update snapshots

* remove a sql parameter that was never assigned to

* Update ee/clickhouse/models/test/test_property.py

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

* Update ee/clickhouse/queries/funnels/base.py

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

* address review comment to simplify reading json expressions for breakdown

* clarify why some uses of get_property_string_expr escape params before passing

* add keyword arguments for calls to getting property string expressions in funnels

* switch to keyword arguments in test helper method

* fix parameterised test

* add multi property materialized column tests

* introduce the shim to allow new API for breakdown properties

* can't remove the naive funnel step breakdown list detection

* move funnel step breakdown list handling

* better handling of numeric funnel step breakdown values

* update snapshots

Co-authored-by: Harry Waye <harry@posthog.com>
2021-11-22 11:20:01 +00:00
Paul D'Ambra
50b12d9bb7
Set debug, test, and primary_db env variables based on context (#7250)
* set debug, test, and primary_db env variables based on context

* remove unnecessary print

* also use pytest.ini for some tests run straight from pytest at the CLI
2021-11-20 17:18:39 +00:00
Harry Waye
60961ae78b
refactor(retention): Adds people_urls to retention trends response (#7184)
* Addtest for people_urls in retention trend response

* Add people_urls to retention trend response

* Run black formater

* sort imports

* Add default value for base_uri

* Let type be missing in EventPattern in tests

TypedDict is so rubbish in not allowing missing attributes 🤷

* fix typing

* refactor creation helper functions

* revert docker compose change
2021-11-19 10:25:58 +00:00
Rick Marron
9b9b12088a
Add 'active segments' to recording metadata endpoint (#7179)
* remove redundant query

* add include_active_segments query parameter to metadata endpoint

* bug fix

* type fixes

* respond to feedback

* add back in query snapshot
2021-11-18 11:32:10 -08:00
Eric Duong
7979f52e8a
[groups persons] API for returning groups based on trend results (#7144)
* working for unique_groups math

* fix types

* add null check

* update snapshots

* update payload

* update snapshots

* use constructor

* adjust queries

* introduce base class

* consolidate querying

* shared serializer and typed

* sort imports

* snapshots

* typing

* change name

* Add group model

```sql
BEGIN;
--
-- Create model Group
--
CREATE TABLE "posthog_group" ("id" serial NOT NULL PRIMARY KEY, "group_key" varchar(400) NOT NULL, "group_type_index" integer NOT NULL, "group_properties" jsonb NOT NULL, "created_at" timestamp with time zone NOT NULL, "properties_last_updated_at" jsonb NOT NULL, "properties_last_operation" jsonb NOT NULL, "version" bigint NOT NULL, "team_id" integer NOT NULL);
--
-- Create constraint unique team_id/group_key/group_type_index combo on model group
--
ALTER TABLE "posthog_group" ADD CONSTRAINT "unique team_id/group_key/group_type_index combo" UNIQUE ("team_id", "group_key", "group_type_index");
ALTER TABLE "posthog_group" ADD CONSTRAINT "posthog_group_team_id_b3aed896_fk_posthog_team_id" FOREIGN KEY ("team_id") REFERENCES "posthog_team" ("id") DEFERRABLE INITIALLY DEFERRED;
CREATE INDEX "posthog_group_team_id_b3aed896" ON "posthog_group" ("team_id");
COMMIT;
```

* Remove a dead import

* Improve typing for groups

* Make groups updating more generic, avoid mutation

This simplifies using the same logic for groups

Note there's a behavioral change: We don't produce a new kafka message
if nothing has been updated anymore.

* Rename a function

* WIP: Handle group property updates

... by storing them in postgres

Uses identical pattern to person property updates, except we handle
first-seen case within updates as well.

* Get rid of boolean option

* WIP continued

* fetchGroup() and upsertGroup()

* Test more edge cases

* Add tests for upsertGroup() in properties-updater

* Rename to PropertyUpdateOperation

* Followup

* Solve typing issues

* changed implementation to use pg

* unusd

* update type

* update snapshots

* rename and remove inlining

* restore bad merge code

* adjust types

* add flag

* remove var

* misnamed

* change to uuid

* make sure to use string when passing result

* remove from columnoptimizer logic and have group join logic implemented by event query classes per insight

* remove unnecessary logic

* typing

* remove dead imports

* remove verbosity

* update snapshots

* typos

* remove signals

* remove plugin excess

Co-authored-by: Karl-Aksel Puulmann <oxymaccy@gmail.com>
2021-11-18 11:58:48 -05:00
Harry Waye
5fdeef664f
dev(clickhouse): use prebuild arm64 clickhouse image (#7187)
I built this image a while ago, it's built with `yarn
arm64:build:clickhouse`, then I did a multipart build to copy only one
binary over and symlinking the various incantations (eg. server, client
etc) to keep the size down.
2021-11-18 08:43:43 +00:00
James Greenhill
df3c159522
Revert "Resurrect "Persons table schema migration" (#7199)" (#7200)
This reverts commit 5c1baa039b.
2021-11-17 23:28:39 -08:00
James Greenhill
5c1baa039b
Resurrect "Persons table schema migration" (#7199)
* Revert "Revert "Persons table schema migration (#6667)" (#7198)"

This reverts commit 311452bca5.

* CREATE TABLE AS

* ON CLUSTER

* prefix database
2021-11-17 23:09:11 -08:00
James Greenhill
311452bca5
Revert "Persons table schema migration (#6667)" (#7198)
This reverts commit 54f23498dc.
2021-11-17 22:29:38 -08:00
Yakko Majuri
54f23498dc
Persons table schema migration (#6667)
* WIP persons table schema migration

* add version to create_person

* test increased timeout

* Update ee/clickhouse/migrations/0019_person_table_version_column.py

* remove flaky kafka test

* format

* test a new approach - make this a non-large migration?

* Update ee/clickhouse/migrations/0021_person_table_version_column.py

* update
2021-11-17 21:19:50 -08:00
Tim Glaser
1d7477f512
Make project based permissioning an enterprise feature (#7163) 2021-11-17 08:08:31 -06:00
Karl-Aksel Puulmann
88db4845f4
Speed up stickiness queries & allow aggregating/filtering by groups (#7117)
* Refactor stickiness to have its own event_query

This will speed up queries significantly and allow for filtering by
group properties

* Use same event_query for stickiness people

* Minor cleanup

* Add tests (and missing file) to group filtering in stickiness

* Allow aggregating by groups in stickiness

* Show group property filters in FE for stickiness
2021-11-17 12:49:49 +02:00
Paul D'Ambra
626efb9490
Convert funnel tests to journey helper (#7111)
* convert the smallest of the funnel test files

* convert unorder funnel person test to journey for helper

* convert another file

* convert another file

* convert another file

* convert another file

* convert another file

* undelete snapshot files

* undelete snapshot files

* Revert "convert another file"

This reverts commit ef08511509.
2021-11-17 08:18:16 +00:00
Eric Duong
b7667f528f
fix issue when breaking down on group property and trying to return persons (#7145) 2021-11-16 09:39:48 +02:00
Rick Marron
c55e834bc1
include elements chain in recordings query when needed (#7147) 2021-11-15 18:35:45 -08:00
Rick Marron
60545e9c93
Recording query improvements (#7006)
* seperate clickhouse and postgres queries

* move to single query

* remove ununsed imports

* fix cohort + subquery issues

* some cleanup

* fix mypy issue

* fixes to query + tests

* add test for person and cohort properties

* remove cruft

* fix api tests

* Remove cohort + person prop filter from postgres

* move cohort and person property tests to clickhouse

* Filter down events

* typing fix

* fix test

* remove unneeded snapshot

* tests working with snapshots

* switch limit to property

* use materialized columns

* move to new distinct_id query

* add snapshots

* fix materialized column bug

* support cohort and person prop filters

* add person and cohort filtering

* remove cohort filtering from clickhouse

* small tweaks

* Lint fix
2021-11-15 16:15:37 -08:00
Harry Waye
a9e615cf45
feat(funnels): update frontend to use new people_urls in response (#7099)
* remove cohort comment

* feat(funnels): update frontend to use new people_urls in response

This change updates the `FunnelBarGraph` and `FunnelStepTable`
components to use the new `converted_people_url` and
`dropped_poeple_url` in the funnels response.

I need to check that this covers all the cases for funnels. I've only
added people urls for funnels of type step for ordered/unordered/strict
and haven't yet touched the time bins and conversion time funnel
endpoint variants.

* add /some/people/url/ to tests

* chore: add action back, update tests to reference it

* fix typing
2021-11-15 18:32:23 +00:00
Eric Duong
c7158fc895
[testing] Organize api tests (#7110)
* move tests

* update compare test

* use latest format

* typing
2021-11-15 13:12:18 -05:00
Karl-Aksel Puulmann
bf28d14aed
Add some benchmarks for stickiness (#7116)
* Add benchmarks for stickiness

* Don't require get_earliest_timestamp always

* Improve benchmark
2021-11-15 13:38:11 +02:00
Li Yi Yu
e0fe499a05
Groups pages table (#7039)
* wip

* get list of groups

* move backend endpoints

* frontend wip

* fix routes for groups

* add groups file

* try to fix tab nav

* fix groups query

* reformat results, add limits and offsets and next url

* move groups pages logic into own file

* fix and clean up tabs

* account for pagination and response reformatting

* lint fixes

* optional prev input

* typescript errors

* typescript fixes

* address feedback comments

* groups list logic test

* render properties expandable row

* fix test and lints

* prettier

* simplify table column title

* Fix a typing issue

* Use enum > boolean parameter

This makes what's going on more explicit

* Turn off pagination at the bottom of the table

* Rename table column

* Make pagination in groups work

Quite bugs fixed:
1. `previous` page was always shown, even if going into negative offsets
2. query_result could never be larger than `limit` with the code

* Cleanup code

* Make sidenav active under persons

* Use the correct query

* Add tests for pagination

* Update wording again

Co-authored-by: Karl-Aksel Puulmann <oxymaccy@gmail.com>
2021-11-15 11:08:13 +02:00
Paul D'Ambra
3a323f361d
batch insert events in the test journey helper (#7108) 2021-11-12 19:33:55 +00:00
Eric Duong
48a6302f6f
[trends] Cumulative fix (#7041)
* cumulative dau for non breakdown

* breakdown case

* clean up test

* add trends request util

* use simpler test util

* types

* insight tests

* add snapshots

* black
2021-11-12 14:27:28 -05:00
Harry Waye
31b4919177
Make get people test ids sorted, remove flakiness (#7107)
I introduced some flakiness in introducing this, it seems indeterministic so need to sort before compare
2021-11-12 18:48:35 +00:00
Paul D'Ambra
19fd07dc87
Convert breakdown_cases to new test helper (#7098)
* adds a first draft of a test helper for clearer event setup in tests

* one spelling of journeys

* obey the type checker

* convert all of breakdown_cases to the new test helper

* Removes unused helper method
2021-11-12 18:33:20 +00:00
Eric Duong
f2108564e2
[trends] Fix compare persons onclick (#7075)
* fix frontend

* temp test
2021-11-12 13:12:23 -05:00
Harry Waye
2550fb26c6
feat(funnel-people): return converted/dropped people url in funnel (#7057)
* test(funnel-people): add tests for converted/dropped people urls

As per https://github.com/PostHog/posthog/issues/6935 we are adding urls
to responses to attempt to improve consistency between insight responses
and the people we display in the UI.

This simply adds tests for these urls, just for funnel step response
shape. The other two types of response will be handled separately.

* feat(funnel-people): return converted/dropped people url in funnel

Here I have simply added converted / dropped urls in the base funnel.
This touches both clickhouse and postgres functionality, so I will
probably add in tests for postgres also, or just disable to postgres.

It doesn't pass yet as there is an issue in that the order appears to be
ignored by the people endpoint.

* fix(funnels): actually use strict/unordered persons querying

Previously we were always using the standard `ClickhouseFunnelPersons`
class for retrieving people from the `/api/persons/funnel/` endpoint.
This change selects from the unordered and strict variants based on the
`funnel_order_type` setting.

Refers to https://github.com/PostHog/posthog/issues/7058 although there
is a frontend component to add that will truely resolve the issue.

* feat(funnel-people): add people urls for funnels with breakdown

In this I have also removed any changes from the non-clickhouse code.
Note that there are two places I've added the url generation code, one
in the `ClickhouseFunnelBase` and another in the `ClickhouseFunnel`

I think the former covers the unordered and strict cases, and the later
for the breakdown case. I think there are further test that I'll need to
add to validate e.g. if breakdown + strict work as expected.

* Fix people urls for unordered funnels + breakdown

* test: add test for strict breakdown with people urls

* make funnel response assertions not check people url equality

* fix typing

* fix tests

* remove new line in postgres funnel.py

* clear cache on insight test start

* no really, clear the cache

* remove flakiness from strict funnel test

* correct the unordered test

* use absolute uris

* use step.index not step.order

* remove out of date comment

* use step.index, not step.order

* use step.index, remove unordered funnels comment

* use journeys_for instead of create_events
2021-11-12 14:50:39 +00:00
Karl-Aksel Puulmann
6344db46a5
Validate group_type_index in properties/entities (#7087)
* Validate group_type_index in properties/entities

This avoids injection-like problems

* Update import path

* No circular import
2021-11-12 14:31:55 +02:00
Paul D'Ambra
1458f07163
Adds a first draft of a test helper for clearer event setup in tests (#7095)
* adds a first draft of a test helper for clearer event setup in tests

* one spelling of journeys

* obey the type checker
2021-11-12 12:26:07 +00:00
Neil Kakkar
13a93098cc
Enable different Property lists based on group type for Property Correlations (#7093)
* Enable different property lists based on group type

* fix test again
2021-11-12 11:45:31 +00:00
Neil Kakkar
7a5bb93e2a
Enable Correlations for Groups (#7056)
* enable correlations for groups

* address comments, refactor bits

* address comments
2021-11-12 11:32:55 +00:00
Eric Duong
d6d924af1d
[funnel] remove funnel persons on data return (#7044)
* remove funnel persons on data return

* remove person checks

* update tests

* remove comment

* add comment

* snapshots
2021-11-11 13:19:20 -05:00
Paul D'Ambra
f319948b2e
Add test helper method (#7053)
* add test_helper_methods

* move all the tests where the properties are the same for all events to the journey helper

* compare funnel results without caring about person order

* spell words correcterly

* Revert "spell words correcterly"

This reverts commit befb83b183.

* Revert "compare funnel results without caring about person order"

This reverts commit 268927b8ba.

* correct types for test props
2021-11-11 13:34:13 +00:00
Neil Kakkar
200caa6b6a
Correlation Persons for properties (#7052)
* Introduce funnel correlation person properties endpoint

* add snapshots

* address comments
2021-11-11 11:31:14 +00:00
Eric Duong
e5503cfd26
remove changing timestamp (#7046) 2021-11-11 11:30:50 +00:00