Skip to content

Commit

Permalink
chore(capture): allow to skip sha hashing of the kafka messages (#21850)
Browse files Browse the repository at this point in the history
  • Loading branch information
xvello authored Apr 25, 2024
1 parent 8535186 commit e7e3514
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion posthog/api/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,11 @@ def capture_internal(
):
kafka_partition_key = None
else:
kafka_partition_key = hashlib.sha256(candidate_partition_key.encode()).hexdigest()
if settings.CAPTURE_SKIP_KEY_HASHING:
kafka_partition_key = candidate_partition_key
else:
# TODO: remove after progressive rollout of the option
kafka_partition_key = hashlib.sha256(candidate_partition_key.encode()).hexdigest()

return log_event(parsed_event, event["event"], partition_key=kafka_partition_key, historical=historical)

Expand Down
3 changes: 3 additions & 0 deletions posthog/settings/ingestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
# partitioning-related settings below.
CAPTURE_ALLOW_RANDOM_PARTITIONING = get_from_env("CAPTURE_ALLOW_RANDOM_PARTITIONING", True, type_cast=str_to_bool)

# TOOD: make default after rollout on both prods: remove the superfluous hashing of the Kafka message key
CAPTURE_SKIP_KEY_HASHING = get_from_env("CAPTURE_SKIP_KEY_HASHING", type_cast=bool, default=False)

# A list of <team_id:distinct_id> pairs (in the format 2:myLovelyId) that we should use
# random partitioning for when producing events to the Kafka topic consumed by the plugin server.
# This is a measure to handle hot partitions in ad-hoc cases.
Expand Down

0 comments on commit e7e3514

Please sign in to comment.