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

127 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
Harry Waye
7989fd24b8
Revert "Revert "feat(correlation): use people_url to load people modal (#6992)" (#7029)" (#7032)
This reverts commit de15fcda3f.
2021-11-10 15:50:32 +00:00
Harry Waye
de15fcda3f
Revert "feat(correlation): use people_url to load people modal (#6992)" (#7029)
This reverts commit 7bca1b78c1.
2021-11-10 14:09:45 +00:00
Harry Waye
7bca1b78c1
feat(correlation): use people_url to load people modal (#6992)
* feat(correlation): use people_url to load people modal

This change adds a new method to the `personsModelLogic` to allow for
specifying a url to be used to retrieve people from. I've avoided
overloading the existing `loadPeople` and rather added a new one,
`lostPeopleFromUrl`.

Currenlty this is only being used by correlations, but the intention is
to extend it's usage to anywhere else that is performing drilldowns to
people from, for instance, the trends aggregation.

* add paycard back

* make labels look right

* remove unused code

* fix typing in test

* fix typing in personsModelLogic

* refactor to make eventUsageLogic work

* fix typing

* fix typing again

* remove some funnel stories

* get storybook working with paycard

* cleaned up the interface a little

* chore(correlation): use `api.get` for fetching people

This updates to use api.get, and also converts the returned uri from the
correlation endpoint to an absolut uri, instead of just an absolute
path.

The `api.get` method expects either an abolute uri, or a relative path.
I'd rather not use an relative path as it's not obvious what it should
be relative to.

* fix tests

* make storybook uris absolute
2021-11-10 12:54:48 +00:00
Neil Kakkar
62af72bf22
Paths filtering by Groups backend (#7008)
* Paths filtering by groups backend

* update correlation tests, now that CTEs are included in sqls

* use decorator for materialising to ensure clean up happens

* cleanup offending tests
2021-11-10 09:47:02 +00:00
Harry Waye
d8e1799ed1
feat(correlations): add people by property to correlation response (#6951)
* feat(correlation): add people drill down urls for event correlation

This change simply adds urls in the response of the correlation endpoint
for each correlation returned. Note that this only adds support when
using correlation_type=events, as the
correlation_type=events_with_properties requires further changes that
I'd like the separate out to keep this PR small.

* feat(correlations): add people by property to correlation response

This commit covers the PROPERTIES case for making sure we return a url
that can be used to retrieve the people associated with a correlation,
either success or failure. This case is a completely different url than
for the events people endpoint as we are reusing the funnel people
endpoint, and filtering by "funnel_step_breakdown".

I'm uncertain if this is actually the correct url at this point in time,
as I have just attempted to copy what I have seen in the request from
the live running app.

* fix test

* Remove another param

* fix mypy typing

* Fix tests

* Add url response support for event_with_properties

* remove type assertion

* remove variable hack

* Remove funnel_steps

* use with_data and to_params

* Remove comment regarding complexity, it seems to pass the tests so...

* Add autocapture support for people url

* refactor people url construction a little

* remove properties attr for event people request

* fix if

* no really, fix if not None

* Remove _assert_never, mypy needs updating

* Fix no return mypy error

* Remove json.dumps
2021-11-09 12:10:40 +00:00
Neil Kakkar
bd5c74ef03
Funnel groups breakdown (#6944)
* Enable breakdowns

* update team

* clean up

* run all breakdown tests, address review comments
2021-11-09 09:12:17 +00:00
Neil Kakkar
82352c4a62
Funnel Groups filtering (#6940)
* enable groups filtering

* rerun snapshots

* update team

* fix tests
2021-11-09 08:32:55 +00:00
Karl-Aksel Puulmann
a39596c092
Groups: Use materialized columns for groups (#6938)
* Migration to use materialized columns for groups

Workaround for https://github.com/PostHog/posthog/issues/6422

* Use groups materialized columns in queries

* Update mat column creation tests

* Simplify aggregation_target_field

* Fix migration

* Update snapshots
2021-11-08 15:49:39 +02:00
Neil Kakkar
d2fe491bfc
Funnel Groups: Rename person_id to aggregation_target (#6939)
* smallest change to make aggregation work

* address comments

* add snapshot

* move function to groups model

* update funnel snapshot

* rename person_id to aggregation_target

* update snapshots as well

* dont support persons query mods for now

* update snapshot

* make array orders deterministic
2021-11-08 14:45:13 +02:00
Neil Kakkar
a400296266
Backend: Groups Aggregation on Funnels (#6937)
* smallest change to make aggregation work
* use team in filter
2021-11-08 11:29:56 +00:00
Neil Kakkar
283319adfc
Modify query to not use properties for autocapture (#6711)
* modify query to not use properties for autocapture

* address comments

* add benchmark test to check if worth materialising
2021-10-28 13:12:26 +01:00
Neil Kakkar
a95e47a80f
Enable exclusions on all kinds of correlations (#6654)
* Enable exclusions on all kinds of correlations

* rm action

* address comment
2021-10-26 13:56:30 +01:00
Neil Kakkar
6ab4b2673a
Backend support for autocapture elements chain in Correlations (#6627)
* Backend support for autocapture elements chain properties

* address some comments
2021-10-25 13:21:57 +01:00
Neil Kakkar
d92ca6ee44
Enable persons modal for properties correlation (#6611)
* Enable persons modal for properties correlation

* adjust header

* fix typings
2021-10-22 14:37:17 +01:00
Neil Kakkar
c87aae2338
Backend for querying persons given an event (#6588)
* Backend for querying persons given an event

* address comments

* add test
2021-10-21 13:40:19 +01:00
Harry Waye
43de375d44
fix(correlation): fix recursion limit error if no steps provided (#6548)
Previously we would attempt to generate a response even though there
were no steps. There appears to be some code paths that blow up if this
happens, so instead we return as soon as we can in this case. This
appears to be the behaviour elsewhere also.

This resolves the sentry error found here:
https://sentry.io/organizations/posthog/issues/2718768248/
2021-10-19 14:38:36 +00:00
Neil Kakkar
f85da24f49
Add backend for correlation event properties (#6539)
* Add backend for event properties

* address comments
2021-10-19 13:55:54 +00:00
Karl-Aksel Puulmann
457e151f58
Push person predicates down (#6346)
* Refactor column_optimizer to work differently

* WIP: Use counter over set

* Handle person filters in person query

* Remove a dead argument

* Use enum over parameter for determining behavior

* Allow excluding person properties mode when handled in person query

* Fix _get_person_query type

* Use correct table for funnel_event_query

* Remove unneeded override

* Add extra typing

* Filter by entity.properties in person query for trends

* Handle error 184 due to naming clash

* Better default for prop_filter_json_extract

* Update column_optimizer tests for Counter

* Handle person_props as extra_fields

* Handle breakdowns and person property filter pushdown

* Transform values correctly

* Simplify get_entity_filtering_params

* Fix funnel correlations

* Solve caching issues in trend people queries

* Remove @skip test

* Add syrupy tests for parse_prop_clauses

Can update these via --snapshot-update

* Add snapshot tests for person queries

* Add a few notes

* Update test to avoid collision

* Kill dead code

* Handle PR comments

* Update ee/clickhouse/queries/person_query.py

Co-authored-by: Neil Kakkar <neilkakkar@gmail.com>

Co-authored-by: Neil Kakkar <neilkakkar@gmail.com>
2021-10-13 14:00:47 +00:00
Karl-Aksel Puulmann
b5e00e44da
Skip a flaky funnel test (#6379)
This seems to be semi-consistently failing locally for me and
inconsistently on CI. The cause is unknown - debugging locally, this
seems more of a query correctness issue than a test data incomplete
issue.
2021-10-12 10:57:34 +03:00
Neil Kakkar
10ae7ca6e3
Enable running correlations over all properties and respect conversio… (#6352)
* Enable running correlations over all properties and respect conversion window

* address comments
2021-10-11 11:13:26 +00:00
Neil Kakkar
d468ed32bf
Discard low significance items, alter odds definition, mention skewed… (#6329)
* Discard low significance items, alter odds definition, mention skewed results

* add test for insignificance

* address comment
2021-10-08 11:27:50 +00:00
Neil Kakkar
899ad24722
Support multiple correlation properties (#6312)
* Support multiple correlation properties

* extensive comments, now that they get stripped at runtime

* rename funnel_correlation_values
2021-10-07 17:22:10 +01:00
Neil Kakkar
8b2cc5d02e
Write few more tests for Correlation + ColumnOptimizer (#6309) 2021-10-07 13:29:16 +00:00
Neil Kakkar
823b3e7ec3
Correlation Analysis for Properties: Backend (#6305)
* Correlation Analysis for Properties

* clean typings

* address some comments

* use ClickhousePersonQuery
2021-10-07 12:24:25 +00:00
Harry Waye
50ee7b91f4
fix(correlation): add lower bounds for selected events (#6280)
* fix(correlation): ensure correlation partitioned by team

Previously if distinct_id's were the same between two teams, we'd end up
pulling in the event data between the teams.

* dev(tests): clear cache between partition calls

* fix(correlation): add lower bounds for selected events

Previously we would consider all events for correlation calculation. Now
we use the funnel `date_from` as the lower bounds.

* chore(correlation): exclude funnel steps

* chore(correlation): make sure cache is cleared before each test

* Update funnel success comment

Co-authored-by: Neil Kakkar <neilkakkar@gmail.com>

* fix: filter events by team_id

* chore(correlation): remove CTEs from correlation query

There seems to be an issue with the CTEs and production clickhouse, see
https://github.com/ClickHouse/ClickHouse/issues/29748

Instead of risking it, I'm just removing them.

* chore: update entities -> events for funnel step exclusion

* fix team_id = team_id issue

Co-authored-by: Neil Kakkar <neilkakkar@gmail.com>
2021-10-07 08:17:07 +01:00
Neil Kakkar
a59610e432
Use FunnelStep properly in Correlation Queries (#6289)
* two wrongs don't make a right

* give beginning timestamps as well
2021-10-06 15:34:19 +00:00
Neil Kakkar
7bfeb9d1b9
Add basic model for Correlation analysis on Funnels behind FF (#6258)
* Add basic model for Correlation analysis on Funnels behind FF

* make frontend ready for testing

* address comments

* prettier
2021-10-06 13:14:32 +01:00
Harry Waye
9887856c33
Implementation of diagnose event names (#6235)
* chore(diagnose): add a stub endpoint for event diagnosis

This adds an insight endpoint that takes a `target_entity` and returns
a list of events ordered by significance of a person reaching
`target_entity`

Followup PRs will add actual calculations but this should act as a
conversation piece around the structure of request and response, as well
as a stub from which UI development can start.

* play around to get mypy typings right

* Sort out test reponse structurea

* refactor: address CR comments

* feat(diagnose): add diagnose stubs for implementation

* feat(funnel): add event correlation calculation implementation

This adds to the `/api/projects/<team_id>/funnel/correlation` endpoint
an implementation that calculates the odds_ratios for each event that a
user that has been part of a funnel, successful or otherwise.

* chore(correlation): get query working

* refactor(correlation): move functions to Query methods
2021-10-06 11:08:16 +01:00
Eric Duong
1a9eafe0ed
paths: remove funnel limit when querying path funnels (#6210)
* remove funnel limit when querying path funnels

* add limit test and fix args

* fix args

* typos
2021-10-04 09:56:20 -04:00
Alex Gyujin Kim
6d6202317a
Add custom_name to entity model (#6090)
* add custom_name to entity model

* fix test and add custom name to funnel

* fix more tests

* remaining broken tests
2021-09-24 08:31:16 -07:00
Alex Gyujin Kim
662c2be31a
Remove steps parameter in time conversion result (#6046)
* remove steps parameter in time conversion result

* fix tests

Co-authored-by: Marius Andra <marius.andra@gmail.com>
2021-09-21 15:23:32 +02:00
Alex Gyujin Kim
e85fde3921
Split out funnel apis and fix histogram paint order bug (#6002)
* split out funnel apis and fix histogram paint order bug

* fix broken tests

* simplify some more

* make this fail if no steps returned

Co-authored-by: Marius Andra <marius.andra@gmail.com>
2021-09-17 09:36:15 +00:00
Eric Duong
6411a79d9a
Revert "Revert "Paths search between funnel steps (#5847)" (#5899)" (#5900)
This reverts commit 4b1c9167d0.
2021-09-10 11:36:26 -04:00
Eric Duong
4b1c9167d0
Revert "Paths search between funnel steps (#5847)" (#5899)
This reverts commit 685bd3be3e.
2021-09-10 10:50:42 -04:00
Eric Duong
685bd3be3e
Paths search between funnel steps (#5847)
* make timestamp dynamic

* change funnel path type to str

* change include_timestamp_step name

* type issues

* add argument

* add type

* explicit none check

* change field names

* change constant name

* between step test

* use different arguments for defining funnel steps and add tests

* after step test

* fix types

* test for valueerror

* add test for before dropoff

* custom logic for finding paths up to a dropoff

* fix type

* update test

* add comment

* change event names in test to be clearer

* run again

* test without caching

* return caching

* try not caching again

* try not caching again

* try not caching again

* restore caching

* remove funnel_window_days

* remove unused import
2021-09-10 10:46:21 -04:00
Neil Kakkar
6e218705f5
Add test for funnel with autocapture elements chain (#5893)
* add test for funnel elements chain

* address comment
2021-09-10 12:49:25 +01:00
Neil Kakkar
09e2eb0bfd
(No) ColumnOptimizer Updates for Paths (#5859)
* add optimizations for paths

* add test for excluding events as well

* clean
2021-09-09 12:50:46 +01:00
Karl-Aksel Puulmann
6014a4f3b5
Follow-up to breakdowns refactor PR (#5826)
Noticed I missed a comment since the thread got resolved 😅
2021-09-07 16:42:22 +03:00
Karl-Aksel Puulmann
35813b3b49
Refactor breakdowns to work with materialized person columns (#5807)
* Make breakdown join with person if needed

* Refactor trends to be purely class-based, don't rely on wonky inheritance

* Extract method

* Improve person join behavior

* Remove unneeded parameter

* Mark a function thats always passed as such

* Add test case demonstrating previous non-join case

* Unify two get_breakdown_prop_values methods

* Add test for materialized columns

* Simplify trends breakdown query

* Unify _breakdown_prop_params for events/person breakdowns

* Use shared column_optimizer

* Typing fix

* Cleanup

* Code style cleanup

* Code style cleanup

* Fix param ordering
2021-09-07 09:05:13 +03:00
Karl-Aksel Puulmann
a8a33251a9
Use materialized person properties in trends & funnels (#5705)
* ColumnOptimizer: Add functionality for person materialized columns

* WIP: Use person properties in trends/funnels

* Test person materialized props in trends cohort breakdown query

* Make use of materialized person properties in breakdowns

* Mark some cases working with materialized columns

* Test and fix breakdown by person props without filtering

* Make filtering by entity/person props on a join work better

By not assuming everything is under `properties`

* Add test case around breakdown with person properties

* Add test cases around materialization

* Add another materialization test

* Test cohorts and fix breakdowns with person filter

This exposes a limitation in the current implementation

* Fix some cohort tests

* Fix event query tests

* Get a funnel materialized column test running

* Cover more funnel breakdown tests with materialized

* Handle person property breakdowns in funnels

* Fixup funnel typo

* Add tests, fix an indentation issue

* TestFunnelPersons with materialized columns

* Test funnels against actions with person filters

* Add failing test for entity filtering failing

* Add test case for filtering with entity properties

* Show my 'broken' test is actually doing a subquery

* Resolve linting issues
2021-08-26 18:00:49 +00:00