Skip to content

Commit

Permalink
chore: Keep ip only within properties
Browse files Browse the repository at this point in the history
  • Loading branch information
tiina303 committed Sep 28, 2023
1 parent 300193c commit 6514987
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 24 deletions.
1 change: 0 additions & 1 deletion plugin-server/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,6 @@ export interface ClickHouseEvent extends BaseEvent {
interface BaseIngestionEvent {
eventUuid: string
event: string
ip: string | null
teamId: TeamId
distinctId: string
properties: Properties
Expand Down
10 changes: 6 additions & 4 deletions plugin-server/src/utils/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
export function convertToProcessedPluginEvent(event: PostIngestionEvent): ProcessedPluginEvent {
return {
distinct_id: event.distinctId,
ip: event.ip,
ip: null, // deprecated : within properties[$ip] now
team_id: event.teamId,
event: event.event,
properties: event.properties,
Expand Down Expand Up @@ -67,7 +67,6 @@ export function convertToIngestionEvent(event: RawClickHouseEvent, skipElementsC
return {
eventUuid: event.uuid,
event: event.event!,
ip: properties['$ip'],
teamId: event.team_id,
distinctId: event.distinct_id,
properties,
Expand Down Expand Up @@ -95,6 +94,10 @@ export function normalizeEvent(event: PluginEvent): PluginEvent {
if (event['$set_once']) {
properties['$set_once'] = { ...properties['$set_once'], ...event['$set_once'] }
}
if (!properties['$ip'] && event.ip) {
// if $ip wasn't sent with the event, then add what we got from capture
properties['$ip'] = event.ip
}
if (!['$snapshot', '$performance_event'].includes(event.event)) {
properties = personInitialAndUTMProperties(properties)
}
Expand All @@ -113,7 +116,6 @@ export function formPipelineEvent(message: Message): PipelineEvent {
const event: PipelineEvent = normalizeEvent({
...combinedEvent,
site_url: combinedEvent.site_url || null,
ip: combinedEvent.ip || null,
})
return event
}
Expand All @@ -122,7 +124,7 @@ export function formPluginEvent(event: RawClickHouseEvent): PluginEvent {
const postIngestionEvent = convertToIngestionEvent(event)
return {
distinct_id: postIngestionEvent.distinctId,
ip: postIngestionEvent.properties['$ip'],
ip: null, // deprecated : within properties[$ip] now
site_url: '',
team_id: postIngestionEvent.teamId,
now: DateTime.now().toISO(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { captureIngestionWarning } from '../utils'
import { EventPipelineRunner } from './runner'

export async function prepareEventStep(runner: EventPipelineRunner, event: PluginEvent): Promise<PreIngestionEvent> {
const { ip, team_id, uuid } = event
const { team_id, uuid } = event
const invalidTimestampCallback = function (type: string, details: Record<string, any>) {
// TODO: make that metric name more generic when transitionning to prometheus
runner.hub.statsd?.increment('process_event_invalid_timestamp', { teamId: String(team_id), type: type })
Expand All @@ -15,7 +15,6 @@ export async function prepareEventStep(runner: EventPipelineRunner, event: Plugi
}
const preIngestionEvent = await runner.hub.eventsProcessor.processEvent(
String(event.distinct_id),
ip,
event,
team_id,
parseEventTimestamp(event, invalidTimestampCallback),
Expand Down
14 changes: 3 additions & 11 deletions plugin-server/src/worker/ingestion/process-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export class EventsProcessor {

public async processEvent(
distinctId: string,
ip: string | null,
data: PluginEvent,
teamId: number,
timestamp: DateTime,
Expand Down Expand Up @@ -90,7 +89,7 @@ export class EventsProcessor {
eventUuid,
})
try {
result = await this.capture(eventUuid, ip, team, data['event'], distinctId, properties, timestamp)
result = await this.capture(eventUuid, team, data['event'], distinctId, properties, timestamp)
this.pluginsServer.statsd?.timing('kafka_queue.single_save.standard', singleSaveTimer, {
team_id: teamId.toString(),
})
Expand All @@ -105,7 +104,6 @@ export class EventsProcessor {

private async capture(
eventUuid: string,
ip: string | null,
team: Team,
event: string,
distinctId: string,
Expand All @@ -121,13 +119,8 @@ export class EventsProcessor {
delete properties['$elements']
}

if (ip) {
if (team.anonymize_ips) {
ip = null
delete properties['$ip']
} else if (!('$ip' in properties)) {
properties['$ip'] = ip
}
if (properties['$ip'] && team.anonymize_ips) {
delete properties['$ip']
}

try {
Expand All @@ -150,7 +143,6 @@ export class EventsProcessor {
return {
eventUuid,
event,
ip,
distinctId,
properties,
timestamp: timestamp.toISO() as ISOTimestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ jest.mock('./../../../src/worker/ingestion/utils')
const event: PostIngestionEvent = {
eventUuid: 'uuid1',
distinctId: 'my_id',
ip: '127.0.0.1',
teamId: 2,
timestamp: '2020-02-23T02:15:00.000Z' as ISOTimestamp,
event: '$pageview',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ jest.mock('../../../../src/utils/status')

const pluginEvent: PluginEvent = {
distinct_id: 'my_id',
ip: '127.0.0.1',
ip: null,
site_url: 'http://localhost',
team_id: 2,
now: '2020-02-23T02:15:00Z',
timestamp: '2020-02-23T02:15:00Z',
event: 'default event',
properties: {},
properties: {
$ip: '127.0.0.1',
},
uuid: '017ef865-19da-0000-3b60-1506093bf40f',
}

Expand Down Expand Up @@ -84,7 +86,6 @@ describe('prepareEventStep()', () => {
elementsList: [],
event: 'default event',
eventUuid: '017ef865-19da-0000-3b60-1506093bf40f',
ip: '127.0.0.1',
properties: {
$ip: '127.0.0.1',
},
Expand All @@ -106,7 +107,6 @@ describe('prepareEventStep()', () => {
elementsList: [],
event: 'default event',
eventUuid: '017ef865-19da-0000-3b60-1506093bf40f',
ip: null,
properties: {},
teamId: 2,
timestamp: '2020-02-23T02:15:00.000Z',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const testElements: any = ['element1', 'element2']
const ingestionEvent: PostIngestionEvent = {
eventUuid: 'uuid1',
distinctId: 'my_id',
ip: '127.0.0.1',
teamId: 2,
timestamp: '2020-02-23T02:15:00.000Z' as ISOTimestamp,
event: '$pageview',
Expand Down

0 comments on commit 6514987

Please sign in to comment.