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

How to get a list of consumer groups? #517

Closed
marghidanu opened this issue Oct 7, 2019 · 13 comments
Closed

How to get a list of consumer groups? #517

marghidanu opened this issue Oct 7, 2019 · 13 comments

Comments

@marghidanu
Copy link

Is there a way to obtain a list of consumer groups using the current Admin API?

@tulios
Copy link
Owner

tulios commented Oct 8, 2019

We currently don't have a way to list of consumer groups, but this is a feature we want to add at some point.

@marghidanu
Copy link
Author

Thanks! That would be great, I'm currently writing a lag monitoring application for our project and this would be a nice feature to have. Currently I have to manually provide the consumer group id, but it would be nice to be able to retrieve it via the Admin API.

@JaapRood
Copy link
Collaborator

JaapRood commented Oct 8, 2019

For anyone who's keen, this would actually be a pretty good start to contributing (beyond something like documentation, etc). It's pretty much a one off request with the Kafka protocol, all the utilities of which are already in place!

@HunderlineK
Copy link

I had a very noob question, how does kafkajs invoke the kafka APIs? Is it through RPC or REST? I was trying to find the starting point of the connection to the brokers in the source could, but was unsuccessful >~< Thanks!

@Delapouite
Copy link

@HunderlineK kafkajs use a socket. See the network code in this dir: https://github.com/tulios/kafkajs/tree/master/src/network

@tulios
Copy link
Owner

tulios commented Dec 17, 2019

Hi @HunderlineK, Kafka has its protocol on top of TCP. In KafkaJS, you have the network layer which is responsible for the socket connection, and the protocol layer, which works encoding and decoding the binary payloads returned by Kafka. The closest thing to a rest client in the library is the broker, which uses the connection and the protocol to interact with Kafka.

You can take a look at the broker code here:
https://github.com/tulios/kafkajs/blob/master/src/broker/index.js

You can find the protocol requests here:
https://github.com/tulios/kafkajs/tree/master/src/protocol/requests

And the network code here:
https://github.com/tulios/kafkajs/tree/master/src/network

@HunderlineK
Copy link

Oh, I think now I understand why developing a modern JavaScript Kafka client has been such an undertaking!

If I have understood the implementation correctly, all the helper functions are already provided, so this will only require, concretely speaking, creating a new folder under protocol/requests called ListGroups and implementing request and response handlers?

For each API, you need to first encode the message into bits based on its signature and then decode the response from bits. For each version of the API, we will also need a corresponding encoder/decoder? Though it seems sometimes one of them e.g. the request signature, remains the same across different versions.

Maybe I haven't noticed this, but all of the parameters are always required, correct? As in, we don't have situations where first we need to check the initial bits of the response in order to find out exactly what parameters we should be reading? (Or, set some initial bits in the request to specify what parameters we will be providing?)

Thanks.

@tulios
Copy link
Owner

tulios commented Dec 18, 2019

@HunderlineK everything you will need is already in KafkaJS, the encoder and decoder can generate all types the Kafka protocol needs. The workflow is exactly what you have mentioned before, first you create a folder with the protocol method you want to implement, in this case, request/ListGroups. In there, you add all versions up to Kafka v1. Then you add your new protocol method in the list of available requests (https://github.com/tulios/kafkajs/blob/master/src/protocol/requests/index.js#L4). Finally, you add a method to the broker class.

Even if the parameters are optional they get encoded in the protocol. The list offsets is a good example for you (https://github.com/tulios/kafkajs/blob/master/src/protocol/requests/listOffsets/v2/request.js)

I can help you land a PR, you can create a proposal PR in GitHub, and we can bounce ideas there.

@HunderlineK
Copy link

HunderlineK commented Jan 2, 2020

@tulios So I've started implementing this; one thing I've noticed is that this particular ListGroups API does not accept any input, so after a bit of digging I found this:

The purpose of the ListGroups API is to get a simple list of the groups that are managed by each broker. To get a list of all groups in the cluster, tools will have to query each broker separately and combine the results.
https://cwiki.apache.org/confluence/display/KAFKA/KIP-40%3A+ListGroups+and+DescribeGroup#KIP-40:ListGroupsandDescribeGroup-Motivation

I'm somewhat lost, as I'm not sure exactly how we can specify the broker?

Looking at a couple of other implementations, they approach it differently:

(I prefer Sarama approach; the user of the library can easily iterate over the brokers if they need all of the consumer groups)

@Nevon
Copy link
Collaborator

Nevon commented Jan 4, 2020

I think kafka-node's approach makes more sense. We shouldn't offload that responsibility to the user, unless there's a compelling reason to.

I think the cluster has all the information you need - the current metadata with the broker's node id, and methods for retrieving those brokers. cluster.metadata() and cluster.findBroker(). That gives you a Broker instance per broker, where you'd make the ListGroups call.

@JaapRood
Copy link
Collaborator

JaapRood commented Jan 6, 2020

I think kafka-node's approach makes more sense. We shouldn't offload that responsibility to the user, unless there's a compelling reason to.

Couldn't agree more. As far as the user should be concerned, you're talking to the Kafka Cluster. Brokers should be an implementation detail of that as much as possible (not possible everywhere, like the amount of acks in producing message, where you'd have to think about the fact that there are individual Brokers). Querying all brokers and aggregating seems like a straightforward way to achieve that in this case.

@lafeuil
Copy link
Contributor

lafeuil commented Nov 3, 2020

I think this issue can be closed. This is fixed in release 1.13 and PR #645.

@Nevon
Copy link
Collaborator

Nevon commented Nov 3, 2020

Yes indeed. Closing.

@Nevon Nevon closed this as completed Nov 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants