Skip to content

: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.

fix(cdp): don't quota-limit hog functions that are never billed (#121707)

Jimmy Zhu0ad3d6f3bf56
diff --git a/nodejs/src/cdp/services/hog-function-invocation-pipeline.service.test.ts b/nodejs/src/cdp/services/hog-function-invocation-pipeline.service.test.ts
index 4331e37ee249..7261f3416a25 100644
--- a/nodejs/src/cdp/services/hog-function-invocation-pipeline.service.test.ts
+++ b/nodejs/src/cdp/services/hog-function-invocation-pipeline.service.test.ts
@@ -220,8 +220,11 @@ describe('HogFunctionInvocationPipeline', () => {
expect(result[0].queue).toBe('hogoverflow')
})
- it('drops quota-limited invocations', async () => {
- const fn = makeHogFunction()
+ it.each([
+ ['drops billed destinations', 'destination', 0],
+ ['keeps never-billed internal destinations', 'internal_destination', 1],
+ ] as const)('for a quota-limited team, %s', async (_name, type, expectedCount) => {
+ const fn = makeHogFunction({ type })
const inv = makeInvocation(fn)
jest.mocked(buildHogFunctionInvocations).mockResolvedValue({
invocations: [inv],
@@ -234,11 +237,11 @@ describe('HogFunctionInvocationPipeline', () => {
quotaLimiting.isTeamQuotaLimited.mockResolvedValue(true)
const result = await pipeline.buildInvocations([makeGlobals()], {
- hogTypes: ['destination'],
+ hogTypes: [type],
filterFn: () => true,
})
- expect(result).toEqual([])
+ expect(result).toHaveLength(expectedCount)
})
it('drops masked invocations', async () => {
diff --git a/nodejs/src/cdp/services/hog-function-invocation-pipeline.service.ts b/nodejs/src/cdp/services/hog-function-invocation-pipeline.service.ts
index bbec3b392ddb..4d8ad5dc32c3 100644
--- a/nodejs/src/cdp/services/hog-function-invocation-pipeline.service.ts
+++ b/nodejs/src/cdp/services/hog-function-invocation-pipeline.service.ts
@@ -48,6 +48,11 @@ export interface HogFunctionInvocationPipelineDeps {
deadLetterService?: InvocationFailureSink
}
+// The one rule for billing and the destinations quota, so an unbilled invocation (an alert notification) is never quota-dropped.
+function isBilledHogFunction(hogFunction: HogFunctionType): boolean {
+ return hogFunction.type === 'destination'
+}
+
export interface BuildHogFunctionInvocationsOptions {
hogTypes: HogFunctionTypeType[]
filterFn: (fn: HogFunctionType) => boolean
@@ -185,10 +190,12 @@ export class HogFunctionInvocationPipeline {
logger.error('🔴', 'Error checking rate limit for hog function', { err: e })
}
- const isQuotaLimited = await shouldBlockInvocationDueToQuota(item, {
- quotaLimiting: this.deps.quotaLimiting,
- hogFunctionMonitoringService: this.deps.hogFunctionMonitoringService,
- })
+ const isQuotaLimited =
+ isBilledHogFunction(item.hogFunction) &&
+ (await shouldBlockInvocationDueToQuota(item, {
+ quotaLimiting: this.deps.quotaLimiting,
+ hogFunctionMonitoringService: this.deps.hogFunctionMonitoringService,
+ }))
if (isQuotaLimited) {
return
@@ -260,7 +267,7 @@ export class HogFunctionInvocationPipeline {
})
// Bill once per triggering event, not per destination
- if (item.hogFunction.type === 'destination') {
+ if (isBilledHogFunction(item.hogFunction)) {
const eventUuid = item.state?.globals?.event?.uuid
if (eventUuid && !billedEventUuids.has(eventUuid)) {
billedEventUuids.add(eventUuid)