:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(workflows): bill push sends as destinations (#101716)
Daniel Marchukb9000703a9bf
diff --git a/nodejs/src/cdp/services/hogflows/hogflow-quota-limiting.test.ts b/nodejs/src/cdp/services/hogflows/hogflow-quota-limiting.test.tsindex af7364ca6af9..91295126201e 100644--- a/nodejs/src/cdp/services/hogflows/hogflow-quota-limiting.test.ts+++ b/nodejs/src/cdp/services/hogflows/hogflow-quota-limiting.test.ts@@ -43,9 +43,8 @@ describe('HogFlow Quota Limiting', () => {const result = await checkHogFlowQuotaLimits(hogFlow, teamId, mockQuotaLimiting)expect(result.isLimited).toBe(false)- expect(mockQuotaLimiting.isTeamQuotaLimited).toHaveBeenCalledTimes(3)+ expect(mockQuotaLimiting.isTeamQuotaLimited).toHaveBeenCalledTimes(2)expect(mockQuotaLimiting.isTeamQuotaLimited).toHaveBeenCalledWith(teamId, 'workflow_emails')- expect(mockQuotaLimiting.isTeamQuotaLimited).toHaveBeenCalledWith(teamId, 'workflow_push')expect(mockQuotaLimiting.isTeamQuotaLimited).toHaveBeenCalledWith(teamId,'workflow_destinations_dispatched'@@ -68,9 +67,9 @@ describe('HogFlow Quota Limiting', () => {expect(result.isLimited).toBe(true)})- it('should limit workflow with push action when team has push quota limit', async () => {+ it('should limit workflow with push action when team has destination quota limit', async () => {mockQuotaLimiting.isTeamQuotaLimited.mockImplementation((_teamId, resource) => {- return Promise.resolve(resource === 'workflow_push')+ return Promise.resolve(resource === 'workflow_destinations_dispatched')})const hogFlow: HogFlow = {@@ -157,9 +156,8 @@ describe('HogFlow Quota Limiting', () => {const result = await checkHogFlowQuotaLimits(hogFlow, teamId, mockQuotaLimiting)expect(result.isLimited).toBe(false)- expect(mockQuotaLimiting.isTeamQuotaLimited).toHaveBeenCalledTimes(3)+ expect(mockQuotaLimiting.isTeamQuotaLimited).toHaveBeenCalledTimes(2)expect(mockQuotaLimiting.isTeamQuotaLimited).toHaveBeenCalledWith(teamId, 'workflow_emails')- expect(mockQuotaLimiting.isTeamQuotaLimited).toHaveBeenCalledWith(teamId, 'workflow_push')expect(mockQuotaLimiting.isTeamQuotaLimited).toHaveBeenCalledWith(teamId,'workflow_destinations_dispatched'diff --git a/nodejs/src/cdp/services/hogflows/hogflow-quota-limiting.ts b/nodejs/src/cdp/services/hogflows/hogflow-quota-limiting.tsindex 54fcedc99c5d..76f83523e74f 100644--- a/nodejs/src/cdp/services/hogflows/hogflow-quota-limiting.ts+++ b/nodejs/src/cdp/services/hogflows/hogflow-quota-limiting.ts@@ -34,9 +34,8 @@ export async function checkHogFlowQuotaLimits(}// Check which quotas the team is limited on- const [isEmailQuotaLimited, isPushQuotaLimited, isDestinationQuotaLimited] = await Promise.all([+ const [isEmailQuotaLimited, isDestinationQuotaLimited] = await Promise.all([quotaLimiting.isTeamQuotaLimited(teamId, 'workflow_emails'),- quotaLimiting.isTeamQuotaLimited(teamId, 'workflow_push'),quotaLimiting.isTeamQuotaLimited(teamId, 'workflow_destinations_dispatched'),])@@ -45,11 +44,11 @@ export async function checkHogFlowQuotaLimits(return { isLimited: true }}- if (isPushQuotaLimited && billableActionTypes.includes('function_push')) {- return { isLimited: true }- }-- if (isDestinationQuotaLimited && billableActionTypes.includes('function')) {+ // Push sends bill as destinations for now, so they fall under the destination quota+ if (+ isDestinationQuotaLimited &&+ (billableActionTypes.includes('function') || billableActionTypes.includes('function_push'))+ ) {return { isLimited: true }}diff --git a/posthog/tasks/test/__snapshots__/test_usage_report.ambr b/posthog/tasks/test/__snapshots__/test_usage_report.ambrindex 74e7f843bd01..d400484dc3a5 100644--- a/posthog/tasks/test/__snapshots__/test_usage_report.ambr+++ b/posthog/tasks/test/__snapshots__/test_usage_report.ambr@@ -1729,7 +1729,8 @@FROM app_metrics2WHERE app_source='hog_flow'AND metric_name IN ('billable_invocation')- AND metric_kind IN ('fetch')+ AND metric_kind IN ('fetch',+ 'push')AND timestamp >= '2022-01-10 00:00:00'AND timestamp < '2022-01-10 23:59:59'GROUP BY team_iddiff --git a/posthog/tasks/test/test_usage_report.py b/posthog/tasks/test/test_usage_report.pyindex f47c1a73f70e..e45d893d12fc 100644--- a/posthog/tasks/test/test_usage_report.py+++ b/posthog/tasks/test/test_usage_report.py@@ -3423,23 +3423,25 @@ class TestHogFunctionUsageReports(ClickhouseDestroyTablesMixin, TestCase, Clickhassert org_1_report["organization_name"] == "Org 1"- # Test org-level workflow metrics (sum of both teams)+ # Test org-level workflow metrics (sum of both teams).+ # Push bills as a destination for now, so it counts toward workflow_billable_invocations+ # while still reporting separately under workflow_push_sent.assert org_1_report["workflow_emails_sent_in_period"] == 25 # 10 + 15assert org_1_report["workflow_push_sent_in_period"] == 12 # 5 + 7assert org_1_report["workflow_sms_sent_in_period"] == 5 # 3 + 2- assert org_1_report["workflow_billable_invocations_in_period"] == 20 # 8 + 12+ assert org_1_report["workflow_billable_invocations_in_period"] == 32 # fetch 8 + 12, push 5 + 7# Test team 1 workflow metricsassert org_1_report["teams"]["3"]["workflow_emails_sent_in_period"] == 10assert org_1_report["teams"]["3"]["workflow_push_sent_in_period"] == 5assert org_1_report["teams"]["3"]["workflow_sms_sent_in_period"] == 3- assert org_1_report["teams"]["3"]["workflow_billable_invocations_in_period"] == 8+ assert org_1_report["teams"]["3"]["workflow_billable_invocations_in_period"] == 13 # fetch 8, push 5# Test team 2 workflow metricsassert org_1_report["teams"]["4"]["workflow_emails_sent_in_period"] == 15assert org_1_report["teams"]["4"]["workflow_push_sent_in_period"] == 7assert org_1_report["teams"]["4"]["workflow_sms_sent_in_period"] == 2- assert org_1_report["teams"]["4"]["workflow_billable_invocations_in_period"] == 12+ assert org_1_report["teams"]["4"]["workflow_billable_invocations_in_period"] == 19 # fetch 12, push 7@parameterized.expand([diff --git a/posthog/tasks/usage_report.py b/posthog/tasks/usage_report.pyindex d82dfda39c63..8457db7d4954 100644--- a/posthog/tasks/usage_report.py+++ b/posthog/tasks/usage_report.py@@ -2470,7 +2470,7 @@ def get_teams_with_workflow_billable_invocations_in_period("""SELECT team_id, SUM(count) as countFROM app_metrics2- WHERE app_source='hog_flow' AND metric_name IN ('billable_invocation') AND metric_kind IN ('fetch') AND timestamp >= %(begin)s AND timestamp < %(end)s+ WHERE app_source='hog_flow' AND metric_name IN ('billable_invocation') AND metric_kind IN ('fetch', 'push') AND timestamp >= %(begin)s AND timestamp < %(end)sGROUP BY team_id""",{"begin": begin, "end": end},