Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: start collecting enhanced_persons metrics in usage reports #21246

Merged
merged 2 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 60 additions & 46 deletions posthog/tasks/test/__snapshots__/test_usage_report.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.10
'''

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.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
Expand All @@ -39,7 +52,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 @@ -56,7 +69,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 @@ -73,7 +86,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 @@ -90,7 +103,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 @@ -107,7 +120,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 @@ -124,7 +137,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 @@ -141,7 +154,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 @@ -158,7 +171,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 @@ -175,7 +188,21 @@
GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.19
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.2
'''

SELECT team_id,
count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
FROM events
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')
GROUP BY team_id
'''
# ---
# 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,
Expand All @@ -192,21 +219,7 @@
GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.2
'''

SELECT team_id,
count(1) as count
FROM events
WHERE timestamp between '2022-01-01 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')
GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.20
# 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 @@ -223,7 +236,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 @@ -240,7 +253,7 @@
GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.22
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.23
'''

SELECT team_id,
Expand All @@ -251,7 +264,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 @@ -262,7 +275,7 @@
GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.24
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.25
'''

SELECT team,
Expand All @@ -283,6 +296,20 @@
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.3
'''

SELECT team_id,
count(1) as count
FROM events
WHERE timestamp between '2022-01-01 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')
GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.4
'''

SELECT team_id,
count(1) as count
FROM events
Expand All @@ -295,7 +322,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 @@ -310,7 +337,7 @@
GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.5
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.6
'''

SELECT team_id,
Expand All @@ -319,7 +346,7 @@
GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.6
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.7
'''

SELECT distinct_id as team,
Expand All @@ -332,7 +359,7 @@
GROUP BY team
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.7
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.8
'''

SELECT distinct_id as team,
Expand All @@ -345,19 +372,6 @@
GROUP BY team
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.8
'''

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-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.9
'''

Expand All @@ -366,7 +380,7 @@
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
'''
Expand Down
6 changes: 6 additions & 0 deletions posthog/tasks/test/test_usage_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ def _test_usage_report(self) -> List[dict]:
"instance_tag": "none",
"event_count_lifetime": 55,
"event_count_in_period": 22,
# TODO: enhanced_persons: modify this test so that there are fewer of these events than the base
"enhanced_persons_event_count_in_period": 22,
"event_count_in_month": 42,
"event_count_with_groups_in_period": 2,
"recording_count_in_period": 5,
Expand Down Expand Up @@ -411,6 +413,7 @@ def _test_usage_report(self) -> List[dict]:
str(self.org_1_team_1.id): {
"event_count_lifetime": 44,
"event_count_in_period": 12,
"enhanced_persons_event_count_in_period": 12,
"event_count_in_month": 32,
"event_count_with_groups_in_period": 2,
"recording_count_in_period": 0,
Expand Down Expand Up @@ -447,6 +450,7 @@ def _test_usage_report(self) -> List[dict]:
str(self.org_1_team_2.id): {
"event_count_lifetime": 11,
"event_count_in_period": 10,
"enhanced_persons_event_count_in_period": 10,
"event_count_in_month": 10,
"event_count_with_groups_in_period": 0,
"recording_count_in_period": 5,
Expand Down Expand Up @@ -506,6 +510,7 @@ def _test_usage_report(self) -> List[dict]:
"instance_tag": "none",
"event_count_lifetime": 11,
"event_count_in_period": 10,
"enhanced_persons_event_count_in_period": 10,
"event_count_in_month": 10,
"event_count_with_groups_in_period": 0,
"recording_count_in_period": 0,
Expand Down Expand Up @@ -548,6 +553,7 @@ def _test_usage_report(self) -> List[dict]:
str(self.org_2_team_3.id): {
"event_count_lifetime": 11,
"event_count_in_period": 10,
"enhanced_persons_event_count_in_period": 10,
"event_count_in_month": 10,
"event_count_with_groups_in_period": 0,
"recording_count_in_period": 0,
Expand Down
Loading
Loading