-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: drop console log events when disabled #18210
Merged
pauldambra
merged 4 commits into
master
from
feat/drop-console-log-events-when-disabled
Oct 26, 2023
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e94fc6c
feat: drop console log events when disabled
pauldambra 1b390dc
don't process logs before dropping them
pauldambra abd75fb
write tests and as a result fix de-duplication
pauldambra d8e066f
overwriting default with default is unnecessary
pauldambra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,14 +8,14 @@ import { sessionRecordingConsumerConfig } from '../../../config/config' | |
import { KAFKA_SESSION_RECORDING_SNAPSHOT_ITEM_EVENTS } from '../../../config/kafka-topics' | ||
import { BatchConsumer, startBatchConsumer } from '../../../kafka/batch-consumer' | ||
import { createRdConnectionConfigFromEnvVars } from '../../../kafka/config' | ||
import { runInstrumentedFunction } from '../../../main/utils' | ||
import { PipelineEvent, PluginsServerConfig, RawEventMessage, RedisPool, RRWebEvent, TeamId } from '../../../types' | ||
import { BackgroundRefresher } from '../../../utils/background-refresher' | ||
import { PostgresRouter } from '../../../utils/db/postgres' | ||
import { status } from '../../../utils/status' | ||
import { createRedisPool } from '../../../utils/utils' | ||
import { fetchTeamTokensWithRecordings } from '../../../worker/ingestion/team-manager' | ||
import { ObjectStorage } from '../../services/object_storage' | ||
import { runInstrumentedFunction } from '../../utils' | ||
import { addSentryBreadcrumbsEventListeners } from '../kafka-metrics' | ||
import { eventDroppedCounter } from '../metrics' | ||
import { ConsoleLogsIngester } from './services/console-logs-ingester' | ||
|
@@ -95,6 +95,11 @@ type PartitionMetrics = { | |
lastKnownCommit?: number | ||
} | ||
|
||
export interface TeamIDWithConfig { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added with structure since if/when we start ingesting network performance events to ClickHouse we'll want the same control |
||
teamId: TeamId | null | ||
consoleLogIngestionEnabled: boolean | ||
} | ||
|
||
export class SessionRecordingIngester { | ||
redisPool: RedisPool | ||
sessions: Record<string, SessionManager> = {} | ||
|
@@ -107,7 +112,7 @@ export class SessionRecordingIngester { | |
batchConsumer?: BatchConsumer | ||
partitionAssignments: Record<number, PartitionMetrics> = {} | ||
partitionLockInterval: NodeJS.Timer | null = null | ||
teamsRefresher: BackgroundRefresher<Record<string, TeamId>> | ||
teamsRefresher: BackgroundRefresher<Record<string, TeamIDWithConfig>> | ||
offsetsRefresher: BackgroundRefresher<Record<number, number>> | ||
config: PluginsServerConfig | ||
topic = KAFKA_SESSION_RECORDING_SNAPSHOT_ITEM_EVENTS | ||
|
@@ -120,7 +125,7 @@ export class SessionRecordingIngester { | |
private objectStorage: ObjectStorage | ||
) { | ||
// NOTE: globalServerConfig contains the default pluginServer values, typically not pointing at dedicated resources like kafka or redis | ||
// We stil connect to some of the non-dedicated resources such as postgres or the Replay events kafka. | ||
// We still connect to some of the non-dedicated resources such as postgres or the Replay events kafka. | ||
this.config = sessionRecordingConsumerConfig(globalServerConfig) | ||
this.redisPool = createRedisPool(this.config) | ||
|
||
|
@@ -198,7 +203,7 @@ export class SessionRecordingIngester { | |
op: 'checkHighWaterMark', | ||
}) | ||
|
||
// Check that we are not below the high water mark for this partition (another consumer may have flushed further than us when revoking) | ||
// Check that we are not below the high-water mark for this partition (another consumer may have flushed further than us when revoking) | ||
if ( | ||
await this.persistentHighWaterMarker.isBelowHighWaterMark(event.metadata, KAFKA_CONSUMER_GROUP_ID, offset) | ||
) { | ||
|
@@ -228,7 +233,7 @@ export class SessionRecordingIngester { | |
if (!this.sessions[key]) { | ||
const { partition, topic } = event.metadata | ||
|
||
const sessionManager = new SessionManager( | ||
this.sessions[key] = new SessionManager( | ||
this.config, | ||
this.objectStorage.s3, | ||
this.realtimeManager, | ||
|
@@ -238,8 +243,6 @@ export class SessionRecordingIngester { | |
partition, | ||
topic | ||
) | ||
|
||
this.sessions[key] = sessionManager | ||
} | ||
|
||
await this.sessions[key]?.add(event) | ||
|
@@ -250,7 +253,7 @@ export class SessionRecordingIngester { | |
|
||
public async parseKafkaMessage( | ||
message: Message, | ||
getTeamFn: (s: string) => Promise<TeamId | null> | ||
getTeamFn: (s: string) => Promise<TeamIDWithConfig | null> | ||
): Promise<IncomingRecordingMessage | void> { | ||
const statusWarn = (reason: string, extra?: Record<string, any>) => { | ||
status.warn('⚠️', 'invalid_message', { | ||
|
@@ -288,14 +291,15 @@ export class SessionRecordingIngester { | |
return statusWarn('no_token') | ||
} | ||
|
||
let teamId: TeamId | null = null | ||
let teamIdWithConfig: TeamIDWithConfig | null = null | ||
const token = messagePayload.token | ||
|
||
if (token) { | ||
teamId = await getTeamFn(token) | ||
teamIdWithConfig = await getTeamFn(token) | ||
} | ||
|
||
if (teamId == null) { | ||
// NB `==` so we're comparing undefined and null | ||
if (teamIdWithConfig == null || teamIdWithConfig.teamId == null) { | ||
eventDroppedCounter | ||
.labels({ | ||
event_type: 'session_recordings_blob_ingestion', | ||
|
@@ -328,7 +332,7 @@ export class SessionRecordingIngester { | |
event, | ||
}, | ||
tags: { | ||
team_id: teamId, | ||
team_id: teamIdWithConfig.teamId, | ||
session_id: $session_id, | ||
}, | ||
}) | ||
|
@@ -343,22 +347,21 @@ export class SessionRecordingIngester { | |
}) | ||
} | ||
|
||
const recordingMessage: IncomingRecordingMessage = { | ||
return { | ||
metadata: { | ||
partition: message.partition, | ||
topic: message.topic, | ||
offset: message.offset, | ||
timestamp: message.timestamp, | ||
consoleLogIngestionEnabled: teamIdWithConfig.consoleLogIngestionEnabled, | ||
}, | ||
|
||
team_id: teamId, | ||
team_id: teamIdWithConfig.teamId, | ||
distinct_id: messagePayload.distinct_id, | ||
session_id: $session_id, | ||
window_id: $window_id, | ||
events: events, | ||
} | ||
|
||
return recordingMessage | ||
} | ||
|
||
public async handleEachBatch(messages: Message[]): Promise<void> { | ||
|
@@ -408,7 +411,10 @@ export class SessionRecordingIngester { | |
} | ||
|
||
const recordingMessage = await this.parseKafkaMessage(message, (token) => | ||
this.teamsRefresher.get().then((teams) => teams[token] || null) | ||
this.teamsRefresher.get().then((teams) => ({ | ||
teamId: teams[token]?.teamId || null, | ||
consoleLogIngestionEnabled: teams[token]?.consoleLogIngestionEnabled ?? true, | ||
})) | ||
) | ||
|
||
if (recordingMessage) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the only real change since last review...
Deduplication didn't work at all 🙈 🤦