Skip to content

Conversation

apalan60
Copy link
Contributor

@apalan60 apalan60 commented Sep 3, 2025

Refactor help and version handling in command-line tools by replacing
duplicate code with CommandLineUtils#maybePrintHelpOrVersion.

Reviewers: TengYao Chi [email protected], Ken Huang
[email protected], Jhen-Yung Hsu [email protected], Chia-Ping
Tsai [email protected]

@github-actions github-actions bot added triage PRs from the community tools small Small PRs labels Sep 3, 2025
@Yunyung
Copy link
Collaborator

Yunyung commented Sep 3, 2025

Thanks for the PR. I see the same pattern in ReplicaVerificationTool.java, could you update it as well?
Also, it would be great if you could provide the before and after output results for verification.

@apalan60 apalan60 changed the title MINOR: Refactor JmxTool and StreamsResetter to use CommandLineUtils#maybePrintHelpOrVersion MINOR: Refactor CLI tools to use CommandLineUtils#maybePrintHelpOrVersion Sep 3, 2025
Copy link
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

LGTM

@apalan60
Copy link
Contributor Author

apalan60 commented Sep 3, 2025

@chia7712 @Yunyung

Thanks for your review!
I ran the following command to verify, and the output is the same as before the change:

# --- JmxTool ---
echo "=== JmxTool --help ==="
./bin/kafka-run-class.sh org.apache.kafka.tools.JmxTool --help |& head -n 3
echo

echo "=== JmxTool --version ==="
./bin/kafka-run-class.sh org.apache.kafka.tools.JmxTool --version |& head -n 3
echo

echo "=== JmxTool (no args) ==="
./bin/kafka-run-class.sh org.apache.kafka.tools.JmxTool |& head -n 3
echo
# -------------------------

# --- StreamsResetter ---
echo "=== StreamsResetter --help ==="
./bin/kafka-run-class.sh org.apache.kafka.tools.StreamsResetter --help |& head -n 3
echo

echo "=== StreamsResetter --version ==="
./bin/kafka-run-class.sh org.apache.kafka.tools.StreamsResetter --version |& head -n 3
echo

echo "=== StreamsResetter (no args) ==="
./bin/kafka-run-class.sh org.apache.kafka.tools.StreamsResetter |& head -n 3
echo
# -------------------------

# --- ReplicaVerificationTool ---
echo "=== ReplicaVerificationTool --help ==="
./bin/kafka-run-class.sh org.apache.kafka.tools.ReplicaVerificationTool --help |& head -n 3
echo

echo "=== ReplicaVerificationTool --version ==="
./bin/kafka-run-class.sh org.apache.kafka.tools.ReplicaVerificationTool --version |& head -n 3
echo

echo "=== ReplicaVerificationTool (no args) ==="
./bin/kafka-run-class.sh org.apache.kafka.tools.ReplicaVerificationTool |& head -n 3
echo
# -------------------------


Trunk output:

=== JmxTool --help ===
Dump JMX values to standard output.
Option                                   Description                           
------                                   -----------                           

=== JmxTool --version ===
4.2.0-SNAPSHOT

=== JmxTool (no args) ===
Dump JMX values to standard output.
Option                                   Description                           
------                                   -----------                           

=== StreamsResetter --help ===
This tool helps to quickly reset an application in order to reprocess its data from scratch.
* This tool resets offsets of input topics to the earliest available offset (by default), or to a specific defined position* This tool deletes the internal topics that were created by Kafka Streams (topics starting with "<application.id>-").
The tool finds these internal topics automatically. If the topics flagged automatically for deletion by the dry-run are unsuitable, you can specify a subset with the "--internal-topics" option.

=== StreamsResetter --version ===
4.2.0-SNAPSHOT

=== StreamsResetter (no args) ===
Missing required option(s) [application-id]
Option (* = required)                  Description                            
---------------------                  -----------                            

=== ReplicaVerificationTool --help ===
[2025-09-04 03:36:50,983] WARN This tool is deprecated and may be removed in a future major release. (org.apache.kafka.tools.ReplicaVerificationTool)
Validate that all replicas for a set of topics have the same data.
Option                                 Description                        

=== ReplicaVerificationTool --version ===
[2025-09-04 03:36:51,749] WARN This tool is deprecated and may be removed in a future major release. (org.apache.kafka.tools.ReplicaVerificationTool)
4.2.0-SNAPSHOT

=== ReplicaVerificationTool (no args) ===
[2025-09-04 03:36:52,509] WARN This tool is deprecated and may be removed in a future major release. (org.apache.kafka.tools.ReplicaVerificationTool)
Validate that all replicas for a set of topics have the same data.
Option                                 Description                        

Branch output:

=== JmxTool --help ===
Dump JMX values to standard output.
Option                                   Description                           
------                                   -----------                           

=== JmxTool --version ===
4.2.0-SNAPSHOT

=== JmxTool (no args) ===
Dump JMX values to standard output.
Option                                   Description                           
------                                   -----------                           

=== StreamsResetter --help ===
This tool helps to quickly reset an application in order to reprocess its data from scratch.
* This tool resets offsets of input topics to the earliest available offset (by default), or to a specific defined position* This tool deletes the internal topics that were created by Kafka Streams (topics starting with "<application.id>-").
The tool finds these internal topics automatically. If the topics flagged automatically for deletion by the dry-run are unsuitable, you can specify a subset with the "--internal-topics" option.

=== StreamsResetter --version ===
4.2.0-SNAPSHOT

=== StreamsResetter (no args) ===
Missing required option(s) [application-id]
Option (* = required)                  Description                            
---------------------                  -----------                            

=== ReplicaVerificationTool --help ===
[2025-09-04 03:37:36,945] WARN This tool is deprecated and may be removed in a future major release. (org.apache.kafka.tools.ReplicaVerificationTool)
Validate that all replicas for a set of topics have the same data.
Option                                 Description                        

=== ReplicaVerificationTool --version ===
[2025-09-04 03:37:37,717] WARN This tool is deprecated and may be removed in a future major release. (org.apache.kafka.tools.ReplicaVerificationTool)
4.2.0-SNAPSHOT

=== ReplicaVerificationTool (no args) ===
[2025-09-04 03:37:38,472] WARN This tool is deprecated and may be removed in a future major release. (org.apache.kafka.tools.ReplicaVerificationTool)
Validate that all replicas for a set of topics have the same data.
Option                                 Description                        

@Yunyung
Copy link
Collaborator

Yunyung commented Sep 3, 2025

Great. LGTM, thanks.

Copy link
Collaborator

@m1a2st m1a2st left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM

@github-actions github-actions bot removed the triage PRs from the community label Sep 4, 2025
Copy link
Contributor

@frankvicky frankvicky left a comment

Choose a reason for hiding this comment

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

@apalan60: LGTM.
Could you please merge the trunk to trigger CI?

@apalan60
Copy link
Contributor Author

apalan60 commented Sep 4, 2025

@frankvicky
CI rerun passed, thanks for the reminder.

@chia7712 chia7712 merged commit 6a1cdf8 into apache:trunk Sep 4, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants