cadonna commented on code in PR #18870: URL: https://github.com/apache/kafka/pull/18870#discussion_r1952799227
########## clients/src/main/java/org/apache/kafka/clients/consumer/internals/StreamsGroupHeartbeatRequestManager.java: ########## @@ -0,0 +1,387 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.kafka.clients.consumer.internals; + +import org.apache.kafka.clients.CommonClientConfigs; +import org.apache.kafka.clients.consumer.ConsumerConfig; +import org.apache.kafka.clients.consumer.internals.events.BackgroundEventHandler; +import org.apache.kafka.clients.consumer.internals.metrics.HeartbeatMetricsManager; +import org.apache.kafka.common.TopicPartition; +import org.apache.kafka.common.message.StreamsGroupHeartbeatRequestData; +import org.apache.kafka.common.message.StreamsGroupHeartbeatResponseData; +import org.apache.kafka.common.metrics.Metrics; +import org.apache.kafka.common.protocol.Errors; +import org.apache.kafka.common.requests.StreamsGroupHeartbeatRequest; +import org.apache.kafka.common.requests.StreamsGroupHeartbeatResponse; +import org.apache.kafka.common.utils.LogContext; +import org.apache.kafka.common.utils.Time; +import org.apache.kafka.common.utils.Timer; + +import org.slf4j.Logger; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + + +public class StreamsGroupHeartbeatRequestManager implements RequestManager { + + static class HeartbeatState { + + private final StreamsMembershipManager membershipManager; + private final int rebalanceTimeoutMs; + + private final StreamsRebalanceData streamsRebalanceData; + + public HeartbeatState(final StreamsRebalanceData streamsRebalanceData, + final StreamsMembershipManager membershipManager, + final int rebalanceTimeoutMs) { + + this.membershipManager = membershipManager; + this.rebalanceTimeoutMs = rebalanceTimeoutMs; + this.streamsRebalanceData = streamsRebalanceData; + } + + public StreamsGroupHeartbeatRequestData buildRequestData() { + StreamsGroupHeartbeatRequestData data = new StreamsGroupHeartbeatRequestData(); + data.setGroupId(membershipManager.groupId()); + data.setMemberId(membershipManager.memberId()); + data.setMemberEpoch(membershipManager.memberEpoch()); + membershipManager.groupInstanceId().ifPresent(data::setInstanceId); + StreamsGroupHeartbeatRequestData.Topology topology = new StreamsGroupHeartbeatRequestData.Topology(); + topology.setSubtopologies(getTopologyFromStreams()); + topology.setEpoch(streamsRebalanceData.topologyEpoch()); + data.setRebalanceTimeoutMs(rebalanceTimeoutMs); + data.setTopology(topology); + data.setProcessId(streamsRebalanceData.processId().toString()); + data.setActiveTasks(Collections.emptyList()); + data.setStandbyTasks(Collections.emptyList()); + data.setWarmupTasks(Collections.emptyList()); + streamsRebalanceData.endpoint().ifPresent(userEndpoint -> { + data.setUserEndpoint(new StreamsGroupHeartbeatRequestData.Endpoint() + .setHost(userEndpoint.host()) + .setPort(userEndpoint.port()) + ); + }); + data.setClientTags(streamsRebalanceData.clientTags().entrySet().stream() Review Comment: Actually, the client tags are only sent with the first full request and they do not change afterwards. However, this is only true because the client tags are set in Streams trough a config which is constant. The KIP says that the client tags are not sent if they do not change. So I was thinking to implement the request manager in such a way that it follows closer the KIP and does not assume the client tags are constant. This is also true for process ID and endpoint. In any case I will consider this in the next PR since this PR is really just about sending the full request. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
