zentol commented on code in PR #19649: URL: https://github.com/apache/flink/pull/19649#discussion_r865639059
########## flink-connectors/flink-connector-kafka/src/test/java/org/apache/flink/streaming/connectors/kafka/internals/metrics/KafkaMetricsITCase.java: ########## @@ -0,0 +1,90 @@ +/* + * 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.flink.streaming.connectors.kafka.internals.metrics; + +import org.apache.flink.util.TestLoggerExtension; + +import org.apache.kafka.clients.consumer.KafkaConsumer; +import org.apache.kafka.clients.producer.KafkaProducer; +import org.apache.kafka.common.serialization.ByteArrayDeserializer; +import org.apache.kafka.common.serialization.ByteArraySerializer; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testcontainers.containers.KafkaContainer; +import org.testcontainers.containers.Network; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Properties; +import java.util.UUID; + +import static org.apache.flink.connector.kafka.testutils.KafkaUtil.createKafkaContainer; +import static org.apache.flink.util.DockerImageVersions.KAFKA; + +@Testcontainers +@ExtendWith(TestLoggerExtension.class) +class KafkaMetricsITCase { + + private static final Logger LOG = LoggerFactory.getLogger(KafkaMetricsITCase.class); + private static final String INTER_CONTAINER_KAFKA_ALIAS = "kafka"; + private static final Network NETWORK = Network.newNetwork(); + + @Container + public static final KafkaContainer KAFKA_CONTAINER = + createKafkaContainer(KAFKA, LOG) + .withEmbeddedZookeeper() + .withNetwork(NETWORK) + .withNetworkAliases(INTER_CONTAINER_KAFKA_ALIAS); + + @Test + void testOnlyMeasurableMetricsAreRegistered() { + final Collection<KafkaMetricMutableWrapper> metricWrappers = new ArrayList<>(); + final KafkaConsumer<?, ?> consumer = new KafkaConsumer<>(getKafkaClientConfiguration()); + final KafkaProducer<?, ?> producer = new KafkaProducer<>(getKafkaClientConfiguration()); + consumer.metrics() + .forEach( + (name, metric) -> + metricWrappers.add(new KafkaMetricMutableWrapper(metric))); + producer.metrics() + .forEach( + (name, metric) -> + metricWrappers.add(new KafkaMetricMutableWrapper(metric))); + + // Ensure that all values are accessible and return valid double values + metricWrappers.forEach(KafkaMetricMutableWrapper::getValue); Review Comment: We should also double-check that metricWrappers is not empty. -- 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: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org