Skip to content

Commit

Permalink
feat: track anonymous personfull events in usage reports (#23461)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
raquelmsmith and github-actions[bot] authored Jul 6, 2024
1 parent 18f2be7 commit d302688
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 63 deletions.
3 changes: 2 additions & 1 deletion posthog/models/event/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,12 @@ def bulk_create_events(

except Group.DoesNotExist:
continue
properties = event.get("properties", {})

event = {
"uuid": str(event["event_uuid"]) if event.get("event_uuid") else str(uuid.uuid4()),
"event": event["event"],
"properties": json.dumps(event["properties"]) if event.get("properties") else "{}",
"properties": json.dumps(properties),
"timestamp": timestamp,
"team_id": team_id,
"distinct_id": str(event["distinct_id"]),
Expand Down
123 changes: 80 additions & 43 deletions posthog/tasks/test/__snapshots__/test_usage_report.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.10
'''
WITH JSONExtractInt(log_comment, 'team_id') as team_id,
JSONExtractString(log_comment, 'query_type') as query_type,
JSONExtractString(log_comment, 'access_method') as access_method
SELECT team_id,
sum(query_duration_ms) as count
FROM clusterAllReplicas(posthog, system.query_log)
WHERE (type = 'QueryFinish'
OR type = 'ExceptionWhileProcessing')
AND is_initial_query = 1
AND query_type IN (['hogql_query', 'HogQLQuery'])
AND query_start_time between '2022-01-10 00:00:00' AND '2022-01-10 23:59:59'
AND access_method = ''
GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.11
'''
WITH JSONExtractInt(log_comment, 'team_id') as team_id,
JSONExtractString(log_comment, 'query_type') as query_type,
Expand All @@ -46,7 +63,7 @@
GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.11
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.12
'''
WITH JSONExtractInt(log_comment, 'team_id') as team_id,
JSONExtractString(log_comment, 'query_type') as query_type,
Expand All @@ -63,7 +80,7 @@
GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.12
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.13
'''
WITH JSONExtractInt(log_comment, 'team_id') as team_id,
JSONExtractString(log_comment, 'query_type') as query_type,
Expand All @@ -80,7 +97,7 @@
GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.13
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.14
'''
WITH JSONExtractInt(log_comment, 'team_id') as team_id,
JSONExtractString(log_comment, 'query_type') as query_type,
Expand All @@ -97,7 +114,7 @@
GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.14
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.15
'''
WITH JSONExtractInt(log_comment, 'team_id') as team_id,
JSONExtractString(log_comment, 'query_type') as query_type,
Expand All @@ -114,7 +131,7 @@
GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.15
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.16
'''
WITH JSONExtractInt(log_comment, 'team_id') as team_id,
JSONExtractString(log_comment, 'query_type') as query_type,
Expand All @@ -131,7 +148,7 @@
GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.16
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.17
'''
WITH JSONExtractInt(log_comment, 'team_id') as team_id,
JSONExtractString(log_comment, 'query_type') as query_type,
Expand All @@ -148,7 +165,7 @@
GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.17
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.18
'''
WITH JSONExtractInt(log_comment, 'team_id') as team_id,
JSONExtractString(log_comment, 'query_type') as query_type,
Expand All @@ -165,7 +182,7 @@
GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.18
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.19
'''
WITH JSONExtractInt(log_comment, 'team_id') as team_id,
JSONExtractString(log_comment, 'query_type') as query_type,
Expand All @@ -182,33 +199,55 @@
GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.19
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.2
'''

SELECT team_id,
COUNT() as count
count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
FROM events
WHERE event = 'survey sent'
AND timestamp between '2022-01-10 00:00:00' AND '2022-01-10 23:59:59'
WHERE timestamp between '2022-01-10 00:00:00' AND '2022-01-10 23:59:59'
AND event != '$feature_flag_called'
AND event NOT IN ('survey sent',
'survey shown',
'survey dismissed')
AND person_mode IN ('full',
'force_upgrade')
AND JSONExtractBool(properties, '$is_identified') = 0
AND JSONExtractString(properties, '$lib') = 'web'
GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.2
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.20
'''

SELECT team_id,
count(1) as count
COUNT() as count
FROM events
WHERE timestamp between '2022-01-10 00:00:00' AND '2022-01-10 23:59:59'
AND ($group_0 != ''
OR $group_1 != ''
OR $group_2 != ''
OR $group_3 != ''
OR $group_4 != '')
WHERE event = 'survey sent'
AND timestamp between '2022-01-10 00:00:00' AND '2022-01-10 23:59:59'
GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.20
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.21
'''

SELECT team,
sum(rows_synced)
FROM
(SELECT JSONExtractString(properties, 'job_id') AS job_id,
distinct_id AS team,
any(JSONExtractInt(properties, 'count')) AS rows_synced
FROM events
WHERE team_id = 2
AND event = '$data_sync_job_completed'
AND JSONExtractString(properties, 'start_time') != ''
AND parseDateTimeBestEffort(JSONExtractString(properties, 'start_time')) BETWEEN '2022-01-10 00:00:00' AND '2022-01-10 23:59:59'
GROUP BY job_id,
team)
GROUP BY team
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.22
'''

SELECT team,
Expand All @@ -230,6 +269,21 @@
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.3
'''

SELECT team_id,
count(1) as count
FROM events
WHERE timestamp between '2022-01-10 00:00:00' AND '2022-01-10 23:59:59'
AND ($group_0 != ''
OR $group_1 != ''
OR $group_2 != ''
OR $group_3 != ''
OR $group_4 != '')
GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.4
'''

SELECT team_id,
count(distinct session_id) as count
FROM
Expand All @@ -247,7 +301,7 @@
GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.4
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.5
'''

SELECT team_id,
Expand All @@ -267,7 +321,7 @@
GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.5
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.6
'''

SELECT distinct_id as team,
Expand All @@ -280,7 +334,7 @@
GROUP BY team
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.6
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.7
'''

SELECT distinct_id as team,
Expand All @@ -293,30 +347,13 @@
GROUP BY team
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.7
'''
WITH JSONExtractInt(log_comment, 'team_id') as team_id,
JSONExtractString(log_comment, 'query_type') as query_type,
JSONExtractString(log_comment, 'access_method') as access_method
SELECT team_id,
sum(read_bytes) as count
FROM clusterAllReplicas(posthog, system.query_log)
WHERE (type = 'QueryFinish'
OR type = 'ExceptionWhileProcessing')
AND is_initial_query = 1
AND query_type IN (['hogql_query', 'HogQLQuery'])
AND query_start_time between '2022-01-10 00:00:00' AND '2022-01-10 23:59:59'
AND access_method = ''
GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.8
'''
WITH JSONExtractInt(log_comment, 'team_id') as team_id,
JSONExtractString(log_comment, 'query_type') as query_type,
JSONExtractString(log_comment, 'access_method') as access_method
SELECT team_id,
sum(read_rows) as count
sum(read_bytes) as count
FROM clusterAllReplicas(posthog, system.query_log)
WHERE (type = 'QueryFinish'
OR type = 'ExceptionWhileProcessing')
Expand All @@ -333,7 +370,7 @@
JSONExtractString(log_comment, 'query_type') as query_type,
JSONExtractString(log_comment, 'access_method') as access_method
SELECT team_id,
sum(query_duration_ms) as count
sum(read_rows) as count
FROM clusterAllReplicas(posthog, system.query_log)
WHERE (type = 'QueryFinish'
OR type = 'ExceptionWhileProcessing')
Expand Down
Loading

0 comments on commit d302688

Please sign in to comment.