Search in sources :

Example 1 with ConsumerSummary

use of io.confluent.ksql.services.KafkaConsumerGroupClient.ConsumerSummary in project ksql by confluentinc.

the class ListTopicsExecutor method getTopicConsumerAndGroupCounts.

/**
 * @return all topics with their associated consumerCount and consumerGroupCount
 */
private static Map<String, List<Integer>> getTopicConsumerAndGroupCounts(final KafkaConsumerGroupClient consumerGroupClient) {
    final List<String> consumerGroups = consumerGroupClient.listGroups();
    final Map<String, AtomicInteger> topicConsumerCount = new HashMap<>();
    final Map<String, Set<String>> topicConsumerGroupCount = new HashMap<>();
    for (final String group : consumerGroups) {
        final Collection<ConsumerSummary> consumerSummaryList = consumerGroupClient.describeConsumerGroup(group).consumers();
        for (final KafkaConsumerGroupClientImpl.ConsumerSummary summary : consumerSummaryList) {
            for (final TopicPartition topicPartition : summary.partitions()) {
                topicConsumerCount.computeIfAbsent(topicPartition.topic(), k -> new AtomicInteger()).incrementAndGet();
                topicConsumerGroupCount.computeIfAbsent(topicPartition.topic(), k -> new HashSet<>()).add(group);
            }
        }
    }
    final HashMap<String, List<Integer>> results = new HashMap<>();
    topicConsumerCount.forEach((k, v) -> {
        results.computeIfAbsent(k, v1 -> new ArrayList<>()).add(v.intValue());
        results.get(k).add(topicConsumerGroupCount.get(k).size());
    });
    return results;
}
Also used : Arrays(java.util.Arrays) SessionProperties(io.confluent.ksql.rest.SessionProperties) ListTopics(io.confluent.ksql.parser.tree.ListTopics) ServiceContext(io.confluent.ksql.services.ServiceContext) ConsumerSummary(io.confluent.ksql.services.KafkaConsumerGroupClient.ConsumerSummary) HashMap(java.util.HashMap) KafkaTopicsList(io.confluent.ksql.rest.entity.KafkaTopicsList) KafkaTopicsListExtended(io.confluent.ksql.rest.entity.KafkaTopicsListExtended) ReservedInternalTopics(io.confluent.ksql.util.ReservedInternalTopics) KafkaTopicClient(io.confluent.ksql.services.KafkaTopicClient) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) TopicDescription(org.apache.kafka.clients.admin.TopicDescription) TopicPartition(org.apache.kafka.common.TopicPartition) KafkaConsumerGroupClientImpl(io.confluent.ksql.services.KafkaConsumerGroupClientImpl) Collection(java.util.Collection) Set(java.util.Set) ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) Collectors(java.util.stream.Collectors) List(java.util.List) TreeMap(java.util.TreeMap) KsqlExecutionContext(io.confluent.ksql.KsqlExecutionContext) KafkaConsumerGroupClient(io.confluent.ksql.services.KafkaConsumerGroupClient) KafkaTopicInfoExtended(io.confluent.ksql.rest.entity.KafkaTopicInfoExtended) KafkaTopicInfo(io.confluent.ksql.rest.entity.KafkaTopicInfo) Optional(java.util.Optional) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ConsumerSummary(io.confluent.ksql.services.KafkaConsumerGroupClient.ConsumerSummary) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KafkaConsumerGroupClientImpl(io.confluent.ksql.services.KafkaConsumerGroupClientImpl) TopicPartition(org.apache.kafka.common.TopicPartition) KafkaTopicsList(io.confluent.ksql.rest.entity.KafkaTopicsList) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Aggregations

KsqlExecutionContext (io.confluent.ksql.KsqlExecutionContext)1 ListTopics (io.confluent.ksql.parser.tree.ListTopics)1 SessionProperties (io.confluent.ksql.rest.SessionProperties)1 KafkaTopicInfo (io.confluent.ksql.rest.entity.KafkaTopicInfo)1 KafkaTopicInfoExtended (io.confluent.ksql.rest.entity.KafkaTopicInfoExtended)1 KafkaTopicsList (io.confluent.ksql.rest.entity.KafkaTopicsList)1 KafkaTopicsListExtended (io.confluent.ksql.rest.entity.KafkaTopicsListExtended)1 KafkaConsumerGroupClient (io.confluent.ksql.services.KafkaConsumerGroupClient)1 ConsumerSummary (io.confluent.ksql.services.KafkaConsumerGroupClient.ConsumerSummary)1 KafkaConsumerGroupClientImpl (io.confluent.ksql.services.KafkaConsumerGroupClientImpl)1 KafkaTopicClient (io.confluent.ksql.services.KafkaTopicClient)1 ServiceContext (io.confluent.ksql.services.ServiceContext)1 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)1 ReservedInternalTopics (io.confluent.ksql.util.ReservedInternalTopics)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1