Skip to content
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

fix: pass offsets to partitions as milliseconds instead of seconds #106

Merged
merged 6 commits into from
Jan 6, 2023

Conversation

rgraber
Copy link
Contributor

@rgraber rgraber commented Jan 6, 2023

Kafka partitions expect time offsets to be in milliseconds instead of seconds, so multiply the timestamp by 1000 before setting it on the partition.

Tested locally against the dev cluster.

Merge checklist:
Check off if complete or not applicable:

  • Version bumped
  • Changelog record added
  • Documentation updated (not only docstrings)
  • Commits are squashed
  • Noted any: Concerns, dependencies, deadlines, tickets, testing instructions

@rgraber rgraber marked this pull request as ready for review January 6, 2023 18:12
# Get the offset from the epoch in seconds.
offset_timestamp_s = int(offset_timestamp.timestamp())
# Get the offset from the epoch (Kafka expects offsets in milliseconds for offsets_for_times, see
# https://kafka-python.readthedocs.io/en/master/apidoc/KafkaConsumer.html#kafka.KafkaConsumer.offsets_for_times)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be misleading to link to the kafka-python library's docs here, since we're not using it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I'll see if I can find it in the library we're actually using.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell it's undocumented, both for confluent-kafka and the underlying librdkafka. I have a PR open to add a note about it in the latter.

CHANGELOG.rst Outdated Show resolved Hide resolved
Co-authored-by: Tim McCormack <tmccormack@edx.org>
@rgraber rgraber merged commit 22c1399 into main Jan 6, 2023
@rgraber rgraber deleted the rsgraber/20230105-use-milliseconds-for-offsets branch January 6, 2023 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants