diff --git a/.github/workflows/ci-hobby.yml b/.github/workflows/ci-hobby.yml index c5b878c8d2184..0025e656c8204 100644 --- a/.github/workflows/ci-hobby.yml +++ b/.github/workflows/ci-hobby.yml @@ -35,7 +35,16 @@ jobs: token: ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }} - name: Get python deps run: pip install python-digitalocean==1.17.0 requests==2.28.1 + - name: Setup DO Hobby Instance + run: python3 bin/hobby-ci.py create + env: + DIGITALOCEAN_TOKEN: ${{ secrets.DIGITALOCEAN_TOKEN }} - name: Run smoke tests on DO - run: python3 bin/hobby-ci.py $GITHUB_HEAD_REF + run: python3 bin/hobby-ci.py test $GITHUB_HEAD_REF + env: + DIGITALOCEAN_TOKEN: ${{ secrets.DIGITALOCEAN_TOKEN }} + - name: Post-cleanup step + if: always() + run: python3 bin/hobby-ci.py destroy env: DIGITALOCEAN_TOKEN: ${{ secrets.DIGITALOCEAN_TOKEN }} diff --git a/bin/docker-worker-celery b/bin/docker-worker-celery index 5d1e7567fcabe..bbd9949d88352 100755 --- a/bin/docker-worker-celery +++ b/bin/docker-worker-celery @@ -71,6 +71,10 @@ FLAGS+=("-n node@%h") # On Heroku $WEB_CONCURRENCY contains suggested number of forks per dyno type # https://github.com/heroku/heroku-buildpack-python/blob/main/vendor/WEB_CONCURRENCY.sh [[ -n "${WEB_CONCURRENCY}" ]] && FLAGS+=" --concurrency $WEB_CONCURRENCY" +# Restart worker process after it processes this many tasks (to mitigate memory leaks) +[[ -n "${CELERY_MAX_TASKS_PER_CHILD}" ]] && FLAGS+=" --max-tasks-per-child $CELERY_MAX_TASKS_PER_CHILD" +# Restart worker process after it exceeds this much memory usage (to mitigate memory leaks) +[[ -n "${CELERY_MAX_MEMORY_PER_CHILD}" ]] && FLAGS+=" --max-memory-per-child $CELERY_MAX_MEMORY_PER_CHILD" if [[ -z "${CELERY_WORKER_QUEUES}" ]]; then source ./bin/celery-queues.env diff --git a/bin/hobby-ci.py b/bin/hobby-ci.py index 7eed9237e6c83..c19022692ece7 100644 --- a/bin/hobby-ci.py +++ b/bin/hobby-ci.py @@ -3,8 +3,6 @@ import datetime import os import random -import re -import signal import string import sys import time @@ -12,43 +10,73 @@ import digitalocean import requests -letters = string.ascii_lowercase -random_bit = "".join(random.choice(letters) for i in range(4)) -name = f"do-ci-hobby-deploy-{random_bit}" -region = "sfo3" -image = "ubuntu-22-04-x64" -size = "s-4vcpu-8gb" -release_tag = "latest-release" -branch_regex = re.compile("release-*.*") -branch = sys.argv[1] -if branch_regex.match(branch): - release_tag = f"{branch}-unstable" -hostname = f"{name}.posthog.cc" -user_data = ( - f"#!/bin/bash \n" - "mkdir hobby \n" - "cd hobby \n" - "sed -i \"s/#\\$nrconf{restart} = 'i';/\\$nrconf{restart} = 'a';/g\" /etc/needrestart/needrestart.conf \n" - "git clone https://github.com/PostHog/posthog.git \n" - "cd posthog \n" - f"git checkout {branch} \n" - "cd .. \n" - f"chmod +x posthog/bin/deploy-hobby \n" - f"./posthog/bin/deploy-hobby {release_tag} {hostname} 1 \n" -) -token = os.getenv("DIGITALOCEAN_TOKEN") + +DOMAIN = "posthog.cc" class HobbyTester: - def __init__(self, domain, droplet, record): - # Placeholders for DO resources + def __init__( + self, + token=None, + name=None, + region="sfo3", + image="ubuntu-22-04-x64", + size="s-4vcpu-8gb", + release_tag="latest-release", + branch=None, + hostname=None, + domain=DOMAIN, + droplet_id=None, + droplet=None, + record_id=None, + record=None, + ): + if not token: + token = os.getenv("DIGITALOCEAN_TOKEN") + self.token = token + self.branch = branch + self.release_tag = release_tag + + random_bit = "".join(random.choice(string.ascii_lowercase) for i in range(4)) + + if not name: + name = f"do-ci-hobby-deploy-{self.release_tag}-{random_bit}" + self.name = name + + if not hostname: + hostname = f"{name}.{DOMAIN}" + self.hostname = hostname + + self.region = region + self.image = image + self.size = size + self.domain = domain self.droplet = droplet + if droplet_id: + self.droplet = digitalocean.Droplet(token=self.token, id=droplet_id) + self.record = record + if record_id: + self.record = digitalocean.Record(token=self.token, id=record_id) - @staticmethod - def block_until_droplet_is_started(droplet): - actions = droplet.get_actions() + self.user_data = ( + f"#!/bin/bash \n" + "mkdir hobby \n" + "cd hobby \n" + "sed -i \"s/#\\$nrconf{restart} = 'i';/\\$nrconf{restart} = 'a';/g\" /etc/needrestart/needrestart.conf \n" + "git clone https://github.com/PostHog/posthog.git \n" + "cd posthog \n" + f"git checkout {self.branch} \n" + "cd .. \n" + f"chmod +x posthog/bin/deploy-hobby \n" + f"./posthog/bin/deploy-hobby {self.release_tag} {self.hostname} 1 \n" + ) + + def block_until_droplet_is_started(self): + if not self.droplet: + return + actions = self.droplet.get_actions() up = False while not up: for action in actions: @@ -60,42 +88,43 @@ def block_until_droplet_is_started(droplet): print("Droplet not booted yet - waiting a bit") time.sleep(5) - @staticmethod - def get_public_ip(droplet): + def get_public_ip(self): + if not self.droplet: + return ip = None while not ip: time.sleep(1) - droplet.load() - ip = droplet.ip_address + self.droplet.load() + ip = self.droplet.ip_address print(f"Public IP found: {ip}") # type: ignore return ip - @staticmethod - def create_droplet(ssh_enabled=False): + def create_droplet(self, ssh_enabled=False): keys = None if ssh_enabled: - manager = digitalocean.Manager(token=token) + manager = digitalocean.Manager(token=self.token) keys = manager.get_all_sshkeys() - droplet = digitalocean.Droplet( - token=token, - name=name, - region=region, - image=image, - size_slug=size, - user_data=user_data, + self.droplet = digitalocean.Droplet( + token=self.token, + name=self.name, + region=self.region, + image=self.image, + size_slug=self.size, + user_data=self.user_data, ssh_keys=keys, tags=["ci"], ) - droplet.create() - return droplet + self.droplet.create() + return self.droplet - @staticmethod - def wait_for_instance(hostname, timeout=20, retry_interval=15): + def test_deployment(self, timeout=20, retry_interval=15): + if not self.hostname: + return # timeout in minutes # return true if success or false if failure print("Attempting to reach the instance") print(f"We will time out after {timeout} minutes") - url = f"https://{hostname}/_health" + url = f"https://{self.hostname}/_health" start_time = datetime.datetime.now() while datetime.datetime.now() < start_time + datetime.timedelta(minutes=timeout): try: @@ -115,9 +144,29 @@ def wait_for_instance(hostname, timeout=20, retry_interval=15): print("Failure - we timed out before receiving a heartbeat") return False + def create_dns_entry(self, type, name, data, ttl=30): + self.domain = digitalocean.Domain(token=self.token, name=DOMAIN) + self.record = self.domain.create_new_domain_record(type=type, name=name, data=data, ttl=ttl) + return self.record + + def create_dns_entry_for_instance(self): + if not self.droplet: + return + self.record = self.create_dns_entry(type="A", name=self.name, data=self.get_public_ip()) + return self.record + + def destroy_self(self, retries=3): + if not self.droplet or not self.domain or not self.record: + return + droplet_id = self.droplet.id + self.destroy_environment(droplet_id, self.domain, self.record["domain_record"]["id"], retries=retries) + @staticmethod - def destroy_environment(droplet, domain, record, retries=3): + def destroy_environment(droplet_id, record_id, retries=3): print("Destroying the droplet") + token = os.getenv("DIGITALOCEAN_TOKEN") + droplet = digitalocean.Droplet(token=token, id=droplet_id) + domain = digitalocean.Domain(token=token, name=DOMAIN) attempts = 0 while attempts <= retries: attempts += 1 @@ -131,36 +180,83 @@ def destroy_environment(droplet, domain, record, retries=3): while attempts <= retries: attempts += 1 try: - domain.delete_domain_record(id=record["domain_record"]["id"]) + domain.delete_domain_record(id=record_id) break except Exception as e: print(f"Could not destroy the dns entry because\n{e}") def handle_sigint(self): - self.destroy_environment(self.droplet, self.domain, self.record) + self.destroy_self() + + def export_droplet(self): + if not self.droplet: + print("Droplet not found. Exiting") + exit(1) + if not self.record: + print("DNS record not found. Exiting") + exit(1) + record_id = self.record["domain_record"]["id"] + record_name = self.record["domain_record"]["name"] + droplet_id = self.droplet.id + + print(f"Exporting the droplet ID: {self.droplet.id} and DNS record ID: {record_id} for name {self.name}") + env_file_name = os.getenv("GITHUB_ENV") + with open(env_file_name, "a") as env_file: + env_file.write(f"HOBBY_DROPLET_ID={droplet_id}\n") + with open(env_file_name, "a") as env_file: + env_file.write(f"HOBBY_DNS_RECORD_ID={record_id}\n") + env_file.write(f"HOBBY_DNS_RECORD_NAME={record_name}\n") + env_file.write(f"HOBBY_NAME={self.name}\n") + + def ensure_droplet(self, ssh_enabled=True): + self.create_droplet(ssh_enabled=ssh_enabled) + self.block_until_droplet_is_started() + self.create_dns_entry_for_instance() + self.export_droplet() def main(): - print("Creating droplet on Digitalocean for testing Hobby Deployment") - droplet = HobbyTester.create_droplet(ssh_enabled=True) - HobbyTester.block_until_droplet_is_started(droplet) - public_ip = HobbyTester.get_public_ip(droplet) - domain = digitalocean.Domain(token=token, name="posthog.cc") - record = domain.create_new_domain_record(type="A", name=name, data=public_ip) - - hobby_tester = HobbyTester(domain, droplet, record) - signal.signal(signal.SIGINT, hobby_tester.handle_sigint) # type: ignore - signal.signal(signal.SIGHUP, hobby_tester.handle_sigint) # type: ignore - print("Instance has started. You will be able to access it here after PostHog boots (~15 minutes):") - print(f"https://{hostname}") - health_success = HobbyTester.wait_for_instance(hostname) - HobbyTester.destroy_environment(droplet, domain, record) - if health_success: - print("We succeeded") - exit() - else: - print("We failed") - exit(1) + command = sys.argv[1] + if command == "create": + print("Creating droplet on Digitalocean for testing Hobby Deployment") + ht = HobbyTester() + ht.ensure_droplet(ssh_enabled=True) + print("Instance has started. You will be able to access it here after PostHog boots (~15 minutes):") + print(f"https://{ht.hostname}") + + if command == "destroy": + print("Destroying droplet on Digitalocean for testing Hobby Deployment") + droplet_id = os.environ.get("HOBBY_DROPLET_ID") + domain_record_id = os.environ.get("HOBBY_DNS_RECORD_ID") + print(f"Droplet ID: {droplet_id}") + print(f"Record ID: {domain_record_id}") + HobbyTester.destroy_environment(droplet_id=droplet_id, record_id=domain_record_id) + + if command == "test": + if len(sys.argv) < 3: + print("Please provide the branch name to test") + exit(1) + branch = sys.argv[2] + name = os.environ.get("HOBBY_NAME") + record_id = os.environ.get("HOBBY_DNS_RECORD_ID") + droplet_id = os.environ.get("HOBBY_DROPLET_ID") + print(f"Testing the deployment for {name} on branch {branch}") + print(f"Record ID: {record_id}") + print(f"Droplet ID: {droplet_id}") + + ht = HobbyTester( + branch=branch, + name=name, + record_id=record_id, + droplet_id=droplet_id, + ) + health_success = ht.test_deployment() + if health_success: + print("We succeeded") + exit() + else: + print("We failed") + exit(1) if __name__ == "__main__": diff --git a/cypress/e2e/featureFlags.cy.ts b/cypress/e2e/featureFlags.cy.ts index 78f0bcd0ab8bd..e4f7e35edb718 100644 --- a/cypress/e2e/featureFlags.cy.ts +++ b/cypress/e2e/featureFlags.cy.ts @@ -119,8 +119,9 @@ describe('Feature Flags', () => { // select "add filter" and "property" cy.get('[data-attr=property-select-toggle-0').click() - // select the third property + // select the first property cy.get('[data-attr=taxonomic-filter-searchfield]').click() + cy.get('[data-attr=taxonomic-filter-searchfield]').type('is_demo') cy.get('[data-attr=taxonomic-tab-person_properties]').click() // select numeric $browser_version cy.get('[data-attr=prop-filter-person_properties-2]').click({ force: true }) diff --git a/ee/api/debug_ch_queries.py b/ee/api/debug_ch_queries.py index f4e7ec8760c26..6c4b1746b425b 100644 --- a/ee/api/debug_ch_queries.py +++ b/ee/api/debug_ch_queries.py @@ -15,7 +15,7 @@ class DebugCHQueries(viewsets.ViewSet): """ - Show recent queries for this user + List recent CH queries initiated by this user. """ def _get_path(self, query: str) -> Optional[str]: @@ -30,16 +30,21 @@ def list(self, request): response = sync_execute( """ - select - query, query_start_time, exception, toInt8(type), query_duration_ms - from clusterAllReplicas(%(cluster)s, system, query_log) - where - query LIKE %(query)s and - query_start_time > %(start_time)s and - type != 1 and - query not like %(not_query)s - order by query_start_time desc - limit 100""", + SELECT + query_id, argMax(query, type), argMax(query_start_time, type), argMax(exception, type), + argMax(query_duration_ms, type), max(type) AS status + FROM ( + SELECT + query_id, query, query_start_time, exception, query_duration_ms, toInt8(type) AS type + FROM clusterAllReplicas(%(cluster)s, system, query_log) + WHERE + query LIKE %(query)s AND + query NOT LIKE %(not_query)s AND + query_start_time > %(start_time)s + ORDER BY query_start_time desc + LIMIT 100 + ) + GROUP BY query_id""", { "query": f"/* user_id:{request.user.pk} %", "start_time": (now() - relativedelta(minutes=10)).timestamp(), @@ -50,12 +55,13 @@ def list(self, request): return Response( [ { - "query": resp[0], - "timestamp": resp[1], - "exception": resp[2], - "type": resp[3], + "query_id": resp[0], + "query": resp[1], + "timestamp": resp[2], + "exception": resp[3], "execution_time": resp[4], - "path": self._get_path(resp[0]), + "status": resp[5], + "path": self._get_path(resp[1]), } for resp in response ] diff --git a/frontend/__snapshots__/exporter-exporter--funnel-top-to-bottom-breakdown-insight--dark.png b/frontend/__snapshots__/exporter-exporter--funnel-top-to-bottom-breakdown-insight--dark.png index 223b0b5a5e0fa..edfba77bef6d2 100644 Binary files a/frontend/__snapshots__/exporter-exporter--funnel-top-to-bottom-breakdown-insight--dark.png and b/frontend/__snapshots__/exporter-exporter--funnel-top-to-bottom-breakdown-insight--dark.png differ diff --git a/frontend/__snapshots__/scenes-app-insights--funnel-top-to-bottom-breakdown-edit--light.png b/frontend/__snapshots__/scenes-app-insights--funnel-top-to-bottom-breakdown-edit--light.png index effe9ed3b3aaf..ce6b88c8b832a 100644 Binary files a/frontend/__snapshots__/scenes-app-insights--funnel-top-to-bottom-breakdown-edit--light.png and b/frontend/__snapshots__/scenes-app-insights--funnel-top-to-bottom-breakdown-edit--light.png differ diff --git a/frontend/src/layout/FeaturePreviews/featurePreviewsLogic.test.ts b/frontend/src/layout/FeaturePreviews/featurePreviewsLogic.test.ts index f0ff2f6404de7..3bd8f0590f20d 100644 --- a/frontend/src/layout/FeaturePreviews/featurePreviewsLogic.test.ts +++ b/frontend/src/layout/FeaturePreviews/featurePreviewsLogic.test.ts @@ -2,6 +2,7 @@ import { expectLogic } from 'kea-test-utils' import { MOCK_DEFAULT_USER } from 'lib/api.mock' import { userLogic } from 'scenes/userLogic' +import { useMocks } from '~/mocks/jest' import { initKeaTests } from '~/test/init' import { featurePreviewsLogic } from './featurePreviewsLogic' @@ -10,6 +11,11 @@ describe('featurePreviewsLogic', () => { let logic: ReturnType beforeEach(() => { + useMocks({ + post: { + 'https://posthoghelp.zendesk.com/api/v2/requests.json': [200, {}], + }, + }) initKeaTests() logic = featurePreviewsLogic() logic.mount() diff --git a/frontend/src/lib/components/AnnotationsOverlay/annotationsOverlayLogic.test.ts b/frontend/src/lib/components/AnnotationsOverlay/annotationsOverlayLogic.test.ts index 02d59125c852f..b5ec3468d12f1 100644 --- a/frontend/src/lib/components/AnnotationsOverlay/annotationsOverlayLogic.test.ts +++ b/frontend/src/lib/components/AnnotationsOverlay/annotationsOverlayLogic.test.ts @@ -143,6 +143,7 @@ function useInsightMocks(interval: string = 'day', timezone: string = 'UTC'): vo [`/api/projects/:team_id/insights/${MOCK_INSIGHT_NUMERIC_ID}`]: () => { return [200, insight] }, + '/api/users/@me/': [200, {}], }, }) } @@ -162,6 +163,7 @@ function useAnnotationsMocks(): void { MOCK_ANNOTATION_PROJECT_SCOPED_FROM_INSIGHT_3, ], }, + '/api/users/@me/': [200, {}], }, }) } @@ -171,6 +173,7 @@ describe('annotationsOverlayLogic', () => { beforeEach(() => { useAnnotationsMocks() + initKeaTests() }) afterEach(() => { @@ -178,8 +181,6 @@ describe('annotationsOverlayLogic', () => { }) it('loads annotations on mount', async () => { - initKeaTests() - useInsightMocks() logic = annotationsOverlayLogic({ @@ -193,8 +194,6 @@ describe('annotationsOverlayLogic', () => { }) describe('relevantAnnotations', () => { - initKeaTests() - it('returns annotations scoped to the insight for a saved insight', async () => { useInsightMocks() @@ -224,8 +223,6 @@ describe('annotationsOverlayLogic', () => { }) it('returns annotations scoped to the project for a new insight', async () => { - initKeaTests() - useInsightMocks() logic = annotationsOverlayLogic({ @@ -250,8 +247,6 @@ describe('annotationsOverlayLogic', () => { }) it('excludes annotations that are outside of insight date range', async () => { - initKeaTests() - useInsightMocks() logic = annotationsOverlayLogic({ @@ -506,8 +501,6 @@ describe('annotationsOverlayLogic', () => { } it(`merges groups when one tick covers more than one date (UTC)`, async () => { - initKeaTests(true, MOCK_DEFAULT_TEAM) - useInsightMocks() logic = annotationsOverlayLogic({ @@ -572,8 +565,6 @@ describe('annotationsOverlayLogic', () => { }) it(`merges groups when one tick covers more than one hour (UTC)`, async () => { - initKeaTests(true, MOCK_DEFAULT_TEAM) - useInsightMocks('hour') logic = annotationsOverlayLogic({ diff --git a/frontend/src/lib/components/AuthorizedUrlList/authorizedUrlListLogic.test.ts b/frontend/src/lib/components/AuthorizedUrlList/authorizedUrlListLogic.test.ts index b21f9012925bb..772646e28882a 100644 --- a/frontend/src/lib/components/AuthorizedUrlList/authorizedUrlListLogic.test.ts +++ b/frontend/src/lib/components/AuthorizedUrlList/authorizedUrlListLogic.test.ts @@ -27,6 +27,9 @@ describe('the authorized urls list logic', () => { return [200, { result: ['result from api'] }] }, }, + patch: { + '/api/projects/:team': [200, {}], + }, }) initKeaTests() logic = authorizedUrlListLogic({ diff --git a/frontend/src/lib/components/CommandPalette/DebugCHQueries.tsx b/frontend/src/lib/components/CommandPalette/DebugCHQueries.tsx index 295298eb0fc28..9c73b502718dd 100644 --- a/frontend/src/lib/components/CommandPalette/DebugCHQueries.tsx +++ b/frontend/src/lib/components/CommandPalette/DebugCHQueries.tsx @@ -25,7 +25,11 @@ export interface Query { timestamp: string query: string exception: string - type: number + /** + * 1 means running, 2 means finished, 3 means errored before execution, 4 means errored during execution. + * + * @see `type` column in https://clickhouse.com/docs/en/operations/system-tables/query_log */ + status: 1 | 2 | 3 | 4 execution_time: number path: string } @@ -146,9 +150,13 @@ function DebugCHQueries(): JSX.Element { ) }, }, + { title: 'Duration', render: function exec(_, item) { + if (item.status === 1) { + return 'In progress…' + } return <>{Math.round((item.execution_time + Number.EPSILON) * 100) / 100} ms }, align: 'right', diff --git a/frontend/src/lib/components/PropertyFilters/components/TaxonomicPropertyFilter.tsx b/frontend/src/lib/components/PropertyFilters/components/TaxonomicPropertyFilter.tsx index 644b01f74b063..d416c1e0502c3 100644 --- a/frontend/src/lib/components/PropertyFilters/components/TaxonomicPropertyFilter.tsx +++ b/frontend/src/lib/components/PropertyFilters/components/TaxonomicPropertyFilter.tsx @@ -9,7 +9,6 @@ import { propertyFilterLogic } from 'lib/components/PropertyFilters/propertyFilt import { PropertyFilterInternalProps } from 'lib/components/PropertyFilters/types' import { isGroupPropertyFilter, - isPersonPropertyFilter, isPropertyFilterWithOperator, PROPERTY_FILTER_TYPE_TO_TAXONOMIC_FILTER_GROUP_TYPE, propertyFilterTypeToTaxonomicFilterType, @@ -64,7 +63,7 @@ export function TaxonomicPropertyFilter({ value, item ) => { - selectItem(taxonomicGroup, value, item) + selectItem(taxonomicGroup, value, item?.propertyFilterType) if ( taxonomicGroup.type === TaxonomicFilterGroupType.Cohorts || taxonomicGroup.type === TaxonomicFilterGroupType.HogQLExpression @@ -215,7 +214,6 @@ export function TaxonomicPropertyFilter({ value: newValue || null, operator: newOperator, type: filter?.type, - ...(isPersonPropertyFilter(filter) ? { table: filter?.table } : {}), ...(isGroupPropertyFilter(filter) ? { group_type_index: filter.group_type_index } : {}), diff --git a/frontend/src/lib/components/PropertyFilters/components/taxonomicPropertyFilterLogic.ts b/frontend/src/lib/components/PropertyFilters/components/taxonomicPropertyFilterLogic.ts index 48760e5ab6747..aa1a1ca685cc7 100644 --- a/frontend/src/lib/components/PropertyFilters/components/taxonomicPropertyFilterLogic.ts +++ b/frontend/src/lib/components/PropertyFilters/components/taxonomicPropertyFilterLogic.ts @@ -51,10 +51,14 @@ export const taxonomicPropertyFilterLogic = kea ({ + selectItem: ( + taxonomicGroup: TaxonomicFilterGroup, + propertyKey?: TaxonomicFilterValue, + itemPropertyFilterType?: PropertyFilterType + ) => ({ taxonomicGroup, propertyKey, - item, + itemPropertyFilterType, }), openDropdown: true, closeDropdown: true, @@ -89,8 +93,7 @@ export const taxonomicPropertyFilterLogic = kea ({ - selectItem: ({ taxonomicGroup, propertyKey, item }) => { - const itemPropertyFilterType = item?.propertyFilterType as PropertyFilterType + selectItem: ({ taxonomicGroup, propertyKey, itemPropertyFilterType }) => { const propertyType = itemPropertyFilterType ?? taxonomicFilterTypeToPropertyFilterType(taxonomicGroup.type) if (propertyKey && propertyType) { if (propertyType === PropertyFilterType.Cohort) { @@ -126,8 +129,8 @@ export const taxonomicPropertyFilterLogic = kea { useMocks({ get: { '/api/projects/:team/subscriptions/1': fixtureSubscriptionResponse(1), + '/api/projects/:team/integrations': { count: 0, results: [] }, }, }) initKeaTests() diff --git a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx index b5904b8957056..cc3e727f7b10d 100644 --- a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx +++ b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx @@ -28,8 +28,7 @@ import { cohortsModel } from '~/models/cohortsModel' import { dashboardsModel } from '~/models/dashboardsModel' import { groupPropertiesModel } from '~/models/groupPropertiesModel' import { groupsModel } from '~/models/groupsModel' -import { personPropertiesModel } from '~/models/personPropertiesModel' -import { updateListOfPropertyDefinitions } from '~/models/propertyDefinitionsModel' +import { updatePropertyDefinitions } from '~/models/propertyDefinitionsModel' import { AnyDataNode, DatabaseSchemaQueryResponseField, NodeKind } from '~/queries/schema' import { ActionType, @@ -77,7 +76,7 @@ export const taxonomicFilterLogic = kea([ props({} as TaxonomicFilterLogicProps), key((props) => `${props.taxonomicFilterLogicKey}`), path(['lib', 'components', 'TaxonomicFilter', 'taxonomicFilterLogic']), - connect((props: TaxonomicFilterLogicProps) => ({ + connect({ values: [ teamLogic, ['currentTeamId'], @@ -87,13 +86,8 @@ export const taxonomicFilterLogic = kea([ ['allGroupProperties'], dataWarehouseSceneLogic, ['externalTables'], - personPropertiesModel({ - propertyAllowList: props.propertyAllowList, - taxonomicFilterLogicKey: props.taxonomicFilterLogicKey, - }), - ['combinedPersonProperties'], ], - })), + }), actions(() => ({ moveUp: true, moveDown: true, @@ -171,7 +165,6 @@ export const taxonomicFilterLogic = kea([ s.metadataSource, s.excludedProperties, s.propertyAllowList, - s.taxonomicFilterLogicKey, ], ( teamId, @@ -181,8 +174,7 @@ export const taxonomicFilterLogic = kea([ schemaColumns, metadataSource, excludedProperties, - propertyAllowList, - taxonomicFilterLogicKey + propertyAllowList ): TaxonomicFilterGroup[] => { const groups: TaxonomicFilterGroup[] = [ { @@ -333,15 +325,14 @@ export const taxonomicFilterLogic = kea([ name: 'Person properties', searchPlaceholder: 'person properties', type: TaxonomicFilterGroupType.PersonProperties, - logic: personPropertiesModel({ propertyAllowList, taxonomicFilterLogicKey }), - value: 'combinedPersonProperties', + endpoint: combineUrl(`api/projects/${teamId}/property_definitions`, { + type: 'person', + properties: propertyAllowList?.[TaxonomicFilterGroupType.PersonProperties] + ? propertyAllowList[TaxonomicFilterGroupType.PersonProperties].join(',') + : undefined, + }).url, getName: (personProperty: PersonProperty) => personProperty.name, - getValue: (personProperty: PersonProperty) => { - if (personProperty.table) { - return personProperty.id - } - return personProperty.name - }, + getValue: (personProperty: PersonProperty) => personProperty.name, propertyAllowList: propertyAllowList?.[TaxonomicFilterGroupType.PersonProperties], ...propertyTaxonomicGroupProps(true), }, @@ -707,7 +698,14 @@ export const taxonomicFilterLogic = kea([ groupType === TaxonomicFilterGroupType.NumericalEventProperties) ) { const propertyDefinitions: PropertyDefinition[] = results.results as PropertyDefinition[] - updateListOfPropertyDefinitions(propertyDefinitions, groupType) + const apiType = groupType === TaxonomicFilterGroupType.PersonProperties ? 'person' : 'event' + const newPropertyDefinitions = Object.fromEntries( + propertyDefinitions.map((propertyDefinition) => [ + `${apiType}/${propertyDefinition.name}`, + propertyDefinition, + ]) + ) + updatePropertyDefinitions(newPropertyDefinitions) } }, })), diff --git a/frontend/src/lib/components/TaxonomicFilter/types.ts b/frontend/src/lib/components/TaxonomicFilter/types.ts index a3edff51c16f0..964847c6eacaf 100644 --- a/frontend/src/lib/components/TaxonomicFilter/types.ts +++ b/frontend/src/lib/components/TaxonomicFilter/types.ts @@ -1,5 +1,5 @@ import Fuse from 'fuse.js' -import { BuiltLogic, LogicWrapper } from 'kea' +import { LogicWrapper } from 'kea' import { DataWarehouseTableType } from 'scenes/data-warehouse/types' import { LocalFilter } from 'scenes/insights/filters/ActionFilter/entityFilterLogic' @@ -61,7 +61,7 @@ export interface TaxonomicFilterGroup { scopedEndpoint?: string expandLabel?: (props: { count: number; expandedCount: number }) => React.ReactNode options?: Record[] - logic?: LogicWrapper | BuiltLogic + logic?: LogicWrapper value?: string searchAlias?: string valuesEndpoint?: (key: string) => string diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx index 292fcb5d957b7..b4ef15a8bea8f 100644 --- a/frontend/src/lib/constants.tsx +++ b/frontend/src/lib/constants.tsx @@ -212,6 +212,7 @@ export const FEATURE_FLAGS = { AUDIT_LOGS_ACCESS: 'audit-logs-access', // owner: #team-growth SUBSCRIBE_FROM_PAYGATE: 'subscribe-from-paygate', // owner: #team-growth REVERSE_PROXY_ONBOARDING: 'reverse-proxy-onboarding', // owner: @zlwaterfield + SESSION_REPLAY_MOBILE_ONBOARDING: 'session-replay-mobile-onboarding', // owner: #team-replay } as const export type FeatureFlagKey = (typeof FEATURE_FLAGS)[keyof typeof FEATURE_FLAGS] diff --git a/frontend/src/mocks/handlers.ts b/frontend/src/mocks/handlers.ts index 3b4d5c2577a7e..e155aa67cf805 100644 --- a/frontend/src/mocks/handlers.ts +++ b/frontend/src/mocks/handlers.ts @@ -10,6 +10,7 @@ import { MOCK_PERSON_PROPERTIES, MOCK_SECOND_ORGANIZATION_MEMBER, } from 'lib/api.mock' +import { ResponseComposition, RestContext, RestRequest } from 'msw' import { getAvailableFeatures } from '~/mocks/features' import { SharingConfigurationType } from '~/types' @@ -25,6 +26,19 @@ export const toPaginatedResponse = (results: any[]): typeof EMPTY_PAGINATED_RESP previous: null, }) +// this really returns MaybePromise> +// but MSW doesn't export MaybePromise 🤷 +function posthogCORSResponse(req: RestRequest, res: ResponseComposition, ctx: RestContext): any { + return res( + ctx.status(200), + ctx.json('ok'), + // some of our tests try to make requests via posthog-js e.g. userLogic calls identify + // they have to have CORS allowed, or they pass but print noise to the console + ctx.set('Access-Control-Allow-Origin', req.referrer.length ? req.referrer : 'http://localhost'), + ctx.set('Access-Control-Allow-Credentials', 'true') + ) +} + export const defaultMocks: Mocks = { get: { '/api/projects/:team_id/activity_log/important_changes/': EMPTY_PAGINATED_RESPONSE, @@ -108,12 +122,13 @@ export const defaultMocks: Mocks = { }, }, post: { - 'https://us.i.posthog.com/e/': (): MockSignature => [200, 'ok'], - '/e/': (): MockSignature => [200, 'ok'], - 'https://us.i.posthog.com/decide/': (): MockSignature => [200, 'ok'], - '/decide/': (): MockSignature => [200, 'ok'], - 'https://us.i.posthog.com/engage/': (): MockSignature => [200, 'ok'], + 'https://us.i.posthog.com/e/': (req, res, ctx): MockSignature => posthogCORSResponse(req, res, ctx), + '/e/': (req, res, ctx): MockSignature => posthogCORSResponse(req, res, ctx), + 'https://us.i.posthog.com/decide/': (req, res, ctx): MockSignature => posthogCORSResponse(req, res, ctx), + '/decide/': (req, res, ctx): MockSignature => posthogCORSResponse(req, res, ctx), + 'https://us.i.posthog.com/engage/': (req, res, ctx): MockSignature => posthogCORSResponse(req, res, ctx), '/api/projects/:team_id/insights/:insight_id/viewed/': (): MockSignature => [201, null], + 'api/projects/:team_id/query': [200, { results: [] }], }, } export const handlers = mocksToHandlers(defaultMocks) diff --git a/frontend/src/models/personPropertiesModel.ts b/frontend/src/models/personPropertiesModel.ts deleted file mode 100644 index f319095c3ba81..0000000000000 --- a/frontend/src/models/personPropertiesModel.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { connect, events, kea, key, listeners, path, props, selectors } from 'kea' -import { loaders } from 'kea-loaders' -import { combineUrl, router } from 'kea-router' -import api from 'lib/api' -import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types' -import { FEATURE_FLAGS } from 'lib/constants' -import { featureFlagLogic } from 'lib/logic/featureFlagLogic' -import { dataWarehouseJoinsLogic } from 'scenes/data-warehouse/external/dataWarehouseJoinsLogic' -import { teamLogic } from 'scenes/teamLogic' - -import { updateListOfPropertyDefinitions } from '~/models/propertyDefinitionsModel' -import { PersonProperty, PropertyDefinition } from '~/types' - -import type { personPropertiesModelType } from './personPropertiesModelType' -import { PersonPropertiesModelProps } from './types' - -const WHITELISTED = ['/insights', '/events', '/sessions', '/dashboard', '/person'] - -export const personPropertiesModel = kea([ - props({} as PersonPropertiesModelProps), - path(['models', 'personPropertiesModel']), - key((props) => props.taxonomicFilterLogicKey), - connect({ - values: [ - teamLogic, - ['currentTeamId'], - dataWarehouseJoinsLogic, - ['columnsJoinedToPersons'], - featureFlagLogic, - ['featureFlags'], - ], - }), - loaders(({ values }) => ({ - personProperties: [ - [] as PersonProperty[], - { - loadPersonProperties: async () => { - const url = combineUrl(`api/projects/${values.currentTeamId}/property_definitions`, { - type: 'person', - properties: values.propertyAllowList?.[TaxonomicFilterGroupType.PersonProperties] - ? values.propertyAllowList[TaxonomicFilterGroupType.PersonProperties].join(',') - : undefined, - }).url - return (await api.get(url)).results - }, - }, - ], - })), - listeners(() => ({ - loadPersonPropertiesSuccess: ({ personProperties }) => { - updateListOfPropertyDefinitions( - personProperties as PropertyDefinition[], - TaxonomicFilterGroupType.PersonProperties - ) - }, - })), - selectors(() => ({ - combinedPersonProperties: [ - (s) => [s.personProperties, s.columnsJoinedToPersons, s.featureFlags], - (personProperties, columnsJoinedToPersons, featureFlags) => { - // Hack to make sure person properties only show data warehouse in specific instances for now - if ( - featureFlags[FEATURE_FLAGS.DATA_WAREHOUSE] && - WHITELISTED.some((path) => router.values.location.pathname.includes(path)) - ) { - return [...personProperties, ...columnsJoinedToPersons] - } - return [...personProperties] - }, - ], - propertyAllowList: [ - () => [(_, props) => props.propertyAllowList], - (propertyAllowList) => propertyAllowList as PersonPropertiesModelProps['propertyAllowList'], - ], - })), - events(({ actions }) => ({ - afterMount: actions.loadPersonProperties, - })), -]) diff --git a/frontend/src/models/propertyDefinitionsModel.ts b/frontend/src/models/propertyDefinitionsModel.ts index b7bba27261714..338e60a5e956f 100644 --- a/frontend/src/models/propertyDefinitionsModel.ts +++ b/frontend/src/models/propertyDefinitionsModel.ts @@ -1,6 +1,6 @@ import { actions, kea, listeners, path, reducers, selectors } from 'kea' import api, { ApiMethodOptions } from 'lib/api' -import { TaxonomicFilterGroupType, TaxonomicFilterValue } from 'lib/components/TaxonomicFilter/types' +import { TaxonomicFilterValue } from 'lib/components/TaxonomicFilter/types' import { dayjs } from 'lib/dayjs' import { captureTimeToSeeData } from 'lib/internalMetrics' import { colonDelimitedDuration } from 'lib/utils' @@ -46,18 +46,6 @@ export const updatePropertyDefinitions = (propertyDefinitions: PropertyDefinitio propertyDefinitionsModel.findMounted()?.actions.updatePropertyDefinitions(propertyDefinitions) } -export const updateListOfPropertyDefinitions = ( - results: PropertyDefinition[], - groupType: TaxonomicFilterGroupType -): void => { - const propertyDefinitions: PropertyDefinition[] = results - const apiType = groupType === TaxonomicFilterGroupType.PersonProperties ? 'person' : 'event' - const newPropertyDefinitions = Object.fromEntries( - propertyDefinitions.map((propertyDefinition) => [`${apiType}/${propertyDefinition.name}`, propertyDefinition]) - ) - updatePropertyDefinitions(newPropertyDefinitions) -} - export type PropValue = { id?: number name?: string | boolean diff --git a/frontend/src/models/types.ts b/frontend/src/models/types.ts deleted file mode 100644 index b3f4c22f60d4d..0000000000000 --- a/frontend/src/models/types.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types' - -export interface PersonPropertiesModelProps { - propertyAllowList?: { [key in TaxonomicFilterGroupType]?: string[] } // only return properties in this list, currently only working for EventProperties and PersonProperties - taxonomicFilterLogicKey: string -} diff --git a/frontend/src/queries/nodes/DataNode/dataNodeLogic.queryCancellation.test.ts b/frontend/src/queries/nodes/DataNode/dataNodeLogic.queryCancellation.test.ts index 55a417bdff91e..ead4227a3c793 100644 --- a/frontend/src/queries/nodes/DataNode/dataNodeLogic.queryCancellation.test.ts +++ b/frontend/src/queries/nodes/DataNode/dataNodeLogic.queryCancellation.test.ts @@ -39,6 +39,9 @@ describe('dataNodeLogic - query cancellation', () => { ) }, }, + delete: { + '/api/projects/:team_id/query/uuid-first': [200, {}], + }, }) }) afterEach(() => logic?.unmount()) diff --git a/frontend/src/queries/query.ts b/frontend/src/queries/query.ts index f866b2f336d31..e2149303733b6 100644 --- a/frontend/src/queries/query.ts +++ b/frontend/src/queries/query.ts @@ -222,7 +222,7 @@ export async function query( if (hogQLInsightsLiveCompareEnabled) { const legacyFunction = (): any => { try { - return legacyUrl ? fetchLegacyUrl : fetchLegacyInsights + return legacyUrl ? fetchLegacyUrl() : fetchLegacyInsights() } catch (e) { console.error('Error fetching legacy insights', e) } @@ -258,11 +258,17 @@ export async function query( res2 = res2[0]?.people.map((n: any) => n.id) res1 = res1.map((n: any) => n[0].id) // Sort, since the order of the results is not guaranteed + const bv = (v: any): string => + [null, 'null', 'none', '9007199254740990', 9007199254740990].includes(v) + ? '$$_posthog_breakdown_null_$$' + : ['Other', '9007199254740991', 9007199254740991].includes(v) + ? '$$_posthog_breakdown_other_$$' + : String(v) res1.sort((a: any, b: any) => - (a.breakdown_value ?? a.label ?? a).localeCompare(b.breakdown_value ?? b.label ?? b) + bv(a.breakdown_value ?? a.label ?? a).localeCompare(bv(b.breakdown_value ?? b.label ?? b)) ) res2.sort((a: any, b: any) => - (a.breakdown_value ?? a.label ?? a).localeCompare(b.breakdown_value ?? b.label ?? b) + bv(a.breakdown_value ?? a.label ?? a).localeCompare(bv(b.breakdown_value ?? b.label ?? b)) ) } diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.json index bb6e2256a43c8..eeac4bb951269 100644 --- a/frontend/src/queries/schema.json +++ b/frontend/src/queries/schema.json @@ -3460,9 +3460,6 @@ "operator": { "$ref": "#/definitions/PropertyOperator" }, - "table": { - "type": "string" - }, "type": { "const": "person", "description": "Person properties", diff --git a/frontend/src/scenes/data-management/events/DefinitionHeader.tsx b/frontend/src/scenes/data-management/events/DefinitionHeader.tsx index 5dcbc8c3604d1..9ecf8b43ce2ed 100644 --- a/frontend/src/scenes/data-management/events/DefinitionHeader.tsx +++ b/frontend/src/scenes/data-management/events/DefinitionHeader.tsx @@ -1,4 +1,4 @@ -import { IconBadge, IconBolt, IconCursor, IconEye, IconLeave, IconList, IconLogomark, IconServer } from '@posthog/icons' +import { IconBadge, IconBolt, IconCursor, IconEye, IconLeave, IconList, IconLogomark } from '@posthog/icons' import { PropertyKeyInfo } from 'lib/components/PropertyKeyInfo' import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types' import { IconSelectAll } from 'lib/lemon-ui/icons' @@ -24,14 +24,6 @@ export function getPropertyDefinitionIcon(definition: PropertyDefinition): JSX.E ) } - if (definition.table) { - return ( - - - - ) - } - return ( diff --git a/frontend/src/scenes/data-warehouse/external/dataWarehouseJoinsLogic.ts b/frontend/src/scenes/data-warehouse/external/dataWarehouseJoinsLogic.ts index 6c6a3af715664..b5f493b2d7f17 100644 --- a/frontend/src/scenes/data-warehouse/external/dataWarehouseJoinsLogic.ts +++ b/frontend/src/scenes/data-warehouse/external/dataWarehouseJoinsLogic.ts @@ -1,19 +1,13 @@ -import { afterMount, connect, kea, path, selectors } from 'kea' +import { afterMount, kea, path } from 'kea' import { loaders } from 'kea-loaders' import api from 'lib/api' -import { capitalizeFirstLetter } from 'lib/utils' -import { DatabaseSchemaQueryResponseField } from '~/queries/schema' -import { DataWarehouseViewLink, PropertyDefinition, PropertyType } from '~/types' +import { DataWarehouseViewLink } from '~/types' import type { dataWarehouseJoinsLogicType } from './dataWarehouseJoinsLogicType' -import { dataWarehouseSceneLogic } from './dataWarehouseSceneLogic' export const dataWarehouseJoinsLogic = kea([ path(['scenes', 'data-warehouse', 'external', 'dataWarehouseJoinsLogic']), - connect(() => ({ - values: [dataWarehouseSceneLogic, ['externalTablesMap']], - })), loaders({ joins: [ [] as DataWarehouseViewLink[], @@ -25,40 +19,6 @@ export const dataWarehouseJoinsLogic = kea([ }, ], }), - selectors({ - personTableJoins: [(s) => [s.joins], (joins) => joins.filter((join) => join.source_table_name === 'persons')], - tablesJoinedToPersons: [ - (s) => [s.externalTablesMap, s.personTableJoins], - (externalTablesMap, personTableJoins) => { - return personTableJoins.map((join: DataWarehouseViewLink) => { - // valid join should have a joining table name - const table = externalTablesMap[join.joining_table_name as string] - return { - table, - join, - } - }) - }, - ], - columnsJoinedToPersons: [ - (s) => [s.tablesJoinedToPersons], - (tablesJoinedToPersons) => { - return tablesJoinedToPersons.reduce((acc, { table, join }) => { - if (table) { - acc.push( - ...table.columns.map((column: DatabaseSchemaQueryResponseField) => ({ - id: column.key, - name: join.field_name + ': ' + column.key, - table: join.field_name, - property_type: capitalizeFirstLetter(column.type) as PropertyType, - })) - ) - } - return acc - }, [] as PropertyDefinition[]) - }, - ], - }), afterMount(({ actions }) => { actions.loadJoins() }), diff --git a/frontend/src/scenes/funnels/funnelCorrelationFeedbackLogic.test.ts b/frontend/src/scenes/funnels/funnelCorrelationFeedbackLogic.test.ts index b88946646be5c..0ac26e5540b5e 100644 --- a/frontend/src/scenes/funnels/funnelCorrelationFeedbackLogic.test.ts +++ b/frontend/src/scenes/funnels/funnelCorrelationFeedbackLogic.test.ts @@ -1,6 +1,7 @@ import { expectLogic } from 'kea-test-utils' import { eventUsageLogic } from 'lib/utils/eventUsageLogic' import posthog from 'posthog-js' +import { teamLogic } from 'scenes/teamLogic' import { useAvailableFeatures } from '~/mocks/features' import { initKeaTests } from '~/test/init' @@ -14,6 +15,7 @@ describe('funnelCorrelationFeedbackLogic', () => { beforeEach(() => { useAvailableFeatures([AvailableFeature.CORRELATION_ANALYSIS]) initKeaTests(false) + teamLogic.mount() }) const defaultProps: InsightLogicProps = { diff --git a/frontend/src/scenes/insights/insightVizDataLogic.test.ts b/frontend/src/scenes/insights/insightVizDataLogic.test.ts index d1de2cd7b8af5..a0a535c7e1686 100644 --- a/frontend/src/scenes/insights/insightVizDataLogic.test.ts +++ b/frontend/src/scenes/insights/insightVizDataLogic.test.ts @@ -23,6 +23,7 @@ describe('insightVizDataLogic', () => { useMocks({ get: { '/api/projects/:team_id/insights/trend': [], + '/api/projects/:team_id/insights/': { results: [{}] }, }, }) initKeaTests() diff --git a/frontend/src/scenes/notebooks/Nodes/utils.test.tsx b/frontend/src/scenes/notebooks/Nodes/utils.test.tsx index af46f229b2cd8..09cfe7c1ceebd 100644 --- a/frontend/src/scenes/notebooks/Nodes/utils.test.tsx +++ b/frontend/src/scenes/notebooks/Nodes/utils.test.tsx @@ -1,6 +1,6 @@ import { NodeViewProps } from '@tiptap/core' import { useSyncedAttributes } from './utils' -import { renderHook, act } from '@testing-library/react-hooks' +import { renderHook, act } from '@testing-library/react' describe('notebook node utils', () => { jest.useFakeTimers() diff --git a/frontend/src/scenes/onboarding/Onboarding.tsx b/frontend/src/scenes/onboarding/Onboarding.tsx index 52efdd5d47f0a..adcd6d3476b4d 100644 --- a/frontend/src/scenes/onboarding/Onboarding.tsx +++ b/frontend/src/scenes/onboarding/Onboarding.tsx @@ -1,11 +1,13 @@ import { useActions, useValues } from 'kea' -import { SESSION_REPLAY_MINIMUM_DURATION_OPTIONS } from 'lib/constants' +import { FEATURE_FLAGS, SESSION_REPLAY_MINIMUM_DURATION_OPTIONS } from 'lib/constants' +import { featureFlagLogic } from 'lib/logic/featureFlagLogic' import { useEffect, useState } from 'react' +import { AndroidInstructions } from 'scenes/onboarding/sdks/session-replay' import { SceneExport } from 'scenes/sceneTypes' import { teamLogic } from 'scenes/teamLogic' import { userLogic } from 'scenes/userLogic' -import { AvailableFeature, ProductKey } from '~/types' +import { AvailableFeature, ProductKey, SDKKey } from '~/types' import { OnboardingBillingStep } from './OnboardingBillingStep' import { OnboardingInviteTeammates } from './OnboardingInviteTeammates' @@ -108,6 +110,9 @@ const SessionReplayOnboarding = (): JSX.Element => { const { hasAvailableFeature } = useValues(userLogic) const { currentTeam } = useValues(teamLogic) + const { featureFlags } = useValues(featureFlagLogic) + const hasAndroidOnBoarding = !!featureFlags[FEATURE_FLAGS.SESSION_REPLAY_MOBILE_ONBOARDING] + const configOptions: ProductConfigOption[] = [ { type: 'toggle', @@ -139,11 +144,16 @@ const SessionReplayOnboarding = (): JSX.Element => { }) } + const sdkInstructionMap = SessionReplaySDKInstructions + if (hasAndroidOnBoarding) { + sdkInstructionMap[SDKKey.ANDROID] = AndroidInstructions + } + return ( @@ -151,6 +161,7 @@ const SessionReplayOnboarding = (): JSX.Element => { ) } + const FeatureFlagsOnboarding = (): JSX.Element => { return ( diff --git a/frontend/src/scenes/onboarding/onboardingLogic.tsx b/frontend/src/scenes/onboarding/onboardingLogic.tsx index 4c8b35542109e..b53b14afc6b62 100644 --- a/frontend/src/scenes/onboarding/onboardingLogic.tsx +++ b/frontend/src/scenes/onboarding/onboardingLogic.tsx @@ -316,9 +316,9 @@ export const onboardingLogic = kea([ actionToUrl(({ values }) => ({ setStepKey: ({ stepKey }) => { if (stepKey) { - return [`/onboarding/${values.productKey}`, { step: stepKey }] + return [`/onboarding/${values.productKey}`, { ...router.values.searchParams, step: stepKey }] } else { - return [`/onboarding/${values.productKey}`] + return [`/onboarding/${values.productKey}`, router.values.searchParams] } }, goToNextStep: () => { @@ -327,9 +327,12 @@ export const onboardingLogic = kea([ ) const nextStep = values.allOnboardingSteps[currentStepIndex + 1] if (nextStep) { - return [`/onboarding/${values.productKey}`, { step: nextStep.props.stepKey }] + return [ + `/onboarding/${values.productKey}`, + { ...router.values.searchParams, step: nextStep.props.stepKey }, + ] } else { - return [`/onboarding/${values.productKey}`] + return [`/onboarding/${values.productKey}`, router.values.searchParams] } }, goToPreviousStep: () => { @@ -338,9 +341,12 @@ export const onboardingLogic = kea([ ) const previousStep = values.allOnboardingSteps[currentStepIndex - 1] if (previousStep) { - return [`/onboarding/${values.productKey}`, { step: previousStep.props.stepKey }] + return [ + `/onboarding/${values.productKey}`, + { ...router.values.searchParams, step: previousStep.props.stepKey }, + ] } else { - return [`/onboarding/${values.productKey}`] + return [`/onboarding/${values.productKey}`, router.values.searchParams] } }, updateCurrentTeamSuccess(val) { diff --git a/frontend/src/scenes/onboarding/sdks/SDKs.tsx b/frontend/src/scenes/onboarding/sdks/SDKs.tsx index 33555a1f17ca9..610caee92ee4f 100644 --- a/frontend/src/scenes/onboarding/sdks/SDKs.tsx +++ b/frontend/src/scenes/onboarding/sdks/SDKs.tsx @@ -118,6 +118,7 @@ export function SDKs({ {sdks?.map((sdk) => ( setSelectedSDK(sdk) : undefined} fullWidth diff --git a/frontend/src/scenes/onboarding/sdks/product-analytics/android.tsx b/frontend/src/scenes/onboarding/sdks/product-analytics/android.tsx index 365f8685a8a74..b6a1fb3c9520f 100644 --- a/frontend/src/scenes/onboarding/sdks/product-analytics/android.tsx +++ b/frontend/src/scenes/onboarding/sdks/product-analytics/android.tsx @@ -1,4 +1,12 @@ import { CodeSnippet, Language } from 'lib/components/CodeSnippet' +import { FlaggedFeature } from 'lib/components/FlaggedFeature' +import { FEATURE_FLAGS } from 'lib/constants' +import { LemonTag } from 'lib/lemon-ui/LemonTag' +import { Link } from 'lib/lemon-ui/Link' +import { OnboardingStepKey } from 'scenes/onboarding/onboardingLogic' +import { urls } from 'scenes/urls' + +import { SDKKey } from '~/types' import { SDKInstallAndroidInstructions } from '../sdk-install-instructions' @@ -6,12 +14,31 @@ function AndroidCaptureSnippet(): JSX.Element { return {`PostHog.capture(event = "test-event")`} } +function AdvertiseAndroidReplay(): JSX.Element { + return ( +
+

+ Session Replay for Android NEW +

+
+ Session replay is now in beta for Android.{' '} + + Learn how to set it up + +
+
+ ) +} + export function ProductAnalyticsAndroidInstructions(): JSX.Element { return ( <>

Send an Event

+ + + ) } diff --git a/frontend/src/scenes/onboarding/sdks/sdk-install-instructions/android.tsx b/frontend/src/scenes/onboarding/sdks/sdk-install-instructions/android.tsx index ff740be34f4fd..103a87f183508 100644 --- a/frontend/src/scenes/onboarding/sdks/sdk-install-instructions/android.tsx +++ b/frontend/src/scenes/onboarding/sdks/sdk-install-instructions/android.tsx @@ -1,8 +1,14 @@ +import { Link } from '@posthog/lemon-ui' import { useValues } from 'kea' import { CodeSnippet, Language } from 'lib/components/CodeSnippet' +import { LemonBanner } from 'lib/lemon-ui/LemonBanner' import { apiHostOrigin } from 'lib/utils/apiHost' import { teamLogic } from 'scenes/teamLogic' +export interface AndroidSetupProps { + includeReplay?: boolean +} + function AndroidInstallSnippet(): JSX.Element { return ( @@ -13,7 +19,7 @@ function AndroidInstallSnippet(): JSX.Element { ) } -function AndroidSetupSnippet(): JSX.Element { +function AndroidSetupSnippet({ includeReplay }: AndroidSetupProps): JSX.Element { const { currentTeam } = useValues(teamLogic) return ( @@ -33,6 +39,18 @@ function AndroidSetupSnippet(): JSX.Element { apiKey = POSTHOG_API_KEY, host = POSTHOG_HOST ) + ${ + includeReplay + ? ` + // check https://posthog.com/docs/session-replay/mobile#installation + // for more config and to learn about how we capture sessions on mobile + // and what to expect + config.sessionReplay = true + // choose whether to mask images or text + config.sessionReplayConfig.maskAllImages = false + config.sessionReplayConfig.maskAllTextInputs = true` + : '' + } // Setup PostHog with the given Context and Config PostHogAndroid.setup(this, config) @@ -41,13 +59,24 @@ function AndroidSetupSnippet(): JSX.Element { ) } -export function SDKInstallAndroidInstructions(): JSX.Element { +export function SDKInstallAndroidInstructions(props: AndroidSetupProps): JSX.Element { return ( <> + {props.includeReplay ? ( + + 🚧 NOTE: Mobile recording is + currently in beta. We are keen to gather as much feedback as possible so if you try this out please + let us know. You can send feedback via the{' '} + + in-app support panel + {' '} + or one of our other support options. + + ) : null}

Install

Configure

- + ) } diff --git a/frontend/src/scenes/onboarding/sdks/sdksLogic.tsx b/frontend/src/scenes/onboarding/sdks/sdksLogic.tsx index df4a13d8adaf1..a46984ee8f897 100644 --- a/frontend/src/scenes/onboarding/sdks/sdksLogic.tsx +++ b/frontend/src/scenes/onboarding/sdks/sdksLogic.tsx @@ -1,5 +1,6 @@ import { actions, afterMount, connect, events, kea, listeners, path, reducers, selectors } from 'kea' import { loaders } from 'kea-loaders' +import { urlToAction } from 'kea-router' import api from 'lib/api' import { LemonSelectOptions } from 'lib/lemon-ui/LemonSelect/LemonSelect' @@ -11,7 +12,7 @@ import { onboardingLogic } from '../onboardingLogic' import { allSDKs } from './allSDKs' import type { sdksLogicType } from './sdksLogicType' -/* +/* To add SDK instructions for your product: 1. If needed, add a new ProductKey enum value in ~/types.ts 2. Create a folder in this directory for your product @@ -118,14 +119,16 @@ export const sdksLogic = kea([ loadSnippetEvents: async () => { const query: HogQLQuery = { kind: NodeKind.HogQLQuery, - query: hogql`SELECT properties.$lib_version AS lib_version, max(timestamp) AS latest_timestamp, count(lib_version) as count - FROM events - WHERE timestamp >= now() - INTERVAL 3 DAY - AND timestamp <= now() - AND properties.$lib = 'web' - GROUP BY lib_version - ORDER BY latest_timestamp DESC - limit 10`, + query: hogql`SELECT properties.$lib_version AS lib_version, + max(timestamp) AS latest_timestamp, + count(lib_version) as count + FROM events + WHERE timestamp >= now() - INTERVAL 3 DAY + AND timestamp <= now() + AND properties.$lib = 'web' + GROUP BY lib_version + ORDER BY latest_timestamp DESC + limit 10`, } const res = await api.query(query) @@ -188,4 +191,12 @@ export const sdksLogic = kea([ afterMount(({ actions }) => { actions.loadSnippetEvents() }), + urlToAction(({ actions }) => ({ + '/onboarding/:productKey': (_productKey, { sdk }) => { + const matchedSDK = allSDKs.find((s) => s.key === sdk) + if (matchedSDK) { + actions.setSelectedSDK(matchedSDK) + } + }, + })), ]) diff --git a/frontend/src/scenes/onboarding/sdks/session-replay/SessionReplaySDKInstructions.tsx b/frontend/src/scenes/onboarding/sdks/session-replay/SessionReplaySDKInstructions.tsx index 7e43a06b7faba..16db14dbd1d85 100644 --- a/frontend/src/scenes/onboarding/sdks/session-replay/SessionReplaySDKInstructions.tsx +++ b/frontend/src/scenes/onboarding/sdks/session-replay/SessionReplaySDKInstructions.tsx @@ -7,4 +7,6 @@ export const SessionReplaySDKInstructions: SDKInstructionsMap = { [SDKKey.HTML_SNIPPET]: HTMLSnippetInstructions, [SDKKey.NEXT_JS]: NextJSInstructions, [SDKKey.REACT]: ReactInstructions, + // added by feature flag in Onboarding.tsx until released + //[SDKKey.ANDROID]: AndroidInstructions, } diff --git a/frontend/src/scenes/onboarding/sdks/session-replay/android.tsx b/frontend/src/scenes/onboarding/sdks/session-replay/android.tsx new file mode 100644 index 0000000000000..4afb1dc91ce60 --- /dev/null +++ b/frontend/src/scenes/onboarding/sdks/session-replay/android.tsx @@ -0,0 +1,11 @@ +import { SDKInstallAndroidInstructions } from '../sdk-install-instructions' +import { SessionReplayFinalSteps } from '../shared-snippets' + +export function AndroidInstructions(): JSX.Element { + return ( + <> + + + + ) +} diff --git a/frontend/src/scenes/onboarding/sdks/session-replay/index.tsx b/frontend/src/scenes/onboarding/sdks/session-replay/index.tsx index bee13a5ce58bb..1ef01349747b4 100644 --- a/frontend/src/scenes/onboarding/sdks/session-replay/index.tsx +++ b/frontend/src/scenes/onboarding/sdks/session-replay/index.tsx @@ -1,3 +1,4 @@ +export * from './android' export * from './html-snippet' export * from './js-web' export * from './next-js' diff --git a/frontend/src/scenes/paths/pathsDataLogic.test.ts b/frontend/src/scenes/paths/pathsDataLogic.test.ts index 99e97de3b031f..e22ec58c79aae 100644 --- a/frontend/src/scenes/paths/pathsDataLogic.test.ts +++ b/frontend/src/scenes/paths/pathsDataLogic.test.ts @@ -1,6 +1,7 @@ import { expectLogic } from 'kea-test-utils' import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types' import { pathsDataLogic } from 'scenes/paths/pathsDataLogic' +import { teamLogic } from 'scenes/teamLogic' import { initKeaTests } from '~/test/init' import { InsightLogicProps, InsightType, PathType } from '~/types' @@ -25,6 +26,7 @@ async function initPathsDataLogic(): Promise { describe('pathsDataLogic', () => { beforeEach(async () => { initKeaTests(false) + teamLogic.mount() await initPathsDataLogic() }) diff --git a/frontend/src/scenes/session-recordings/player/inspector/components/ItemPerformanceEvent.tsx b/frontend/src/scenes/session-recordings/player/inspector/components/ItemPerformanceEvent.tsx index 8442cdd4a28aa..5741c225a66a0 100644 --- a/frontend/src/scenes/session-recordings/player/inspector/components/ItemPerformanceEvent.tsx +++ b/frontend/src/scenes/session-recordings/player/inspector/components/ItemPerformanceEvent.tsx @@ -1,7 +1,8 @@ -import { LemonButton, LemonDivider, LemonTabs, LemonTag, LemonTagType, Link } from '@posthog/lemon-ui' +import { LemonButton, LemonDivider, LemonTabs, LemonTag, LemonTagType } from '@posthog/lemon-ui' import clsx from 'clsx' import { CodeSnippet, Language } from 'lib/components/CodeSnippet' import { Dayjs, dayjs } from 'lib/dayjs' +import { Link } from 'lib/lemon-ui/Link' import { Tooltip } from 'lib/lemon-ui/Tooltip' import { humanFriendlyMilliseconds, humanizeBytes, isURL } from 'lib/utils' import { Fragment, useState } from 'react' diff --git a/frontend/src/scenes/session-recordings/player/inspector/playerInspectorLogic.test.ts b/frontend/src/scenes/session-recordings/player/inspector/playerInspectorLogic.test.ts index 236cc3b5b8dc5..4f0bf12fc81cd 100644 --- a/frontend/src/scenes/session-recordings/player/inspector/playerInspectorLogic.test.ts +++ b/frontend/src/scenes/session-recordings/player/inspector/playerInspectorLogic.test.ts @@ -2,6 +2,7 @@ import { expectLogic } from 'kea-test-utils' import { featureFlagLogic } from 'lib/logic/featureFlagLogic' import { playerInspectorLogic } from 'scenes/session-recordings/player/inspector/playerInspectorLogic' +import { useMocks } from '~/mocks/jest' import { initKeaTests } from '~/test/init' const playerLogicProps = { sessionRecordingId: '1', playerKey: 'playlist' } @@ -10,6 +11,11 @@ describe('playerInspectorLogic', () => { let logic: ReturnType beforeEach(() => { + useMocks({ + get: { + 'api/projects/:team_id/session_recordings/1/': {}, + }, + }) initKeaTests() featureFlagLogic.mount() logic = playerInspectorLogic(playerLogicProps) diff --git a/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.test.ts b/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.test.ts index ccbc8d962f1da..4e5002f5dabf7 100644 --- a/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.test.ts +++ b/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.test.ts @@ -29,6 +29,8 @@ describe('sessionRecordingsPlaylistLogic', () => { ], }, + 'api/projects/:team/property_definitions/seen_together': { $pageview: true }, + '/api/projects/:team/session_recordings': (req) => { const { searchParams } = req.url if ( diff --git a/frontend/src/scenes/trends/persons-modal/peronsModalLogic.test.ts b/frontend/src/scenes/trends/persons-modal/peronsModalLogic.test.ts index 70958019ed94c..f2666ba43f58f 100644 --- a/frontend/src/scenes/trends/persons-modal/peronsModalLogic.test.ts +++ b/frontend/src/scenes/trends/persons-modal/peronsModalLogic.test.ts @@ -1,5 +1,6 @@ import { expectLogic } from 'kea-test-utils' +import { useMocks } from '~/mocks/jest' import { initKeaTests } from '~/test/init' import { personsModalLogic } from './personsModalLogic' @@ -8,6 +9,11 @@ describe('personsModalLogic', () => { let logic: ReturnType beforeEach(() => { + useMocks({ + get: { + 'api/projects/:team_id/persons/trends': {}, + }, + }) initKeaTests() }) diff --git a/frontend/src/scenes/urls.ts b/frontend/src/scenes/urls.ts index 943ebbaa80bb2..13262c0eb3656 100644 --- a/frontend/src/scenes/urls.ts +++ b/frontend/src/scenes/urls.ts @@ -16,6 +16,7 @@ import { PipelineTab, ProductKey, ReplayTabs, + SDKKey, } from '~/types' import { OnboardingStepKey } from './onboarding/onboardingLogic' @@ -175,8 +176,10 @@ export const urls = { `/verify_email${userUuid ? `/${userUuid}` : ''}${token ? `/${token}` : ''}`, inviteSignup: (id: string): string => `/signup/${id}`, products: (): string => '/products', - onboarding: (productKey: string, stepKey?: OnboardingStepKey): string => - `/onboarding/${productKey}${stepKey ? '?step=' + stepKey : ''}`, + onboarding: (productKey: string, stepKey?: OnboardingStepKey, sdk?: SDKKey): string => + `/onboarding/${productKey}${stepKey ? '?step=' + stepKey : ''}${ + sdk && stepKey ? '&sdk=' + sdk : sdk ? '?sdk=' + sdk : '' + }`, // Cloud only organizationBilling: (products?: ProductKey[]): string => `/organization/billing${products && products.length ? `?products=${products.join(',')}` : ''}`, diff --git a/frontend/src/types.ts b/frontend/src/types.ts index 58aea7f43fdab..a583fe34c26d2 100644 --- a/frontend/src/types.ts +++ b/frontend/src/types.ts @@ -672,7 +672,6 @@ export interface EventPropertyFilter extends BasePropertyFilter { export interface PersonPropertyFilter extends BasePropertyFilter { type: PropertyFilterType.Person operator: PropertyOperator - table?: string } export interface DataWarehousePropertyFilter extends BasePropertyFilter { @@ -2813,9 +2812,6 @@ export interface PropertyDefinition { verified?: boolean verified_at?: string verified_by?: string - - // For Data warehouse person properties - table?: string } export enum PropertyDefinitionState { @@ -2828,10 +2824,9 @@ export enum PropertyDefinitionState { export type Definition = EventDefinition | PropertyDefinition export interface PersonProperty { - id: string | number + id: number name: string count: number - table?: string } export type GroupTypeIndex = 0 | 1 | 2 | 3 | 4 diff --git a/plugin-server/src/types.ts b/plugin-server/src/types.ts index 114547cfe605f..d70238307eaac 100644 --- a/plugin-server/src/types.ts +++ b/plugin-server/src/types.ts @@ -868,7 +868,6 @@ export interface EventPropertyFilter extends PropertyFilterWithOperator { /** Sync with posthog/frontend/src/types.ts */ export interface PersonPropertyFilter extends PropertyFilterWithOperator { type: 'person' - table?: string } /** Sync with posthog/frontend/src/types.ts */ diff --git a/posthog/hogql/property.py b/posthog/hogql/property.py index ba9f92443b4e8..98019cdaa54b7 100644 --- a/posthog/hogql/property.py +++ b/posthog/hogql/property.py @@ -147,10 +147,7 @@ def property_to_expr( value = property.value if property.type == "person" and scope != "person": - if property.table: - chain = ["person", property.table] - else: - chain = ["person", "properties"] + chain = ["person", "properties"] elif property.type == "group": chain = [f"group_{property.group_type_index}", "properties"] elif property.type == "data_warehouse": diff --git a/posthog/models/property/property.py b/posthog/models/property/property.py index 4bd44646ec4a9..d0e0f94439cf5 100644 --- a/posthog/models/property/property.py +++ b/posthog/models/property/property.py @@ -202,7 +202,6 @@ class Property: total_periods: Optional[int] min_periods: Optional[int] negation: Optional[bool] = False - table: Optional[str] _data: Dict def __init__( @@ -225,7 +224,6 @@ def __init__( seq_time_value: Optional[int] = None, seq_time_interval: Optional[OperatorInterval] = None, negation: Optional[bool] = None, - table: Optional[str] = None, **kwargs, ) -> None: self.key = key @@ -243,7 +241,6 @@ def __init__( self.seq_time_value = seq_time_value self.seq_time_interval = seq_time_interval self.negation = None if negation is None else str_to_bool(negation) - self.table = table if value is None and self.operator in ["is_set", "is_not_set"]: self.value = self.operator diff --git a/posthog/schema.py b/posthog/schema.py index 7068c39090a2f..17ad11fc4f236 100644 --- a/posthog/schema.py +++ b/posthog/schema.py @@ -1369,7 +1369,6 @@ class PersonPropertyFilter(BaseModel): key: str label: Optional[str] = None operator: PropertyOperator - table: Optional[str] = None type: Literal["person"] = Field(default="person", description="Person properties") value: Optional[Union[str, float, List[Union[str, float]]]] = None