Skip to content

Commit

Permalink
feat(usage-report): Add decide usage report (#15956)
Browse files Browse the repository at this point in the history
  • Loading branch information
neilkakkar authored Jun 9, 2023
1 parent 0cb194b commit 9fb1aa7
Show file tree
Hide file tree
Showing 4 changed files with 471 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ jobs:
# Also skip for persons-on-events runs, as we want to ignore snapshots diverging there
if: ${{ github.repository == 'PostHog/posthog' && needs.changes.outputs.backend == 'true' && !matrix.person-on-events }}
with:
add: '["ee", "posthog/clickhouse/test/__snapshots__", "posthog/api/test/__snapshots__", "posthog/test/__snapshots__", "posthog/queries/", "posthog/migrations"]'
add: '["ee", "posthog/clickhouse/test/__snapshots__", "posthog/api/test/__snapshots__", "posthog/test/__snapshots__", "posthog/queries/", "posthog/migrations", "posthog/tasks"]'
message: 'Update query snapshots'
pull: --rebase --autostash # Make sure we're up to date with other segments' updates
default_author: github_actions
Expand Down
298 changes: 298 additions & 0 deletions posthog/tasks/test/__snapshots__/test_usage_report.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,298 @@
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests
'

SELECT team_id,
count(1) as count
FROM events
GROUP BY team_id
'
---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.1
'

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'
GROUP BY team_id
'
---
# 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,
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 = 'personal_api_key'
GROUP BY team_id
'
---
# 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,
JSONExtractString(log_comment, 'access_method') as access_method
SELECT team_id,
sum(read_rows) 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'
GROUP BY team_id
'
---
# 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,
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 = 'personal_api_key'
GROUP BY team_id
'
---
# 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,
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 (['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.15
'
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
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.16
'
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.17
'
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 (['EventsQuery'])
AND query_start_time between '2022-01-10 00:00:00' AND '2022-01-10 23:59:59'
AND access_method = 'personal_api_key'
GROUP BY team_id
'
---
# 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,
JSONExtractString(log_comment, 'access_method') as access_method
SELECT team_id,
sum(read_rows) 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 = 'personal_api_key'
GROUP BY team_id
'
---
# 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,
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 = 'personal_api_key'
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'
GROUP BY team_id
'
---
# 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 session_recording_events
WHERE first_event_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_recording_events
WHERE toDate(first_event_timestamp) = toDate('2022-01-10 00:00:00') - INTERVAL 1 DAY
GROUP BY session_id)
GROUP BY team_id
'
---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.5
'

SELECT team_id,
count(distinct session_id) as count
FROM session_recording_events
GROUP BY team_id
'
---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.6
'

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
'
---
# 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-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.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_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.9
'
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
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
'
---
Loading

0 comments on commit 9fb1aa7

Please sign in to comment.