-
Notifications
You must be signed in to change notification settings - Fork 10
Add integration test for MirrorMaker connectors #89
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
Changes from all commits
a998990
f4f22d3
70190da
0e03d43
3d1038e
d54c1e9
d88adbf
b568ab2
ad7da1b
850cf74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
/* | ||
* Copyright Strimzi authors. | ||
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). | ||
*/ | ||
package io.strimzi.kafka.metrics.prometheus.integration; | ||
|
||
import io.strimzi.kafka.metrics.prometheus.ClientMetricsReporter; | ||
import io.strimzi.kafka.metrics.prometheus.ClientMetricsReporterConfig; | ||
import io.strimzi.kafka.metrics.prometheus.MetricsUtils; | ||
import io.strimzi.kafka.metrics.prometheus.http.Listener; | ||
import io.strimzi.test.container.StrimziConnectCluster; | ||
import io.strimzi.test.container.StrimziKafkaCluster; | ||
import org.apache.kafka.clients.CommonClientConfigs; | ||
import org.apache.kafka.clients.admin.Admin; | ||
import org.apache.kafka.clients.admin.AdminClientConfig; | ||
import org.apache.kafka.clients.admin.NewTopic; | ||
import org.apache.kafka.clients.consumer.OffsetAndMetadata; | ||
import org.apache.kafka.clients.producer.KafkaProducer; | ||
import org.apache.kafka.clients.producer.ProducerConfig; | ||
import org.apache.kafka.clients.producer.ProducerRecord; | ||
import org.apache.kafka.common.TopicPartition; | ||
import org.apache.kafka.common.serialization.StringSerializer; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.wait.strategy.HttpWaitStrategy; | ||
import org.testcontainers.utility.MountableFile; | ||
|
||
import java.net.HttpURLConnection; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
||
public class TestMirrorMakerMetricsIT { | ||
|
||
private static final int PORT = Listener.parseListener(ClientMetricsReporterConfig.LISTENER_CONFIG_DEFAULT).port; | ||
private static final String CONNECT_ID = "my-cluster"; | ||
private static final String TOPIC = "input"; | ||
private static final String GROUP = "my-group"; | ||
private static final String SOURCE_CONNECTOR = "source"; | ||
private static final String CHECKPOINT_CONNECTOR = "checkpoint"; | ||
|
||
private StrimziKafkaCluster kafka; | ||
private StrimziConnectCluster connect; | ||
|
||
@BeforeEach | ||
public void setUp() throws Exception { | ||
// Use a single cluster as source and target | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmmm, when you also used the target Kafka cluster, it didn't work, I assume (why?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be honest I don't really know. I'm wondering if it may have been a resources issue. It seems out of the 2 pipelines (Java 11 and 17) each time a random one would pass and the other fail. Since we don't effectively need 2 Kafka clusters, I opted to use a single one, that also simplified the test slightly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think that's not a problem for sure. As we have in
But locally, it was okay, I assume? I was just curious, if that is okay with you, I am fine with that (to have just one Kafka cluster as source/target). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've run this test 100s of times locally and it was consistently passing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note also the failures we saw in the CI were always in the test setup, the MirrorMakerSource connector tasks were not starting in time. It was not a failure to collect and emit metrics in the reporter. |
||
// MirrorSourceConnector is configured with a fixed topics configuration to avoid loop | ||
kafka = new StrimziKafkaCluster.StrimziKafkaClusterBuilder() | ||
.withNumberOfBrokers(1) | ||
.withSharedNetwork() | ||
.build(); | ||
kafka.start(); | ||
|
||
connect = new StrimziConnectCluster.StrimziConnectClusterBuilder() | ||
.withGroupId(CONNECT_ID) | ||
.withKafkaCluster(kafka) | ||
.withAdditionalConnectConfiguration(Map.of( | ||
CommonClientConfigs.METRIC_REPORTER_CLASSES_CONFIG, ClientMetricsReporter.class.getName() | ||
)) | ||
.build(); | ||
|
||
for (GenericContainer<?> worker : connect.getWorkers()) { | ||
worker.withCopyFileToContainer(MountableFile.forHostPath(MetricsUtils.REPORTER_JARS), MetricsUtils.MOUNT_PATH) | ||
.withExposedPorts(8083, PORT) | ||
.withEnv(Map.of("CLASSPATH", MetricsUtils.MOUNT_PATH + "*")) | ||
.waitingFor(new HttpWaitStrategy() | ||
.forPath("/health") | ||
.forStatusCode(HttpURLConnection.HTTP_OK)); | ||
} | ||
connect.start(); | ||
|
||
try (Admin admin = Admin.create(Map.of(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, kafka.getBootstrapServers()))) { | ||
// Create a topic with 2 partitions so we get 2 MirrorSourceConnector tasks | ||
admin.createTopics(List.of(new NewTopic(TOPIC, 2, (short) -1))).all().get(); | ||
// Create 2 consumer groups so we get 2 MirrorCheckpointConnector tasks | ||
admin.alterConsumerGroupOffsets(GROUP, Map.of(new TopicPartition(TOPIC, 0), new OffsetAndMetadata(1))).all().get(); | ||
admin.alterConsumerGroupOffsets(GROUP + "-2", Map.of(new TopicPartition(TOPIC, 0), new OffsetAndMetadata(1))).all().get(); | ||
} | ||
try (KafkaProducer<String, String> producer = new KafkaProducer<>(Map.of( | ||
ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, kafka.getBootstrapServers(), | ||
ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName(), | ||
ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName() | ||
))) { | ||
for (int i = 0; i < 5; i++) { | ||
producer.send(new ProducerRecord<>(TOPIC, i % 2, null, "record" + i)); | ||
} | ||
} | ||
} | ||
|
||
@AfterEach | ||
public void tearDown() { | ||
if (connect != null) { | ||
connect.stop(); | ||
} | ||
if (kafka != null) { | ||
kafka.stop(); | ||
} | ||
} | ||
|
||
@Test | ||
public void testMirrorMakerConnectorMetrics() { | ||
// Start MirrorSourceConnector and check its metrics | ||
String sourceTags = ".*partition=\"\\d+\",source=\"source\",target=\"target\",topic=\"source.input\".*"; | ||
List<String> sourceMetricsPatterns = List.of( | ||
"kafka_connect_mirror_mirrorsourceconnector_byte_count" + sourceTags, | ||
"kafka_connect_mirror_mirrorsourceconnector_byte_rate" + sourceTags, | ||
"kafka_connect_mirror_mirrorsourceconnector_record_age_ms" + sourceTags, | ||
"kafka_connect_mirror_mirrorsourceconnector_record_age_ms_avg" + sourceTags, | ||
"kafka_connect_mirror_mirrorsourceconnector_record_age_ms_max" + sourceTags, | ||
"kafka_connect_mirror_mirrorsourceconnector_record_age_ms_min" + sourceTags, | ||
"kafka_connect_mirror_mirrorsourceconnector_record_count" + sourceTags, | ||
"kafka_connect_mirror_mirrorsourceconnector_record_rate" + sourceTags, | ||
"kafka_connect_mirror_mirrorsourceconnector_replication_latency_ms" + sourceTags, | ||
"kafka_connect_mirror_mirrorsourceconnector_replication_latency_ms_avg" + sourceTags, | ||
"kafka_connect_mirror_mirrorsourceconnector_replication_latency_ms_max" + sourceTags, | ||
"kafka_connect_mirror_mirrorsourceconnector_replication_latency_ms_min" + sourceTags | ||
); | ||
String sourceConfig = | ||
"{\n" + | ||
" \"name\": \"" + SOURCE_CONNECTOR + "\",\n" + | ||
" \"connector.class\": \"org.apache.kafka.connect.mirror.MirrorSourceConnector\",\n" + | ||
" \"tasks.max\": \"2\",\n" + | ||
" \"key.converter\": \"org.apache.kafka.connect.converters.ByteArrayConverter\",\n" + | ||
" \"value.converter\": \"org.apache.kafka.connect.converters.ByteArrayConverter\",\n" + | ||
" \"source.cluster.alias\": \"source\",\n" + | ||
" \"target.cluster.alias\": \"target\",\n" + | ||
" \"source.cluster.bootstrap.servers\": \"" + kafka.getNetworkBootstrapServers() + "\",\n" + | ||
" \"target.cluster.bootstrap.servers\": \"" + kafka.getNetworkBootstrapServers() + "\",\n" + | ||
" \"replication.factor\": \"-1\",\n" + | ||
" \"offset-syncs.topic.replication.factor\": \"-1\",\n" + | ||
" \"refresh.topics.interval.seconds\": \"1\",\n" + | ||
" \"topics\": \"" + TOPIC + "\",\n" + | ||
" \"metric.reporters\": \"" + ClientMetricsReporter.class.getName() + "\",\n" + | ||
" \"prometheus.metrics.reporter.listener.enable\": \"false\"" + | ||
"}"; | ||
MetricsUtils.startConnector(connect, SOURCE_CONNECTOR, sourceConfig, 2); | ||
checkMetricsExist(sourceMetricsPatterns); | ||
|
||
// Start MirrorCheckpointConnector and check its metrics | ||
String checkpointTags = ".*group=\".*\",partition=\"\\d+\",source=\"source\",target=\"target\",topic=\"source.input\".*"; | ||
List<String> checkpointMetricPatterns = List.of( | ||
"kafka_connect_mirror_mirrorcheckpointconnector_checkpoint_latency_ms" + checkpointTags, | ||
"kafka_connect_mirror_mirrorcheckpointconnector_checkpoint_latency_ms_avg" + checkpointTags, | ||
"kafka_connect_mirror_mirrorcheckpointconnector_checkpoint_latency_ms_max" + checkpointTags, | ||
"kafka_connect_mirror_mirrorcheckpointconnector_checkpoint_latency_ms_min" + checkpointTags | ||
); | ||
String checkpointConfig = | ||
"{\n" + | ||
" \"name\": \"" + CHECKPOINT_CONNECTOR + "\",\n" + | ||
" \"connector.class\": \"org.apache.kafka.connect.mirror.MirrorCheckpointConnector\",\n" + | ||
" \"tasks.max\": \"2\",\n" + | ||
" \"key.converter\": \"org.apache.kafka.connect.converters.ByteArrayConverter\",\n" + | ||
" \"value.converter\": \"org.apache.kafka.connect.converters.ByteArrayConverter\",\n" + | ||
" \"source.cluster.alias\": \"source\",\n" + | ||
" \"target.cluster.alias\": \"target\",\n" + | ||
" \"source.cluster.bootstrap.servers\": \"" + kafka.getNetworkBootstrapServers() + "\",\n" + | ||
" \"target.cluster.bootstrap.servers\": \"" + kafka.getNetworkBootstrapServers() + "\",\n" + | ||
" \"checkpoints.topic.replication.factor\": \"-1\",\n" + | ||
" \"emit.checkpoints.interval.seconds\": \"1\",\n" + | ||
" \"refresh.groups.interval.seconds\": \"1\",\n" + | ||
" \"metric.reporters\": \"" + ClientMetricsReporter.class.getName() + "\",\n" + | ||
" \"prometheus.metrics.reporter.listener.enable\": \"false\"" + | ||
"}"; | ||
MetricsUtils.startConnector(connect, CHECKPOINT_CONNECTOR, checkpointConfig, 2); | ||
checkMetricsExist(checkpointMetricPatterns); | ||
} | ||
|
||
private void checkMetricsExist(List<String> patterns) { | ||
for (GenericContainer<?> worker : connect.getWorkers()) { | ||
MetricsUtils.verify(worker, patterns, PORT, metrics -> assertFalse(metrics.isEmpty())); | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.