Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ protected void finalOffsetCommit(boolean failed) {
@Override
public void removeMetrics() {
Utils.closeQuietly(transactionMetrics, "source task transaction metrics tracker");
super.removeMetrics();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.RecordMetadata;
import org.apache.kafka.common.KafkaException;
import org.apache.kafka.common.MetricName;
import org.apache.kafka.common.TopicPartition;
import org.apache.kafka.common.errors.InvalidTopicException;
import org.apache.kafka.common.errors.RecordTooLargeException;
Expand Down Expand Up @@ -82,7 +83,9 @@
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import static java.util.Collections.emptySet;
import static org.apache.kafka.connect.integration.MonitorableSourceConnector.TOPIC_CONFIG;
import static org.apache.kafka.connect.runtime.ConnectorConfig.CONNECTOR_CLASS_CONFIG;
import static org.apache.kafka.connect.runtime.ConnectorConfig.KEY_CONVERTER_CLASS_CONFIG;
Expand Down Expand Up @@ -291,6 +294,23 @@ private void createWorkerTask(TargetState initialState, Converter keyConverter,
sourceConfig, Runnable::run, preProducerCheck, postProducerCheck);
}

@Test
public void testRemoveMetrics() {
createWorkerTask();

workerTask.removeMetrics();

assertEquals(emptySet(), filterToTaskMetrics(metrics.metrics().metrics().keySet()));
}

private Set<MetricName> filterToTaskMetrics(Set<MetricName> metricNames) {
return metricNames
.stream()
.filter(m -> metrics.registry().taskGroupName().equals(m.group())
|| metrics.registry().sourceTaskGroupName().equals(m.group()))
.collect(Collectors.toSet());
}

@Test
public void testStartPaused() throws Exception {
createWorkerTask(TargetState.PAUSED);
Expand Down