[improve][cli] pulsar-perf: check for invalid CLI options#18889
Conversation
|
There is currently some code repetition between pulsar-perf consume, produce, and read, however, removing this duplication requires a larger refactoring, and I think is outside of the scope of this change. I'll try to work on a separate PR which can share more code between these commands. |
tisonkun
left a comment
There was a problem hiding this comment.
Interesting.
This should have been handled by JCommander. But it seems that the version of jc we depend on cannot regard these cases as unknown options.
I read the source code of JCommander#parseValues and it shows the case...
For this patch, we may factor out this three code snippet to a utility and name it as validating params?
OK. I read this sentence now. Another question is that: is it possible a valid topic name starts with |
|
@tisonkun AFAICT even the latest versions of JCommander don't handle this. If you specify an unnamed set of args, like we do for the topics, JCommander will interpret any unknown options as args, and there doesn't seem to be a way to check for this other than the manual check. Yes, pulsar allows topics that start with |
tisonkun
left a comment
There was a problem hiding this comment.
Thanks for your explanation! Good to go.
|
/pulsarbot run-failure-checks |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #18889 +/- ##
============================================
+ Coverage 46.17% 46.94% +0.77%
- Complexity 10359 10534 +175
============================================
Files 703 703
Lines 68845 68861 +16
Branches 7382 7383 +1
============================================
+ Hits 31788 32330 +542
+ Misses 33448 32906 -542
- Partials 3609 3625 +16
Flags with carried forward coverage won't be shown. Click here to find out more. |
Fixes #18866
Motivation
pulsar-perf incorrectly interprets bad options (e.g. --foo) as topic names. This results in an unclear error message if, for example, there is a typo in one of the options.
Modifications
I looked through the code for the JCommander library to see if there is a built-in argument validation for things like this, however, JCommander is kind of limited in this respect. If you accept any non-option arguments, then it's up to you to validate those, so I had to add arg/topic validation to the pulsar-perf code.
Check the non-option arguments for values starting with a '-'. If found, print an error message that there was an un-recognized option.
Old error message
New error message
Verifying this change
This change is a trivial rework / code cleanup without any test coverage.
Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
Documentation
docdoc-requireddoc-not-neededdoc-completeMatching PR in forked repository
PR in forked repository: pgier#6