Copilot commented on code in PR #23703:
URL: https://github.com/apache/kafka/pull/23703#discussion_r4540633292
##########
clients/src/main/java/org/apache/kafka/common/telemetry/internals/ClientTelemetryReporter.java:
##########
@@ -495,10 +501,14 @@ public void handleResponse(PushTelemetryResponse
response) {
lock.writeLock().lock();
try {
/*
- This is the case when client began termination sometime after
the last push request
- was issued. Just getting the callback, hence need to ignore
it.
+ This is the case when client began termination some time
after the last push request
+ was issued. Just getting the callback, hence need to ignore
it. If the terminating
+ push itself has been issued, this response completes it.
*/
if (isTerminatingState()) {
+ if (state ==
ClientTelemetryState.TERMINATING_PUSH_IN_PROGRESS) {
+ terminatingPushCompleted = true;
Review Comment:
A regular push can still be outstanding when the terminating push is issued,
so its response or failure can incorrectly mark the terminating push complete
and let the admin client close the connection prematurely. Correlate completion
with the actual terminating request, or serialize it behind the earlier push.
The same issue affects the failure callback at line 550.
##########
clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java:
##########
@@ -1534,6 +1565,10 @@ private boolean hasActiveExternalCalls() {
private boolean threadShouldExit(long now, long curHardShutdownTimeMs)
{
if (!hasActiveExternalCalls()) {
+ if (isTerminatingTelemetryPushPending(now)) {
Review Comment:
When no external calls remain, this branch waits for telemetry even after
the hard shutdown deadline expires. A short close timeout leaves the I/O thread
running past the caller's deadline, and `close(Duration.ZERO)` can block for
the full request timeout because it calls `join(0)`. Only wait for telemetry
while the hard shutdown deadline has not expired.
##########
clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java:
##########
@@ -1593,6 +1628,10 @@ private void processRequests() {
if (curHardShutdownTimeMs != INVALID_SHUTDOWN_TIME) {
pollTimeout = Math.min(pollTimeout, curHardShutdownTimeMs
- now);
}
+ long terminatingPushDeadlineMs =
terminatingTelemetryPushDeadlineMs.get();
+ if (terminatingPushDeadlineMs != INVALID_SHUTDOWN_TIME) {
+ pollTimeout = Math.min(pollTimeout, Math.max(0,
terminatingPushDeadlineMs - now));
Review Comment:
Once the telemetry deadline expires, this permanently sets the poll timeout
to zero. External admin calls can still be active beyond that deadline (for
example, retries under a longer API timeout), so the I/O thread busy-spins
until those calls finish or the hard shutdown deadline expires. Stop applying
this poll-timeout cap after the telemetry deadline has elapsed.
##########
clients/clients-integration-tests/src/test/java/org/apache/kafka/clients/admin/ClientTelemetryTest.java:
##########
@@ -132,9 +154,210 @@ public void testMetrics(ClusterInstance clusterInstance) {
}
}
+ @ClusterTest(
+ types = Type.KRAFT,
+ serverProperties = {
+ @ClusterConfigProperty(key = METRIC_REPORTER_CLASSES_CONFIG,
value = TELEMETRY_EXPORTER),
+ })
+ public void testProducerMetricsPush(ClusterInstance clusterInstance)
throws Exception {
+ clusterInstance.createTopic(TOPIC, 1, (short) 1);
+ createSubscription(clusterInstance, "producer-metrics",
PRODUCER_METRICS_PREFIX, Optional.empty());
+
+ Uuid clientInstanceId;
+ try (Producer<byte[], byte[]> producer = clusterInstance.producer()) {
+ producer.send(new ProducerRecord<>(TOPIC,
"value".getBytes())).get();
+ clientInstanceId =
producer.clientInstanceId(Duration.ofSeconds(10));
+ assertNotNull(clientInstanceId);
+
+ // Wait for two pushes so that the regular push interval, not just
the initial push, is exercised.
+ List<PushedMetrics> pushes = waitForPushes(clientInstanceId, 2);
+ PushedMetrics push = pushes.get(0);
Review Comment:
The first telemetry push can precede the first produce request and therefore
omit per-topic metrics, which are registered by
`SenderMetrics.updateProduceRequestMetrics`. Waiting for two pushes still
selects that first snapshot, so the per-topic assertion can fail under
scheduling or metadata delays. Wait for and select a push containing the
per-topic metric instead.
--
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]