0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-25 11:10:24 +01:00
Commit Graph

163 Commits

Author SHA1 Message Date
Michael Matloka
eb0d289e97
Insight last modification shown (#8273)
* Add Insight `last_modified_at` and `last_modified_by`

* Add "Last modified" to InsightCard

* Use `updated_at` as default `last_modified_at`

* Add `test_created_updated_and_last_modified`

* Fix comments style

* Fix `InsightMeta__modification` alignment

* Run `black`

* Run `black`

* Add `LastModified` to insight page

* Tune `LastModified` margin

* Update test_clickhouse_insights.ambr
2022-01-26 12:04:14 +01:00
Neil Kakkar
840781871b
Update experiments model (#8189)
* update experiments model

* fix typings

* fix bugs

* rename latest
2022-01-24 14:59:14 +00:00
Tiina Turban
d5fce14cea
async migrations separate errors table (#8152) 2022-01-21 19:54:47 +01:00
Yakko Majuri
d25fc565f6
Stateless plugins (#8112)
* WIP stateless plugins

* add test

* fix tests

Co-authored-by: James Greenhill <fuziontech@gmail.com>
2022-01-18 19:42:09 +00:00
Alex Gyujin Kim
204ca1bc92
Add verified properties to event definitions (#8081)
Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com>
2022-01-18 08:38:55 -06: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
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
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
151f759faa
Event property counter (#7500)
* 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

* 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

* move ONE_HOUR to constants

* use sane_repr

* fix typo
2021-12-17 13:54:03 +01: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
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
c32b3a88c8
Experimentation backend (#7492) 2021-12-09 10:24:03 +00:00
Michael Matloka
ecd77dcfe3
Rename "dashboard item" to "insight" where applicable (#7563)
* Rename "dashboard item" to "insight" where applicable

* Use `InsightModel` instead of `InsightType` for former `DashboardItemType`

* Rename some more

* Add migration for enum variant name

* Update migration
2021-12-08 19:06:03 +01: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
Paolo D'Amico
47a2d72007
Stale events support (#7422)
Co-authored-by: Marius Andra <marius.andra@gmail.com>
2021-12-08 06:48:39 -07:00
Tim Glaser
b4f76e39ba
Add max retrying on insights (#7435)
* Add max retrying on insights

* Typing
2021-12-02 11:23:34 +01:00
Yakko Majuri
7520aca027
Add SpecialMigration model (#7054 pt. 1) (#7425)
* SpecialMigration model

* Update latest_migrations.manifest

* update model

* add ph version range to model

* format

* progress -> PositiveSmallIntegerField
2021-11-30 14:23:41 -03: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
Karl-Aksel Puulmann
059c710db3
Groups: Support updating properties incrementally (#7180)
* 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

* Cleanup nits

* Add test showing desired behavior during insert race

* Handle race conditions gracefully
2021-11-18 13:32:04 +02:00
Rick Marron
b78499d61a
Ingest window_id for recordings (#6806)
* add window-id to ingestion

* move window_id into snapshot data

* Add tests

* add window_id to snapshot_data only if included in the event

* add window_id to session_recording_events table

* revert ph-js downgrade

* fix data generator

* remove partition change

* update window_id defaults for tests

* missed one window_id default

* rename migration for conflict
2021-11-08 14:29:54 -08:00
Harry Waye
b7c898d23e
feat(correlation): load exclude properties from team settings (#6715)
* feat(correlation): add team wide person property exclusion list

This change just adds the exclusion list to the `Team` model and checks
that it can be updated. Separately we can:

 1. add interface for the Project page to display
 2. pull and update this list from the funnels correlation page

NOTE: We don't perform any validation on the structure, :fingerscrossed:
this won't be an issue. Alternative would be to use ArrayField, but use
of JSONField is consistent with other fields.

* test(correlation): add test checking exclude properties pulled from team

* feat(correlation): load exclude properties from team settings

Previously we were loading exclude properties from local storage, so we
would not be sharing the exclusion list between users. This change
simply plugs the `excludePropertyNames` into the `teamLogic` for the
purpose of persisting and loading the values.

* use [teamLogic.actionTypes.loadCurrentTeamSuccess]

* get tests passing

* switch frontend to using `correlation_config`

* refactor: use Team.correlation_config for persistence

* add project settings for correlation

* fix lint

* ensure excluded properties are saved to project config

* Add default excluded properties

* format

* make propertyCorrelations not null

* ensure excluded property names config is unique

* rename excludeProperty to excludePropertyFromProject

* update var names

* change to targetProperties

* remove null special casing

* update to filter client side on exclude from project clicked

* update test name to reflect new functionality

* fix tests
2021-11-02 11:12:13 +00:00
Yakko Majuri
6ce204fe3c
add version to person (#6628)
* add version to person

* add migration

* set all initial version values to 0

* remove defaults

* fix dep
2021-10-28 15:43:30 +00:00
Karl-Aksel Puulmann
cef2af5e4c
Group analytics: Initial schema (#6462)
* Add table for group_type_mapping

* Remove materialized columns from events table schema

These are not used and not needed w/ new mat columns work

* WIP: Migration to add group analytics columns

* Remove event table changes temporarily
2021-10-25 15:05:58 +03:00
Michael Matloka
53a58c9d2c
Rename DashboardItem model to Insight and deprecate DashboardItem{Serializer,ViewSet} (#6567)
* Only run `test_migrations_are_null` on new migrations

* Rename `DashboardItem` to `SavedInsight`

* Add explanation to `test_migrations_are_null` script

* Rename `test_dashboard` to `test_saved_insight_model`

* Ditch `DashboardItem{ViewSet,Serializer}` altogether

* Fix refresh via `InsightSerializer`

* "SavedInsight" to just "Insight"

* Update file names

* Update insight.py

* Update dashboardLogic.test.ts

* Update migration

Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com>
2021-10-25 09:12:37 +02:00
Eric Duong
1f143d109e
Path cleaning integration (#6488)
* initial refactoring

* popup UI

* refactor path cleaning logic

* add nullable

* all ui working

* fix migration

* use regex replacement from team object

* add flag

* add switch

* fix type

* fix type

* UI update

* restore removed arg

* add local path cleaning filters to api

* add test for local path filters

* working new UI

* reduced repeated code

* fix numbering

* minor refactoring

* update copy

* add under advanced features

* address comments, minor cleanup

Co-authored-by: Neil Kakkar <neilkakkar@gmail.com>
2021-10-22 11:51:45 -04:00
Yakko Majuri
1578c468f5
Update should_update_person_prop (#6428) 2021-10-14 14:26:15 +00:00
Michael Matloka
ec0f7ef880
Add slug field to Organization (#6395)
* Add `slug` fields to `Organization` and `Team`

* Expose slugs to user

* Add slug autogeneration for new orgs/projects

* Improve slug UX

* Remove slug from settings

* Update org/team instance creation plus add tests

* Only require project slug to be unique for org, not globally

* Fix `get_prep_value`

* Test organization slugification

* Deslugify `Team`

* Clean up changes

* Update test_user.py

* Apply suggestions from code review

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

* Random 4 letter suffixes for the win

* Fix import

* Ignore `test_migrations_are_null`

* Fix `RunSQL` query being empty

* Fix `generate_random_short_suffix` testing

Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com>
2021-10-13 14:09:40 +02:00
Yakko Majuri
1f951f7c39
Postgres function should_update_person_props (#6259)
* add migration for function

* add test

* fix migration name

* approach to address raw sql in migrations

* add more tests, address review

* add equal timestamps test

* update structure

* format

* much better approach, fix tests
2021-10-07 08:41:07 +00:00
Yakko Majuri
27f9481716
Add properties_last_operation to person table (#6253)
* add properties_last_operation to person model

* update comment
2021-10-06 12:28:09 +00:00
Michael Matloka
7fa218bcf8
Add cohort description backend (#6089)
* Add cohort description backend

* Increase `Cohort.description` limit

* Require `DASHBOARD_COLLABORATION` for cohort description box to be shown
2021-09-27 11:57:13 +00:00
Michael Matloka
bc3e223265
Project-based permissioning framework (#5976)
* Refactor `AvailableFeature` from strings to an enum everywhere

* Fix circular dependency and type

* Add "Per-project access" feature flag, premium feature, and organization switch

* Rename `OrganizationMembershipLevel` to `OrganizationAccessLevel`

* Create `ExplicitTeamMembership` model

* Show whether projects are restricted in the project switcher

* Update organizations API code

* Fix migrations

* Move organization tests that require EE to `ee`

* Revert `OrganizationMembershipLevel` rename

* Fix organization tests

* Update migration

* Fix schema and add Members to Project Settings

* Build out test memberships API with security tests

* Update `TeamMembers` and `teamMembersLogic`

* Move "Per-project access" description to tooltip

* Add moar tests

* Fix Project Members list logic

* Add additional membership checks

* Update migrations

* Fix typing

* Adjust explicit team memberships API similarly

* Fix typo

* Unify `ExplicitTeamMemberSerializer`

* Remove old changes to `membersLogic` usage

* Use `effective_membership_level` on `TeamBasicSerializer`

* Clean up organization update tests

* Explicitly disallow enabling per-project access for free

* Fix circular import

* Remove `id` from `UserSerializer`

* Fix typing

* Try to fix import

* Fix fatal typing

* Add more tests

* Update permissioning.ts

* Add clarifying comment to migration

* Fix import

* minor clarifications

* Revert `TopNavigation` changes

* Make new access control entirely project-based

* Update migrations

* Add `project_based_permissioning` to `TeamBasicSerializer`

* Update test_team.py

* Fix Access Control restriction tooltip

* adjust copy & UI a bit

* Address feedback on field comment

* "Privacy settings" to "Access Control"

* Ignore mypy

* Rename `Team` field `project_based_permissioning` to `access_control`

* Update migrations

Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com>
2021-09-22 18:29:59 +02:00
Yakko Majuri
ca57946ff3
add properties_last_updated_at (#6058) 2021-09-22 14:44:14 +00:00
Marius Andra
e13d8e9b6b
Action step empty field ==> null (#5942)
* save null for empty action steps

* save null for empty action steps in toolbar

* simplify

* fix type

* reset existing empty action step fields
2021-09-21 14:04:17 +02:00
Rick Marron
cdd43b908d
Add feature flag overrides api (#5824)
* override feature flags in the API

* improve types (thanks mypy!)

* remove unrelated code

* better comment

* fix test query count

* remove v2 in get_active_feature_flags_v2

* store `$feature/{key}` in properties

* Move feature flag overrides to their own model

* little bit of cleanup

* some type check + test cleanup

* respond to comments, add tests, add team permission checks

* add basic analytics

* add team to override model and simplify endpoints

* cleanup

* fix up instrumentation

* restrict a user to only their own overrides

* override query now works for all distinct ids

* typing fix

* fix tests

* sort flags by created date

* fix tests

* Clean up

* remove defualt from override_value field

* update migration

* fix migration dependancy

* run black on feature_flag.py

Co-authored-by: Marius Andra <marius.andra@gmail.com>
2021-09-14 09:41:17 -07:00
Yakko Majuri
e708d202c6
Job triggering interface (#5720)
* wip job triggering interface

* add support for number

* update tests

* fix api call

* minor fixes

* move to kea, better UI, remove logs

* updates
2021-09-13 07:01:28 +00:00
Sam Winslow
aedd207a78
Add dive dashboard to model + API (#5779)
* add key for dive dashboard to model

* simplify API & add dive dashboard to it

* walk back sketchy api changes
2021-09-01 22:17:06 +01:00
Karl-Aksel Puulmann
82056d2f05
Add migration to index person by team_id, id DESC (#5489)
Closes https://github.com/PostHog/posthog/issues/4941
2021-08-09 13:57:24 +03:00
Li Yi Yu
cd94321cba
Saved insights default page (#5416) 2021-08-05 07:38:07 -07:00
Michael Matloka
e48bd8b08b
Allow "new member" email opt-out (#5430) 2021-08-04 18:09:41 -07:00
Sam Winslow
60cbf2e7c1
Trigram fuzzy search for property definitions (#5039)
* Trigram fuzzy search for property definitions

* support empty search param

* Only use pg_trgm search if pg extension is installed

* suppress exceptions if migration does not succeed

* checks for index

* troubleshooting

* wip: change migration number; strip out conditionals

* wip: copy code from #4110

* remove is_pg_trgm_installed

* try ngram search on CH

* add AND before ngram

* correct some check failures

* remove ordering

* remove ordering from tests

* fix ordering

* rewrite queries for psql, add test bypass for EE features

* remove ordering filter bc of bugs

* remove test code

* check if isinstance of RawQuerySet

* cleanup sql

* add ordering

* typing

* test for ee prop definition

* adjustments to test_ee_property_definition

* add test_ee_event_definition

* restore this prop

* convert to simple term filter

* use term search in EE

* fix EE tests

* fix non-EE tests

* fix test

* fix filter types

Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com>
Co-authored-by: Marius Andra <marius.andra@gmail.com>
2021-07-20 14:58:16 +02:00
Paolo D'Amico
1b190e89cf
SSO domain whitelist (#5111) 2021-07-15 18:20:43 -05:00
Tim Glaser
208d201bba
Remove accidental breakdown on funnels (#5106)
* Remove accidental breakdown on funnels

* fix
2021-07-13 18:17:54 +02:00
Yakko Majuri
6c9bb2db0f
Update token gen (#4832)
* use base36 for random tokens

* Use prefix + base62

* add migration

Co-authored-by: Michael Matloka <dev@twixes.com>
2021-06-23 13:19:05 -03:00
Yakko Majuri
a71a1eac96
add metrics to plugin table (#4783) 2021-06-22 11:07:05 -03:00
Li Yi Yu
7546e3ea0a
Event properties taxonomy (#4486)
* add description and tag fields to event and property definitions

* set up description and tagging on models

* frontend functionality for description editing

* connect backend and kea logic for description editing

* update event and property definitions model and migration

* delete set null instead of cascade

* migration merge fix

* add owner column

* undo posthog event property taxonomy migrations

* set up definitions on enterprise level

* allow enterprise definitions description editing

* fix licensing conditions and add tests

* proper get and update methods for the multi inheritance table and new column fields for enterprise event model

* check for license to separate routes

* migrate existing definitions to ee definitions tables and render ee vs non-ee definition views based on existing feature conditional

* all the working backend updates

* updated tests

* frontend fixes and linting updates

* feature flag it
2021-06-03 09:22:16 -04:00
Paolo D'Amico
1b0240d7fa
Insights short share URL (#4513) 2021-06-01 07:18:19 -07:00
Michael Matloka
eaf2459724
Save Organization.available_features as a DB column (#4426)
* 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

* Remove redundant null=False

* Fix `Organization.update_available_features()`

* Run Cloud tests in respect to `posthog-cloud` `4426-fix` branch

* Revert "Run Cloud tests in respect to `posthog-cloud` `4426-fix` branch"

This reverts commit 421e8541b3.
2021-05-24 22:17:01 +02:00
Karl-Aksel Puulmann
030529cfb3
Show internal metrics on /instance/status page (#4366)
* Extract function for capture

* Add capability to capture internal metrics

- This is behind an environment variable, we'll turn this on by default
on clickhouse-based installation.
- A special Org/Team gets created for this lazily, which is not accessible for
anyone. This makes avoiding issues with stats/billing/properties and easier.

* Capture some useful metrics into posthog

* Set up an unique constraint for for_internal_metrics organization

This avoids some nasty race conditions

* internal_metrics fixes

* Extract component OverviewTab

* New tabbing system for system status page

* Embed ClickhouseTab

* Generate a dashboard for internal metrics on demand

* More metrics

* Add more internal metrics, add tests

* Fix migration files

* Adjust copy

* Update task definitions

* Fix a typing issue

* Rename a component

* Migration fixup

* Try reset patch after test ends

* Clear lru_cache between tests
2021-05-20 13:42:39 +03:00
Neil Kakkar
7be1b0ef92
Add Capabilities to Plugin model (#4371)
* Add capabilities to plugin model

* update tests
2021-05-18 11:46:01 +01:00
Tim Glaser
1ae890fbe2
1534 configurable columns person events table (#4141)
Co-authored-by: Mohit Gupta <mohitgupta3mail@gmail.com>
Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com>
Co-authored-by: Sam Winslow <sammywinslow@gmail.com>
2021-05-13 14:13:54 -07:00