Skip to content

[ISSUE 9757][pulsar-admin] add cmd to get service url of the leader broker - #9799

Merged
codelipenghui merged 10 commits into
apache:masterfrom
linlinnn:issue-9757
Mar 10, 2021
Merged

[ISSUE 9757][pulsar-admin] add cmd to get service url of the leader broker#9799
codelipenghui merged 10 commits into
apache:masterfrom
linlinnn:issue-9757

Conversation

@linlinnn

@linlinnn linlinnn commented Mar 4, 2021

Copy link
Copy Markdown
Contributor

Fixes: #9757

Motivation

see #9757 add cmd to get service url of the leader broker.

Modifications

add cmd parameter "leader-broker" in CmdBrokers, and provide "/admin/v2/brokers/leaderBroker" web endpoint to get service url of the leader broker.

Verifying this change

  • Make sure that the change passes the CI checks.

Documentation

Does this pull request introduce a new feature? yes
If yes, how is the feature documented? ( JavaDocs )

@codelipenghui codelipenghui left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice contribution!

@codelipenghui codelipenghui added this to the 2.8.0 milestone Mar 4, 2021
@codelipenghui codelipenghui added release/2.7.2 type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages labels Mar 4, 2021
@codelipenghui

Copy link
Copy Markdown
Contributor

/pulsarbot run-failure-checks

@wolfstudy wolfstudy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM +1

@codelipenghui codelipenghui added the doc-required Your PR changes impact docs and you will update later. label Mar 5, 2021
try {
return pulsar().getLeaderElectionService().getCurrentLeader()
.map(LeaderBroker::getServiceUrl)
.orElse("None");

@315157973 315157973 Mar 5, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice contribution!

Now we will return null if we have no data. I think it is better to keep the same, otherwise the status returned by the Broker side will be more and more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your comment.
But maybe unclear semantics if we print "" on the console.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In CMD, we can handle the case of null, but the exposed REST API should be consistent

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, i will take your advice.

@linlinnn
linlinnn requested a review from 315157973 March 6, 2021 11:09

@eolivelli eolivelli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall looks good to me.

I left a suggestion, thinking about future improvements to this API

Please take a look.
Once we publish an API we will have to maintain it basically forever

value = {
@ApiResponse(code = 401, message = "Authentication required"),
@ApiResponse(code = 403, message = "This operation requires super-user access") })
public String getLeaderBroker() throws Exception {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What about returning a structure instead of a single String?
This way in the future we will be about to return more information .
If we return only one String we cannot extend this API in the future

@linlinnn linlinnn Mar 8, 2021

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your suggestion.
What about returning LeaderBroker directly?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@eolivelli Good suggestion.

Yes, I think you can use the class LeaderBroker directly.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1 to return LeaderBroker

.orElse(null);
LeaderBroker leaderBroker = pulsar().getLeaderElectionService().getCurrentLeader()
.orElseThrow(() -> new RestException(Status.NOT_FOUND, "Couldn't find leader broker"));
BrokerInfo brokerInfo = new BrokerInfo();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I create BrokerInfo which is the same as LeaderBroker, Because I can not access LeaderBroker in module pulsar-client-admin.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@eolivelli Please help to review this PR.

@eolivelli eolivelli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perfect

+1

```shell
$ pulsar-admin brokers leader-broker
```

@Anonymitaet Anonymitaet Mar 8, 2021

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  1. If pulsar-admin brokers leader-broker has flags and descriptions, do not forget to add them to pulsar-admin docs.

  2. To allow users to have more info (flags and descriptions), it is better to add the URL of the pulsar-admin brokers leader-broker command on pulsar-admin. Like For more information, see [here](xxx).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your tip.
There is no more args for this command.

```java
admin.brokers().getLeaderBroker()
```

@Anonymitaet Anonymitaet Mar 8, 2021

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Better to add the Java admin URL to give more info to users?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The URL was contained in this doc.
The brokers method of the {@Inject: javadoc:PulsarAdmin:/admin/org/apache/pulsar/client/admin/PulsarAdmin.html} object in the Java API

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your explanations. Sorry I do not get you. I mean we can add a link w/ the line pointed to this command? Like https://github.com/apache/pulsar/blob/master/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/BrokersImpl.java#L80

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok

@Anonymitaet Anonymitaet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Many thanks for adding docs! I've commented, PTAL.

@Anonymitaet Anonymitaet added the doc Your PR contains doc changes, no matter whether the changes are in markdown or code files. label Mar 8, 2021
@linlinnn

linlinnn commented Mar 9, 2021

Copy link
Copy Markdown
Contributor Author

/pulsarbot run-failure-checks

@linlinnn
linlinnn requested a review from Anonymitaet March 10, 2021 09:40
@linlinnn

Copy link
Copy Markdown
Contributor Author

/pulsarbot run-failure-checks

@codelipenghui
codelipenghui merged commit dd5c3b4 into apache:master Mar 10, 2021
@codelipenghui

Copy link
Copy Markdown
Contributor

Thanks for the great work @linlinnn

@Anonymitaet Anonymitaet removed the doc-required Your PR changes impact docs and you will update later. label Apr 9, 2021
BewareMyPower pushed a commit to apache/pulsar-client-go that referenced this pull request Apr 22, 2024
### Motivation

To keep consistent with the [Java client](apache/pulsar#9799).

### Modifications

Add `GetLeaderBroker` interface.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc Your PR contains doc changes, no matter whether the changes are in markdown or code files. type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support to get which broker is the load coordinator

8 participants