[improve][cli] Add client side looping in "pulsar-admin topics analyze-backlog" cli to avoid potential HTTP call timeout#25126
Conversation
| mergedResult.setLastMessageId(currentResult.getLastMessageId()); | ||
| } | ||
|
|
||
| if (!mergedResult.isAborted() || mergedResult.getEntries() >= backlogScanMaxEntries) { |
There was a problem hiding this comment.
the !mergedResult.isAborted() part isn't correct.
The purpose of the CLI loop is to keep on iterating until the result is COMPLETED or the number of scanned entries exceeds backlogScanMaxEntries.
| String[] messageIdSplits = mergedResult.getLastMessageId().split(":"); | ||
| MessageIdImpl nextScanMessageId = | ||
| new MessageIdImpl(Long.parseLong(messageIdSplits[0]), Long.parseLong(messageIdSplits[1]) + 1, | ||
| partitionIndex); |
There was a problem hiding this comment.
Instead of parsing the message Id String, it would be better to use org.apache.pulsar.client.api.MessageIdAdv interface to get the ledgerId and entryId.
There was a problem hiding this comment.
Could you provide me more information, I couldn't find one method that could parse ledgerId:entryId string to a MessageIdAdv instance.
| print("Analyze backlog progress, scanned entries: " + mergedResult.getEntries() | ||
| + ", scan max entries: " + backlogScanMaxEntries); |
There was a problem hiding this comment.
It would be useful to print the current value of mergedResult in json format without linefeeds so that the CLI output can be parsed as NDJSON.
There was a problem hiding this comment.
There are two ObjectMapper in CliCommand, so we should use the one without pretty printer to print json without linefeeds, and then pass the json string to print() method. Is my understanding correct?
| partitionIndex); | ||
| startPosition = Optional.of(nextScanMessageId); | ||
| } | ||
| print(mergedResult); |
There was a problem hiding this comment.
output would have to be json format without linefeeds to make the CLI output parseable as NDJSON. The last line in the output would be the final result. Perhaps there could be a command line option to configure whether ndjson should be used since it's not pretty printed.
There was a problem hiding this comment.
Perhaps there could be a command line option to configure whether ndjson should be used since it's not pretty printed.
A little bit confused. Does this option only take effect on the final result, or does it also apply to the intermediate results?
| } | ||
|
|
||
| @Test | ||
| public void topicsAnalyzeBacklog() throws Exception { |
There was a problem hiding this comment.
A test without mocks, similar to the tests in #25127 would be useful in addition since it would serve as an integration test.
There was a problem hiding this comment.
I haven't found similar examples for reference. Could you provide me some examples.
I don't know how to invoke admin CLI in integration tests and how to receive the outputs(since they are printed to the console output).
There was a problem hiding this comment.
Seems we need to handle the test in integration module like CLITest?
Is there a better approach? Running the tests in integration module requires local image building.
There was a problem hiding this comment.
Seems we need to handle the test in integration module like
CLITest?Is there a better approach? Running the tests in integration module requires local image building.
Yes it's a bit clumbersome.
To build an image quickly, use this script:
./build/build_java_test_image.sh
That requires setting export PULSAR_TEST_IMAGE_NAME=apachepulsar/java-test-image:latest environment variable so that the apachepulsar/java-test-image:latest docker image is used instead of the default apachepulsar/pulsar-test-latest-version:latest which takes much longer to build.
If you are running the test in IntelliJ, you can edit the default value at
For running integration tests on command line, this is the sequence I have used:
# compile integration test dependencies
mvn -am -pl tests/integration -Dcheckstyle.skip=true -Dlicense.skip=true -Dspotbugs.skip=true -DskipTests install
./build/build_java_test_image.sh
export PULSAR_TEST_IMAGE_NAME=apachepulsar/java-test-image:latest
# run the test
mvn -DintegrationTests -pl tests/integration -DtestRetryCount=0 -DredirectTestOutputToFile=false test \
-Dtest=TestClassNameHere
If you are working on the test alone, you obviously don't have to rebuild the image after each change.
Fixes #25083
Motivation
Use client-side looping instead of increasing broker settings to avoid potential HTTP call timeout in "pulsar-admin topics analyze-backlog" cli.
Modifications
Add client-side looping, add test.
Verifying this change
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: oneby-wang#21