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.

feat(cdp): match cohort joins and leaves in workflow goals and waits (#122553)

Harley Alexanderdde02077529a
diff --git a/nodejs/src/cdp/consumers/cdp-cohort-membership-trigger.consumer.ts b/nodejs/src/cdp/consumers/cdp-cohort-membership-trigger.consumer.ts
index 1a93587dd9ed..a52e697fe750 100644
--- a/nodejs/src/cdp/consumers/cdp-cohort-membership-trigger.consumer.ts
+++ b/nodejs/src/cdp/consumers/cdp-cohort-membership-trigger.consumer.ts
@@ -9,7 +9,7 @@ import { parseJSON } from '~/common/utils/json-parse'
import { logger } from '~/common/utils/logger'
import { captureException } from '~/common/utils/posthog'
-import { HealthCheckResult, PluginsServerConfig } from '../../types'
+import { HealthCheckResult, PluginsServerConfig, Team } from '../../types'
import { HogFlow } from '../schema/hogflow'
import { PRODUCER_VERSION_FORMAT } from '../services/cohort-membership/sweeper.service'
import {
@@ -40,6 +40,35 @@ export function isMatchingCohortTrigger(flow: HogFlow, globals: HogFunctionInvoc
)
}
+/**
+ * A join or a leave as a `$cohort_membership_changed` event for the person. The change carries no
+ * distinct_id and no person properties, so the event has neither.
+ */
+export function convertCohortMembershipChangeToGlobals(
+ change: CohortMembershipChange,
+ team: Team,
+ siteUrl: string
+): HogFunctionInvocationGlobals {
+ const globals = convertBatchHogFlowRequestToHogFunctionInvocationGlobals({
+ team,
+ personId: change.person_id,
+ siteUrl,
+ })
+ globals.event = {
+ ...globals.event,
+ event: COHORT_MEMBERSHIP_CHANGED_EVENT,
+ properties: {
+ cohort_id: change.cohort_id,
+ status: change.status,
+ // An off-format stamp can't be bound into the `::timestamp` comparison.
+ ...(change.last_updated && PRODUCER_VERSION_FORMAT.test(change.last_updated)
+ ? { [COHORT_MEMBERSHIP_VERSION_PROPERTY]: change.last_updated }
+ : {}),
+ },
+ }
+ return globals
+}
+
/**
* Starts workflow runs from realtime cohort membership changes.
*
@@ -198,24 +227,7 @@ export class CdpCohortMembershipTriggerConsumer extends CdpConsumerBase {
return
}
- const globals = convertBatchHogFlowRequestToHogFunctionInvocationGlobals({
- team,
- personId: change.person_id,
- siteUrl: this.config.SITE_URL,
- })
- globals.event = {
- ...globals.event,
- event: COHORT_MEMBERSHIP_CHANGED_EVENT,
- properties: {
- cohort_id: change.cohort_id,
- status: change.status,
- // An off-format stamp can't be bound into the `::timestamp` comparison.
- ...(change.last_updated && PRODUCER_VERSION_FORMAT.test(change.last_updated)
- ? { [COHORT_MEMBERSHIP_VERSION_PROPERTY]: change.last_updated }
- : {}),
- },
- }
- events.push(globals)
+ events.push(convertCohortMembershipChangeToGlobals(change, team, this.config.SITE_URL))
})
)
diff --git a/nodejs/src/cdp/consumers/cdp-hogflow-subscription-matcher.consumer.test.ts b/nodejs/src/cdp/consumers/cdp-hogflow-subscription-matcher.consumer.test.ts
index 99c5aee4baf4..6eec24d138f5 100644
--- a/nodejs/src/cdp/consumers/cdp-hogflow-subscription-matcher.consumer.test.ts
+++ b/nodejs/src/cdp/consumers/cdp-hogflow-subscription-matcher.consumer.test.ts
@@ -227,8 +227,8 @@ class MatcherUnderTest extends CdpHogflowSubscriptionMatcherConsumer {
)
}
- public async runWake(invocationGlobals: HogFunctionInvocationGlobals[]): Promise<void> {
- await (this as any).wakeMatchingWorkflows(invocationGlobals)
+ public async runWake(invocationGlobals: HogFunctionInvocationGlobals[], source?: string): Promise<void> {
+ await (this as any).wakeMatchingWorkflows(invocationGlobals, source)
}
// start() arms the watcher sweep and team-refresh intervals, and only stop() clears them. This
@@ -288,6 +288,35 @@ const rawInternalEvent = (overrides: { team_id?: number; event?: Record<string,
),
})
+const MEMBER_PERSON_ID = '0190b0c4-0000-7000-8000-000000000001'
+
+const rawCohortMembershipChange = (overrides: Record<string, any> = {}): any => ({
+ value: Buffer.from(
+ JSON.stringify({
+ team_id: 1,
+ cohort_id: 42,
+ person_id: MEMBER_PERSON_ID,
+ status: 'entered',
+ last_updated: '2024-01-01 00:00:00.000000',
+ ...overrides,
+ })
+ ),
+})
+
+const cohortMembershipEvent = (): HogFunctionInvocationGlobals =>
+ makeGlobals({
+ event: {
+ ...makeGlobals({}).event,
+ event: '$cohort_membership_changed',
+ distinct_id: '',
+ properties: { cohort_id: 42, status: 'entered' },
+ },
+ person: { id: 'person-uuid-1', properties: {}, name: '', url: '' },
+ })
+
+// person.properties.email == null, which an empty person satisfies.
+const personEmailIsNotSetBytecode = ['_H', 1, 31, 32, 'email', 32, 'properties', 32, 'person', 1, 3, 11]
+
const invalidTeamIds = [undefined, null, 'abc', 1.5, 3_000_000_000]
describe('CdpHogflowSubscriptionMatcherConsumer', () => {
@@ -1204,6 +1233,37 @@ describe('CdpHogflowSubscriptionMatcherConsumer', () => {
expect(getTeam).toHaveBeenCalledTimes(1)
expect(getTeam).toHaveBeenCalledWith(1)
})
+
+ it('drops a captured $cohort_membership_changed event, so a client cannot fake a cohort join', async () => {
+ const result = await (matcher as any)._parseKafkaBatch([
+ rawEvent({ event: '$cohort_membership_changed' }),
+ rawEvent({}),
+ ])
+
+ expect(result.map((g: HogFunctionInvocationGlobals) => g.event.event)).toEqual(['wuc_subscribed'])
+ })
+ })
+
+ describe('_parseCohortMembershipBatch', () => {
+ beforeEach(() => {
+ matcher.setHogFlows({ 'flow-1': makeHogFlow({ id: 'flow-1', team_id: 1 }) })
+ })
+
+ it('maps a join to a $cohort_membership_changed event keyed on person_id, and skips backfills', async () => {
+ const result = await (matcher as any)._parseCohortMembershipBatch([
+ rawCohortMembershipChange({ origin: 'seed' }),
+ rawCohortMembershipChange(),
+ ])
+
+ expect(result).toHaveLength(1)
+ const globals = result[0] as HogFunctionInvocationGlobals
+ expect(globals.event).toMatchObject({
+ event: '$cohort_membership_changed',
+ distinct_id: '',
+ properties: { cohort_id: 42, status: 'entered' },
+ })
+ expect(globals.person?.id).toBe(MEMBER_PERSON_ID)
+ })
})
describe('_parsePersonBatch', () => {
@@ -1323,13 +1383,22 @@ describe('CdpHogflowSubscriptionMatcherConsumer', () => {
// The schema already rejects a missing, null or string team_id.
...invalidTeamIds
.filter((teamId) => typeof teamId === 'number')
- .map((teamId) => ({
- name: `an internal event with team_id ${teamId}`,
- parse: '_parseInternalEventsBatch',
- bad: rawInternalEvent({ team_id: teamId }),
- good: rawInternalEvent(),
- expectedInvalidTeamIdSkips: 1,
- })),
+ .flatMap((teamId) => [
+ {
+ name: `an internal event with team_id ${teamId}`,
+ parse: '_parseInternalEventsBatch',
+ bad: rawInternalEvent({ team_id: teamId }),
+ good: rawInternalEvent(),
+ expectedInvalidTeamIdSkips: 1,
+ },
+ {
+ name: `a cohort membership change with team_id ${teamId}`,
+ parse: '_parseCohortMembershipBatch',
+ bad: rawCohortMembershipChange({ team_id: teamId }),
+ good: rawCohortMembershipChange(),
+ expectedInvalidTeamIdSkips: 1,
+ },
+ ]),
{
name: 'an event that is not JSON',
parse: '_parseKafkaBatch',
@@ -1374,6 +1443,11 @@ describe('CdpHogflowSubscriptionMatcherConsumer', () => {
{ stream: 'realtime-only events', consumer: 'realtimeOnlyEventsKafkaConsumer', message: rawEvent({}) },
{ stream: 'person', consumer: 'personKafkaConsumer', message: rawPerson({}) },
{ stream: 'internal events', consumer: 'internalEventsKafkaConsumer', message: rawInternalEvent() },
+ {
+ stream: 'cohort membership',
+ consumer: 'cohortMembershipKafkaConsumer',
+ message: rawCohortMembershipChange(),
+ },
]
const lookupFailures = [
{
@@ -1768,6 +1842,41 @@ describe('CdpHogflowSubscriptionMatcherConsumer', () => {
expect(matcher.queueConversionEventMock).not.toHaveBeenCalled()
})
+ it('counts only event goals from a cohort membership change, and attributes them to the run', async () => {
+ // A membership change has no person properties, so a negative person filter such as "email is
+ // not set" would match the empty person, in a property goal or inside an event goal.
+ matcher.watcherRows = [
+ watcher({
+ person_id: 'person-uuid-1',
+ goal: { events: [eventBytecode('$cohort_membership_changed')] },
+ }),
+ watcher({
+ id: 'watcher-2',
+ run_id: 'run-2',
+ person_id: 'person-uuid-1',
+ goal: { properties: ['_H', 1, 29] },
+ }),
+ watcher({
+ id: 'watcher-3',
+ run_id: 'run-3',
+ person_id: 'person-uuid-1',
+ goal: { events: [personEmailIsNotSetBytecode] },
+ }),
+ ]
+
+ await matcher.runWake([cohortMembershipEvent()], 'cohort_membership')
+
+ const claim = matcher.calls.find((c) => c.sql.startsWith('DELETE FROM conversion_watchers'))
+ expect(claim?.params).toEqual([['watcher-1']])
+ // The change has no distinct_id, so the conversion event takes the run's.
+ expect(matcher.queueConversionEventMock).toHaveBeenCalledWith(
+ expect.objectContaining({
+ distinct_id: 'user-1',
+ properties: expect.objectContaining({ $workflow_run_id: 'run-1' }),
+ })
+ )
+ })
+
it('does not count a watcher whose goal does not match', async () => {
matcher.watcherRows = [watcher()]
@@ -1812,6 +1921,7 @@ describe('CdpHogflowSubscriptionMatcherConsumer', () => {
name: string
config: Record<string, any>
event: () => HogFunctionInvocationGlobals
+ source?: string
woken: boolean
}
@@ -1914,6 +2024,54 @@ describe('CdpHogflowSubscriptionMatcherConsumer', () => {
event: unrelatedEvent,
woken: false,
},
+ // ---- cohort membership changes ----
+ {
+ name: 'cohort join entry + cohort membership change',
+ config: {
+ events: [
+ {
+ filters: {
+ bytecode: eventBytecode('$cohort_membership_changed'),
+ events: [{ id: '$cohort_membership_changed' }],
+ },
+ },
+ ],
+ },
+ event: cohortMembershipEvent,
+ source: 'cohort_membership',
+ woken: true,
+ },
+ {
+ // The change has no person properties, so a negative person filter would match it.
+ name: 'person property condition + cohort membership change',
+ config: {
+ condition: {
+ filters: {
+ bytecode: ALWAYS_TRUE,
+ properties: [{ key: 'email', type: 'person', operator: 'is_not_set' }],
+ },
+ },
+ },
+ event: cohortMembershipEvent,
+ source: 'cohort_membership',
+ woken: false,
+ },
+ {
+ name: 'event entry that reads the person + cohort membership change',
+ config: {
+ events: [
+ {
+ filters: {
+ bytecode: personEmailIsNotSetBytecode,
+ events: [{ id: '$cohort_membership_changed' }],
+ },
+ },
+ ],
+ },
+ event: cohortMembershipEvent,
+ source: 'cohort_membership',
+ woken: false,
+ },
]
// Follow-live contract: a parked job carries no copy of its wait condition - the matcher
@@ -1974,7 +2132,7 @@ describe('CdpHogflowSubscriptionMatcherConsumer', () => {
expect(matcher.calls.find((c) => c.sql.startsWith('UPDATE cyclotron_jobs'))).toBeDefined()
})
- it.each(cases)('$name -> woken: $woken', async ({ config, event, woken }) => {
+ it.each(cases)('$name -> woken: $woken', async ({ config, event, source, woken }) => {
matcher.findRows = [
{
id: 'job-1',
@@ -1982,7 +2140,7 @@ describe('CdpHogflowSubscriptionMatcherConsumer', () => {
function_id: 'flow-1',
action_id: 'wait_node',
distinct_id: 'user-1',
- person_id: null,
+ person_id: 'person-uuid-1',
},
]
// Wire the wake path so that IF the job is woken, an UPDATE is produced.
@@ -2009,7 +2167,7 @@ describe('CdpHogflowSubscriptionMatcherConsumer', () => {
} as any),
})
- await matcher.runWake([event()])
+ await matcher.runWake([event()], source)
const update = matcher.calls.find((c) => c.sql.startsWith('UPDATE cyclotron_jobs'))
if (woken) {
diff --git a/nodejs/src/cdp/consumers/cdp-hogflow-subscription-matcher.consumer.ts b/nodejs/src/cdp/consumers/cdp-hogflow-subscription-matcher.consumer.ts
index 7316a8d90f95..132322ee61df 100644
--- a/nodejs/src/cdp/consumers/cdp-hogflow-subscription-matcher.consumer.ts
+++ b/nodejs/src/cdp/consumers/cdp-hogflow-subscription-matcher.consumer.ts
@@ -12,6 +12,7 @@ import {
import { parseWorkflowStepDispatchKey } from '~/cdp/utils/workflow-step-dispatch-key'
import {
KAFKA_CDP_INTERNAL_EVENTS,
+ KAFKA_COHORT_MEMBERSHIP_CHANGED,
KAFKA_EVENTS_JSON,
KAFKA_PERSON,
KAFKA_PERSON_DISTINCT_ID,
@@ -33,6 +34,7 @@ import {
Team,
} from '../../types'
import { CdpInternalEventSchema } from '../schema'
+import { COHORT_MEMBERSHIP_CHANGED_EVENT } from '../services/cohorts/cohort-membership-repository'
import {
hasEventOrActionTarget,
matchesWaitUntilCondition,
@@ -46,6 +48,8 @@ import {
} from '../utils'
import { convertToHogFunctionFilterGlobal } from '../utils/hog-function-filtering'
import { CdpConsumerBase, CdpConsumerBaseDeps } from './cdp-base.consumer'
+import { convertCohortMembershipChangeToGlobals } from './cdp-cohort-membership-trigger.consumer'
+import { CohortMembershipChangeSchema } from './cdp-cohort-membership.consumer'
import { ParseBatchOptions, parseBatch, skipIfMalformed } from './message-parsing'
// A waker only needs signals that arrive after a job parks, never history. auto.offset.reset=latest
@@ -136,11 +140,11 @@ const histogramHogflowMatcherFindParkedJobs = new Histogram({
// Which Kafka stream a batch came from. Labels the find_parked_jobs metric so the person and
// internal-event query load is distinguishable from the events firehose on the shared cyclotron DB.
-type WakeSource = 'events' | 'person' | 'internal_events'
+type WakeSource = 'events' | 'person' | 'internal_events' | 'cohort_membership'
export const counterHogflowMatcherEventSkipped = new Counter({
name: 'cdp_hogflow_matcher_event_skipped',
- help: 'An incoming event was dropped before matching: no identifiers (distinct_id or person_id), an invalid team id, or unknown team.',
+ help: 'An incoming event was dropped before matching: no identifiers (distinct_id or person_id), an invalid team id, unknown team, a backfilled cohort membership change, or a captured event that uses the reserved cohort membership event name.',
labelNames: ['reason'],
})
@@ -212,6 +216,9 @@ export class CdpHogflowSubscriptionMatcherConsumer<
// realtime_only_events_json carries the $feature_flag_called events that ingestion stops writing to
// clickhouse_events_json for a FLAG_EVALUATIONS_ONLY organization.
private realtimeOnlyEventsKafkaConsumer?: KafkaConsumerInterface
+ // cohort_membership_changed carries realtime cohort joins and leaves. Each one becomes a
+ // `$cohort_membership_changed` event, so event waits and event conversion goals can match it.
+ private cohortMembershipKafkaConsumer: KafkaConsumerInterface
private cyclotronPool: Pool
private watcherTeamsRefreshTimer: NodeJS.Timeout | null = null
// Teams with at least one unexpired watcher. Empty until the first refresh, which start() awaits
@@ -253,6 +260,13 @@ export class CdpHogflowSubscriptionMatcherConsumer<
},
startAtLatest
)
+ this.cohortMembershipKafkaConsumer = createKafkaConsumer(
+ {
+ groupId: 'cdp-hogflow-subscription-matcher-cohort-membership-consumer',
+ topic: KAFKA_COHORT_MEMBERSHIP_CHANGED,
+ },
+ startAtLatest
+ )
if (config.CDP_HOGFLOW_SUBSCRIPTION_MATCHER_REALTIME_ONLY_EVENTS_TOPIC) {
this.realtimeOnlyEventsKafkaConsumer = createKafkaConsumer(
{
@@ -325,10 +339,15 @@ export class CdpHogflowSubscriptionMatcherConsumer<
return fg
}
+ // A cohort membership change carries no person properties. A filter that reads the person would see
+ // an empty person, so a negative filter such as "is not set" would match. Such a change is judged
+ // only by event entries that do not read the person.
+ const eventsOnly = source === 'cohort_membership'
+
// Claimed before the parked-job work and independently of it: a watcher's run may have
// finished long ago, so gating this on the flow still having something parked would put back
// exactly the blind spot watchers exist to remove.
- const conversionsCounted = await this.claimConversionWatchers(indexed, filterGlobalsFor)
+ const conversionsCounted = await this.claimConversionWatchers(indexed, filterGlobalsFor, eventsOnly)
counterHogflowMatcherConversionsCounted.inc(conversionsCounted)
// Build the set of actionable flows from the in-memory hogflow cache (same pattern as
@@ -374,9 +393,22 @@ export class CdpHogflowSubscriptionMatcherConsumer<
continue
}
- const action = candidate.actionId
+ const parkedOn = candidate.actionId
? hogflow.actions.find((a: HogFlowAction) => a.id === candidate.actionId)
: undefined
+ const action =
+ eventsOnly && parkedOn?.type === 'wait_until_condition'
+ ? {
+ ...parkedOn,
+ config: {
+ ...parkedOn.config,
+ condition: { filters: null },
+ events: parkedOn.config.events?.filter(
+ (eventConfig) => !readsPerson(eventConfig.filters?.bytecode)
+ ),
+ },
+ }
+ : parkedOn
// Any single matching event is enough. Stop early once both flags are set.
let stepMatched = false
@@ -402,7 +434,7 @@ export class CdpHogflowSubscriptionMatcherConsumer<
stepMatchedEventTimestamp = globals.event.timestamp
}
}
- if (!conversionMatched && (await this.evaluateConversionEvents(hogflow, filterGlobals))) {
+ if (!conversionMatched && (await this.evaluateConversionEvents(hogflow, filterGlobals, eventsOnly))) {
conversionMatched = true
// Remember who converted (and via which event) so we can emit $workflows_conversion.
conversionDistinctId = globals.event.distinct_id
@@ -450,13 +482,20 @@ export class CdpHogflowSubscriptionMatcherConsumer<
})
}
- private async evaluateConversionEvents(hogflow: HogFlow, filterGlobals: FilterGlobals): Promise<boolean> {
+ private async evaluateConversionEvents(
+ hogflow: HogFlow,
+ filterGlobals: FilterGlobals,
+ eventsOnly: boolean
+ ): Promise<boolean> {
const conversionEvents = hogflow.conversion?.events ?? []
const context = { hogFlowId: hogflow.id }
for (const eventConfig of conversionEvents) {
if (!hasEventOrActionTarget(eventConfig)) {
continue
}
+ if (eventsOnly && readsPerson(eventConfig.filters?.bytecode)) {
+ continue
+ }
if (await runFilterBytecode(eventConfig.filters?.bytecode, filterGlobals, context)) {
return true
}
@@ -615,7 +654,8 @@ export class CdpHogflowSubscriptionMatcherConsumer<
*/
private async claimConversionWatchers(
indexed: IndexedBatch,
- filterGlobalsFor: (globals: HogFunctionInvocationGlobals) => FilterGlobals
+ filterGlobalsFor: (globals: HogFunctionInvocationGlobals) => FilterGlobals,
+ eventsOnly: boolean
): Promise<number> {
const { distinctTeamIds, distinctIds, personTeamIds, personIds, byDistinctId, byPersonId } = indexed
@@ -661,8 +701,11 @@ export class CdpHogflowSubscriptionMatcherConsumer<
byDistinctId,
byPersonId
)
+ const goal: PinnedConversionGoal = eventsOnly
+ ? { events: row.goal.events?.filter((bytecode: unknown) => !readsPerson(bytecode)) }
+ : row.goal
for (const globals of candidateGlobals) {
- const conversionType = await matchesPinnedGoal(row.goal, filterGlobalsFor(globals), row.function_id)
+ const conversionType = await matchesPinnedGoal(goal, filterGlobalsFor(globals), row.function_id)
if (conversionType) {
converted.push({
row,
@@ -777,6 +820,12 @@ export class CdpHogflowSubscriptionMatcherConsumer<
counterHogflowMatcherEventSkipped.labels({ reason: 'no_identifiers' }).inc()
return null
}
+ // Only the cohort membership topic says who joined or left a cohort. Anyone with the
+ // project token can capture an event with this name, and it would count as a conversion.
+ if (clickHouseEvent.event === COHORT_MEMBERSHIP_CHANGED_EVENT) {
+ counterHogflowMatcherEventSkipped.labels({ reason: 'reserved_event_name' }).inc()
+ return null
+ }
return {
teamId: clickHouseEvent.team_id,
toGlobals: (team) => convertToHogFunctionInvocationGlobals(clickHouseEvent, team, this.config.SITE_URL),
@@ -784,6 +833,23 @@ export class CdpHogflowSubscriptionMatcherConsumer<
})
}
+ @instrumented('cdpHogflowSubscriptionMatcher.parseCohortMembershipMessages')
+ public async _parseCohortMembershipBatch(messages: Message[]): Promise<HogFunctionInvocationGlobals[]> {
+ return await this.parseMatcherBatch(messages, 'Error parsing cohort membership change', (message) => {
+ const change = CohortMembershipChangeSchema.parse(parseJSON(message.value!.toString()))
+ // Seed and reconcile changes restate membership the person already had. They are not a join
+ // or a leave, so they must not satisfy a wait or a conversion goal.
+ if (change.origin) {
+ counterHogflowMatcherEventSkipped.labels({ reason: 'cohort_membership_backfill' }).inc()
+ return null
+ }
+ return {
+ teamId: change.team_id,
+ toGlobals: (team) => convertCohortMembershipChangeToGlobals(change, team, this.config.SITE_URL),
+ }
+ })
+ }
+
@instrumented('cdpHogflowSubscriptionMatcher.parsePersonMessages')
public async _parsePersonBatch(messages: Message[]): Promise<HogFunctionInvocationGlobals[]> {
return await this.parseMatcherBatch(messages, 'Error parsing person message', (message) => {
@@ -1180,6 +1246,14 @@ export class CdpHogflowSubscriptionMatcherConsumer<
this.realtimeOnlyEventsKafkaConsumer?.connect(
this.eventsBatchHandler('cdpHogflowSubscriptionMatcher.handleRealtimeOnlyEventsBatch')
),
+ this.cohortMembershipKafkaConsumer.connect(async (messages) => {
+ return await instrumentFn('cdpHogflowSubscriptionMatcher.handleCohortMembershipBatch', async () => ({
+ backgroundTask: this.processBatch(
+ await this._parseCohortMembershipBatch(messages),
+ 'cohort_membership'
+ ),
+ }))
+ }),
])
}
@@ -1203,6 +1277,7 @@ export class CdpHogflowSubscriptionMatcherConsumer<
this.internalEventsKafkaConsumer.disconnect(),
this.personDistinctIdKafkaConsumer.disconnect(),
this.realtimeOnlyEventsKafkaConsumer?.disconnect(),
+ this.cohortMembershipKafkaConsumer.disconnect(),
])
await this.cyclotronPool.end()
await super.stop()
@@ -1217,6 +1292,7 @@ export class CdpHogflowSubscriptionMatcherConsumer<
this.internalEventsKafkaConsumer.isHealthy(),
this.personDistinctIdKafkaConsumer.isHealthy(),
...(this.realtimeOnlyEventsKafkaConsumer ? [this.realtimeOnlyEventsKafkaConsumer.isHealthy()] : []),
+ this.cohortMembershipKafkaConsumer.isHealthy(),
]
return results.find((r) => r.status !== 'ok') ?? results[0]
}
@@ -1296,6 +1372,12 @@ function hasWaitUntilOrConversion(hogflow: HogFlow): boolean {
return Array.isArray(conversionEvents) && conversionEvents.length > 0
}
+// Compiled filters read `person.properties.<key>` by pushing the string 'person' as the root of the field
+// chain. A literal 'person' value in a filter also matches, which only drops that entry for membership changes.
+function readsPerson(bytecode: unknown): boolean {
+ return Array.isArray(bytecode) && bytecode.includes('person')
+}
+
// A pinned goal converts when the property branch matches, or any event branch does. The two are
// independent detectors of the same goal, so they are OR'd — matching the UI, where a person who
// does either is converted.