Skip to content

cli: accept timestamps in partitions list-offsets - #3214

Open
LemonCondor wants to merge 1 commit into
dpkp:masterfrom
LemonCondor:fix/cli-list-offsets-timestamp
Open

LemonCondor wants to merge 1 commit into
dpkp:masterfrom
LemonCondor:fix/cli-list-offsets-timestamp

Conversation

@LemonCondor

Copy link
Copy Markdown

The help of partitions list-offsets says that a spec may be a millisecond timestamp (both -s and -p TOPIC:PARTITION:SPEC), but a number is rejected (output of kafka.cli.admin.run_cli() against the test MockBroker):

$ python -m kafka.admin -b localhost:9092 partitions list-offsets -t topic-a -s 1700000000000
Unrecognized OffsetSpec: 1700000000000

This looks unintended: #2905 replaced the local _parse_spec(), which tried int() first, with OffsetSpec.build_from(), which only knows the named specs. KafkaAdminClient.list_partition_offsets() itself accepts timestamps, and groups reset-offsets --spec still does.

The command now parses an integer as OffsetTimestamp and passes everything else to OffsetSpec.build_from(), so named specs and the Unrecognized OffsetSpec message are unchanged.

Test: added TestListPartitionOffsetsCli in test/admin/test_admin_partitions.py. On master the three numeric cases fail and the two others pass; all five pass with the change. pytest test/admin passes (208 tests, MockBroker only, no real cluster), and pylint --errors-only on kafka/cli and the test file reports nothing.

The help text says a spec may be a millisecond timestamp, but since dpkp#2905
the value goes straight to OffsetSpec.build_from(), which only knows the
named specs: "-s 1700000000000" fails with "Unrecognized OffsetSpec".
Parse integers as OffsetTimestamp, as groups reset-offsets accepts them.
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.

1 participant