Skip to content

Commit

Permalink
feat(hog): standardize event fields (#24882)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
mariusandra and github-actions[bot] authored Sep 19, 2024
1 parent ded7c2a commit eb6ab26
Show file tree
Hide file tree
Showing 35 changed files with 156 additions and 132 deletions.
90 changes: 45 additions & 45 deletions .github/workflows/rust-docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ jobs:
strategy:
matrix:
include:
- image: capture
dockerfile: ./rust/Dockerfile
- image: hook-api
dockerfile: ./rust/Dockerfile
- image: hook-janitor
dockerfile: ./rust/Dockerfile
- image: hook-worker
dockerfile: ./rust/Dockerfile
- image: hook-migrator
dockerfile: ./rust/Dockerfile.migrate-hooks
- image: cyclotron-janitor
dockerfile: ./rust/Dockerfile
- image: cyclotron-fetch
dockerfile: ./rust/Dockerfile
- image: property-defs-rs
dockerfile: ./rust/Dockerfile
- image: capture
dockerfile: ./rust/Dockerfile
- image: hook-api
dockerfile: ./rust/Dockerfile
- image: hook-janitor
dockerfile: ./rust/Dockerfile
- image: hook-worker
dockerfile: ./rust/Dockerfile
- image: hook-migrator
dockerfile: ./rust/Dockerfile.migrate-hooks
- image: cyclotron-janitor
dockerfile: ./rust/Dockerfile
- image: cyclotron-fetch
dockerfile: ./rust/Dockerfile
- image: property-defs-rs
dockerfile: ./rust/Dockerfile
runs-on: depot-ubuntu-22.04-4
permissions:
id-token: write # allow issuing OIDC tokens for this workflow run
Expand Down Expand Up @@ -122,35 +122,35 @@ jobs:
if: github.ref == 'refs/heads/master'
strategy:
matrix:
include:
- release: capture
values:
image:
sha: "${{ needs.build.outputs.capture_digest }}"
- release: capture-replay
values:
image:
sha: "${{ needs.build.outputs.capture_digest }}"
- release: cyclotron
values:
fetch_image:
sha: "${{ needs.build.outputs.cyclotron-fetch_digest }}"
janitor_image:
sha: "${{ needs.build.outputs.cyclotron-janitor_digest }}"
- release: property-defs-rs
values:
image:
sha: "${{ needs.build.outputs.property-defs-rs_digest }}"
- release: hoghooks
values:
api_image:
sha: "${{ needs.build.outputs.hook-api_digest }}"
janitor_image:
sha: "${{ needs.build.outputs.hook-janitor_digest }}"
worker_image:
sha: "${{ needs.build.outputs.hook-worker_digest }}"
migrator_image:
sha: "${{ needs.build.outputs.hook-migrator_digest }}"
include:
- release: capture
values:
image:
sha: '${{ needs.build.outputs.capture_digest }}'
- release: capture-replay
values:
image:
sha: '${{ needs.build.outputs.capture_digest }}'
- release: cyclotron
values:
fetch_image:
sha: '${{ needs.build.outputs.cyclotron-fetch_digest }}'
janitor_image:
sha: '${{ needs.build.outputs.cyclotron-janitor_digest }}'
- release: property-defs-rs
values:
image:
sha: '${{ needs.build.outputs.property-defs-rs_digest }}'
- release: hoghooks
values:
api_image:
sha: '${{ needs.build.outputs.hook-api_digest }}'
janitor_image:
sha: '${{ needs.build.outputs.hook-janitor_digest }}'
worker_image:
sha: '${{ needs.build.outputs.hook-worker_digest }}'
migrator_image:
sha: '${{ needs.build.outputs.hook-migrator_digest }}'
steps:
- name: get deployer token
id: deployer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,26 +137,28 @@ export function convertToHogFunctionInvocationGlobals(
return {
project: {
id: team?.id ?? 0,

name: team?.name ?? 'Default project',
url: projectUrl,
},
event: {
uuid: event.uuid ?? '',
name: event.event, // TODO: rename back to "event"?
event: event.event,
distinct_id: event.distinct_id,
// TODO: add back elements_chain?
elements_chain: event.elements_chain ?? '',
properties: event.properties,
timestamp: event.timestamp,

name: event.event,
url: `${projectUrl}/events/${encodeURIComponent(event.uuid ?? '')}/${encodeURIComponent(event.timestamp)}`,
properties: {
...event.properties,
...(event.elements_chain ? { $elements_chain: event.elements_chain } : {}),
},
},
person: {
uuid: person.uuid ?? person.id ?? '', // TODO: rename back to "id"?
id: person.uuid ?? person.id ?? '',
uuid: person.uuid ?? person.id ?? '', // TODO: remove
properties: person.properties,

name: asDisplay(person),
url: `${projectUrl}/person/${encodeURIComponent(event.distinct_id)}`,
properties: person.properties,
},
groups: {},
}
Expand Down Expand Up @@ -465,21 +467,24 @@ export const hogFunctionConfigurationLogic = kea<hogFunctionConfigurationLogicTy
event: {
uuid: eventId,
distinct_id: uuid(),
name: '$pageview',
event: '$pageview',
timestamp: dayjs().toISOString(),
url: `${window.location.origin}/project/${currentTeam?.id}/events/`,
elements_chain: '',
properties: {
$current_url: currentUrl,
$browser: 'Chrome',
},
name: '$pageview',
url: `${window.location.origin}/project/${currentTeam?.id}/events/`,
},
person: {
uuid: personId,
name: 'Example person',
url: `${window.location.origin}/person/${personId}`,
id: personId,
uuid: personId, // TODO: remove
properties: {
email: '[email protected]',
},
name: 'Example person',
url: `${window.location.origin}/person/${personId}`,
},
groups: {},
project: {
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4502,17 +4502,20 @@ export type HogFunctionInvocationGlobals = {
}
event: {
uuid: string
name: string
event: string
elements_chain: string
distinct_id: string
properties: Record<string, any>
timestamp: string
name: string
url: string
}
person?: {
id: string
properties: Record<string, any>
uuid: string
name: string
url: string
properties: Record<string, any>
}
groups?: Record<
string,
Expand Down
15 changes: 12 additions & 3 deletions plugin-server/src/cdp/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,27 @@ export type HogFunctionInvocationGlobals = {
url: string
}
event: {
/* Database fields */
uuid: string
name: string
event: string
distinct_id: string
properties: Record<string, any>
elements_chain: string
timestamp: string

/* Special fields in Hog */
name: string
url: string
}
person?: {
uuid: string
/** Database fields */
id: string
properties: Record<string, any>

/** Special fields in Hog */
uuid: string // TODO: remove?
name: string
url: string
properties: Record<string, any>
}
groups?: Record<string, GroupType>
}
Expand Down
13 changes: 6 additions & 7 deletions plugin-server/src/cdp/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ export function convertToHogFunctionInvocationGlobals(
siteUrl: string
): HogFunctionInvocationGlobals {
const properties = event.properties ? JSON.parse(event.properties) : {}
if (event.elements_chain) {
properties['$elements_chain'] = event.elements_chain
}

const projectUrl = `${siteUrl}/project/${team.id}`

let person: HogFunctionInvocationGlobals['person']
Expand All @@ -63,9 +59,10 @@ export function convertToHogFunctionInvocationGlobals(
const personDisplayName = getPersonDisplayName(team, event.distinct_id, personProperties)

person = {
id: event.person_id,
properties: personProperties,
uuid: event.person_id,
name: personDisplayName,
properties: personProperties,
url: `${projectUrl}/person/${encodeURIComponent(event.distinct_id)}`,
}
}
Expand All @@ -80,10 +77,12 @@ export function convertToHogFunctionInvocationGlobals(
},
event: {
uuid: event.uuid,
name: event.event!,
event: event.event!,
elements_chain: event.elements_chain,
distinct_id: event.distinct_id,
properties,
timestamp: eventTimestamp,
name: event.event!,
url: `${projectUrl}/events/${encodeURIComponent(event.uuid)}/${encodeURIComponent(eventTimestamp)}`,
},
person,
Expand Down Expand Up @@ -141,7 +140,7 @@ export function convertToHogFunctionFilterGlobal(globals: HogFunctionInvocationG
}
}

const elementsChain = globals.event.properties['$elements_chain']
const elementsChain = globals.event.elements_chain ?? globals.event.properties['$elements_chain']
const response = {
event: globals.event.name,
elements_chain: elementsChain,
Expand Down
7 changes: 1 addition & 6 deletions plugin-server/tests/cdp/hog-executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ import { HogExecutor } from '../../src/cdp/hog-executor'
import { HogFunctionManager } from '../../src/cdp/hog-function-manager'
import { HogFunctionInvocation, HogFunctionType } from '../../src/cdp/types'
import { HOG_EXAMPLES, HOG_FILTERS_EXAMPLES, HOG_INPUTS_EXAMPLES } from './examples'
import {
createHogExecutionGlobals,
createHogFunction,
createInvocation,
insertHogFunction as _insertHogFunction,
} from './fixtures'
import { createHogExecutionGlobals, createHogFunction, createInvocation } from './fixtures'

const setupFetchResponse = (invocation: HogFunctionInvocation, options?: { status?: number; body?: string }): void => {
invocation.queue = 'hog'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_function_works(self):
self.run_function(
inputs=create_inputs(),
globals={
"event": {"name": "$identify"},
"event": {"event": "$identify"},
},
)

Expand Down
4 changes: 2 additions & 2 deletions posthog/cdp/templates/avo/template_avo.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
'trackingId': '',
'samplingRate': 1,
'type': 'event',
'eventName': event.name,
'eventName': event.event,
'messageId': event.uuid,
'eventProperties': []
}
Expand Down Expand Up @@ -157,7 +157,7 @@ def migrate(cls, obj):
event_string = ", ".join(escape_hogql_string(event) for event in events_to_exclude)
hf["filters"]["events"] = [
{
"id": "All events",
"id": None,
"name": "All events",
"type": "events",
"order": 0,
Expand Down
8 changes: 4 additions & 4 deletions posthog/cdp/templates/avo/test_template_avo.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_function_works(self):
"event": {
"uuid": "0191c693-d93b-7516-b1e3-64ec33c96464",
"distinct_id": "66e614bd-d9f2-491e-9e2c-eeab3090f72f",
"name": "sign up",
"event": "sign up",
"properties": {
"distinct_id": "66e614bd-d9f2-491e-9e2c-eeab3090f72f",
"token": "phc_ex7Mnvi4DqeB6xSQoXU1UVPzAmUIpicMFKELQXGGTYQO",
Expand Down Expand Up @@ -107,7 +107,7 @@ def test_automatic_type_mapping(self):
self.run_function(
inputs=self._inputs(),
globals={
"event": {"name": "sign up", "properties": {"test": property_value}},
"event": {"event": "sign up", "properties": {"test": property_value}},
},
)

Expand All @@ -132,7 +132,7 @@ def test_property_filters(self):
},
globals={
"event": {
"name": "sign up",
"event": "sign up",
"properties": {"name": "Max", "company": "PostHog", "job": "Product Engineer"},
},
},
Expand Down Expand Up @@ -202,7 +202,7 @@ def test_exclude_events(self):
assert template["filters"] == {
"events": [
{
"id": "All events",
"id": None,
"name": "All events",
"type": "events",
"order": 0,
Expand Down
2 changes: 1 addition & 1 deletion posthog/cdp/templates/braze/template_braze.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"default": {
"properties": "{event.properties}",
"external_id": "{event.distinct_id}",
"name": "{event.name}",
"name": "{event.event}",
"time": "{event.timestamp}",
},
"secret": False,
Expand Down
4 changes: 2 additions & 2 deletions posthog/cdp/templates/braze/test_template_braze.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_function_works(self):
"apiKey": "my_secret_key",
"attributes": {"email": "{person.properties.email}"},
"event": {
"name": "{event.name}",
"name": "{event.event}",
"time": "{event.timestamp}",
"properties": "{event.properties}",
"external_id": "{event.distinct_id}",
Expand All @@ -36,7 +36,7 @@ def test_function_works(self):
"events": [
{
"external_id": "{event.distinct_id}",
"name": "{event.name}",
"name": "{event.event}",
"properties": "{event.properties}",
"time": "{event.timestamp}",
},
Expand Down
2 changes: 1 addition & 1 deletion posthog/cdp/templates/clearbit/template_clearbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
let api_key := inputs.api_key
let email := inputs.email
if (empty(email) or event.name == '$set' or person.properties.clearbit_enriched) {
if (empty(email) or event.event == '$set' or person.properties.clearbit_enriched) {
return false
}
Expand Down
Loading

0 comments on commit eb6ab26

Please sign in to comment.