Skip to content

Commit

Permalink
feat: mobile replay in usage take two (#21826)
Browse files Browse the repository at this point in the history
* Revert "revert: "feat: mobile replay in usage" (#21789)"

This reverts commit a8eccd4.

* don't count totals separately
  • Loading branch information
pauldambra authored Apr 25, 2024
1 parent 281dd88 commit a3ab26d
Show file tree
Hide file tree
Showing 3 changed files with 213 additions and 107 deletions.
121 changes: 73 additions & 48 deletions posthog/tasks/test/__snapshots__/test_usage_report.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,22 @@
FROM events
WHERE team_id = 2
AND event='local evaluation usage'
AND timestamp between '2022-01-01 00:00:00' AND '2022-01-10 23:59:59'
AND timestamp between '2022-01-10 00:00:00' AND '2022-01-10 23:59:59'
AND has(['correct'], replaceRegexpAll(JSONExtractRaw(properties, 'token'), '^"|"$', ''))
GROUP BY team
'''
# ---
# 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,
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

SELECT distinct_id as team,
sum(JSONExtractInt(properties, 'count')) as sum
FROM events
WHERE team_id = 2
AND event='local evaluation usage'
AND timestamp between '2022-01-01 00:00:00' AND '2022-01-10 23:59:59'
AND has(['correct'], replaceRegexpAll(JSONExtractRaw(properties, 'token'), '^"|"$', ''))
GROUP BY team
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.12
Expand All @@ -58,7 +54,7 @@
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 @@ -75,7 +71,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 All @@ -92,14 +88,14 @@
JSONExtractString(log_comment, 'query_type') as query_type,
JSONExtractString(log_comment, 'access_method') as access_method
SELECT team_id,
sum(read_bytes) as count
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 = 'personal_api_key'
AND access_method = ''
GROUP BY team_id
'''
# ---
Expand All @@ -109,7 +105,7 @@
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 @@ -126,7 +122,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 All @@ -143,14 +139,14 @@
JSONExtractString(log_comment, 'query_type') as query_type,
JSONExtractString(log_comment, 'access_method') as access_method
SELECT team_id,
sum(read_bytes) as count
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 (['EventsQuery'])
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 = ''
AND access_method = 'personal_api_key'
GROUP BY team_id
'''
# ---
Expand All @@ -160,7 +156,7 @@
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 @@ -177,7 +173,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 All @@ -204,6 +200,23 @@
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.20
'''
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 (['EventsQuery'])
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.21
'''
WITH JSONExtractInt(log_comment, 'team_id') as team_id,
JSONExtractString(log_comment, 'query_type') as query_type,
Expand All @@ -220,7 +233,7 @@
GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.21
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.22
'''
WITH JSONExtractInt(log_comment, 'team_id') as team_id,
JSONExtractString(log_comment, 'query_type') as query_type,
Expand All @@ -237,7 +250,7 @@
GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.22
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.23
'''
WITH JSONExtractInt(log_comment, 'team_id') as team_id,
JSONExtractString(log_comment, 'query_type') as query_type,
Expand All @@ -254,7 +267,7 @@
GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.23
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.24
'''

SELECT team_id,
Expand All @@ -265,7 +278,7 @@
GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.24
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.25
'''

SELECT team_id,
Expand All @@ -276,7 +289,7 @@
GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.25
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.26
'''

SELECT team,
Expand Down Expand Up @@ -329,12 +342,6 @@
SELECT team_id,
count(distinct session_id) as count
FROM session_replay_events
WHERE min_first_timestamp BETWEEN '2022-01-10 00:00:00' AND '2022-01-10 23:59:59'
AND session_id NOT IN
(SELECT DISTINCT session_id
FROM session_replay_events
WHERE min_first_timestamp BETWEEN '2022-01-09 00:00:00' AND '2022-01-10 00:00:00'
GROUP BY session_id)
GROUP BY team_id
'''
# ---
Expand All @@ -343,21 +350,39 @@

SELECT team_id,
count(distinct session_id) as count
FROM session_replay_events
FROM
(SELECT any(team_id) as team_id,
session_id
FROM session_replay_events
WHERE min_first_timestamp BETWEEN '2022-01-10 00:00:00' AND '2022-01-10 23:59:59'
GROUP BY session_id
HAVING ifNull(argMinMerge(snapshot_source), 'web') == 'web')
WHERE session_id NOT IN
(SELECT DISTINCT session_id
FROM session_replay_events
WHERE min_first_timestamp BETWEEN '2022-01-09 00:00:00' AND '2022-01-10 00:00:00'
GROUP BY session_id)
GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.7
'''

SELECT distinct_id as team,
sum(JSONExtractInt(properties, 'count')) as sum
FROM events
WHERE team_id = 2
AND event='decide usage'
AND timestamp between '2022-01-10 00:00:00' AND '2022-01-10 23:59:59'
AND has(['correct'], replaceRegexpAll(JSONExtractRaw(properties, 'token'), '^"|"$', ''))
GROUP BY team
SELECT team_id,
count(distinct session_id) as count
FROM
(SELECT any(team_id) as team_id,
session_id
FROM session_replay_events
WHERE min_first_timestamp BETWEEN '2022-01-10 00:00:00' AND '2022-01-10 23:59:59'
GROUP BY session_id
HAVING ifNull(argMinMerge(snapshot_source), 'web') == 'mobile')
WHERE session_id NOT IN
(SELECT DISTINCT session_id
FROM session_replay_events
WHERE min_first_timestamp BETWEEN '2022-01-09 00:00:00' AND '2022-01-10 00:00:00'
GROUP BY session_id)
GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.8
Expand All @@ -368,7 +393,7 @@
FROM events
WHERE team_id = 2
AND event='decide usage'
AND timestamp between '2022-01-01 00:00:00' AND '2022-01-10 23:59:59'
AND timestamp between '2022-01-10 00:00:00' AND '2022-01-10 23:59:59'
AND has(['correct'], replaceRegexpAll(JSONExtractRaw(properties, 'token'), '^"|"$', ''))
GROUP BY team
'''
Expand All @@ -380,8 +405,8 @@
sum(JSONExtractInt(properties, 'count')) as sum
FROM events
WHERE team_id = 2
AND event='local evaluation usage'
AND timestamp between '2022-01-10 00:00:00' AND '2022-01-10 23:59:59'
AND event='decide usage'
AND timestamp between '2022-01-01 00:00:00' AND '2022-01-10 23:59:59'
AND has(['correct'], replaceRegexpAll(JSONExtractRaw(properties, 'token'), '^"|"$', ''))
GROUP BY team
'''
Expand Down
Loading

0 comments on commit a3ab26d

Please sign in to comment.