Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 10 commits into from
Mar 10, 2021

Conversation

linlinnn
Copy link
Contributor

@linlinnn linlinnn commented Mar 4, 2021

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 )

Copy link
Contributor

@codelipenghui codelipenghui left a comment

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
Contributor

/pulsarbot run-failure-checks

Copy link
Member

@wolfstudy wolfstudy left a comment

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");
Copy link
Contributor

@315157973 315157973 Mar 5, 2021

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
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
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
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
Copy link
Contributor

@eolivelli eolivelli left a comment

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
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

Copy link
Contributor Author

@linlinnn linlinnn Mar 8, 2021

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
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
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
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
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.

Copy link
Contributor

@eolivelli eolivelli left a comment

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
```

Copy link
Member

@Anonymitaet Anonymitaet Mar 8, 2021

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
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()
```

Copy link
Member

@Anonymitaet Anonymitaet Mar 8, 2021

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
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
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
Contributor Author

Choose a reason for hiding this comment

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

ok

Copy link
Member

@Anonymitaet Anonymitaet left a comment

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
Copy link
Contributor Author

linlinnn commented Mar 9, 2021

/pulsarbot run-failure-checks

@linlinnn
Copy link
Contributor Author

/pulsarbot run-failure-checks

@codelipenghui codelipenghui merged commit dd5c3b4 into apache:master Mar 10, 2021
@codelipenghui
Copy link
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