You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2020/07/13 13:15:29 UTC

[GitHub] [flink] zentol commented on a change in pull request #12883: [FLINK-18573][metrics] Ensure metric reporters could be loaded via SPI

zentol commented on a change in pull request #12883:
URL: https://github.com/apache/flink/pull/12883#discussion_r453633452



##########
File path: flink-runtime/src/test/java/org/apache/flink/runtime/metrics/MetricReporterSetupTestBase.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.runtime.metrics;
+
+import org.apache.flink.metrics.reporter.MetricReporterFactory;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * The base class to verify metric reporter factory.
+ */
+public abstract class MetricReporterSetupTestBase extends TestLogger {
+
+	@Test
+	public void testMetricReporterSetupViaSPI() {
+		Iterator<MetricReporterFactory> factoryIterator = ReporterSetup.getAllReporterFactoriesViaSPI();

Review comment:
       It would be good to get rid of the dependency to flink-runtime; this change goes contrary to our goals of separating the metric modules from flink-runtime.
   The ServiceLoader mechanism is standardized, so it's fine to just call `ServiceLoader.load(MetricReporterFactory.class).iterator()` here.

##########
File path: flink-metrics/flink-metrics-prometheus/src/test/java/org/apache/flink/metrics/prometheus/PrometheusMetricReporterFactoryTest.java
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.metrics.prometheus;
+
+import org.apache.flink.metrics.reporter.MetricReporterFactory;
+import org.apache.flink.runtime.metrics.MetricReporterSetupTestBase;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Tests for loading the {@link PrometheusPushGatewayReporterFactory} and {@link PrometheusReporterFactory}.
+ */
+public class PrometheusMetricReporterFactoryTest extends MetricReporterSetupTestBase {

Review comment:
       redundant as we have a e2e test covering it, which is preferable. I'd only add this to reporters that are not otherwise covered as a band-aid.

##########
File path: flink-metrics/flink-metrics-slf4j/src/test/java/org/apache/flink/metrics/slf4j/Slf4jReporterFactoryTest.java
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.metrics.slf4j;
+
+import org.apache.flink.metrics.reporter.MetricReporterFactory;
+import org.apache.flink.runtime.metrics.MetricReporterSetupTestBase;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Tests for loading the {@link Slf4jReporterFactory}.
+ */
+public class Slf4jReporterFactoryTest extends MetricReporterSetupTestBase {
+
+	@Override
+	protected List<Class<? extends MetricReporterFactory>> getMetricReporterFactoryClass() {

Review comment:
       redundant due to usage in e2e tests.

##########
File path: flink-runtime/src/test/java/org/apache/flink/runtime/metrics/MetricReporterSetupTestBase.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.runtime.metrics;
+
+import org.apache.flink.metrics.reporter.MetricReporterFactory;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * The base class to verify metric reporter factory.
+ */
+public abstract class MetricReporterSetupTestBase extends TestLogger {
+
+	@Test
+	public void testMetricReporterSetupViaSPI() {
+		Iterator<MetricReporterFactory> factoryIterator = ReporterSetup.getAllReporterFactoriesViaSPI();
+		Set<String> metricReporterFactoryClasses = getMetricReporterFactoryClass().stream().map(Class::getCanonicalName).collect(Collectors.toSet());
+		assertFalse(metricReporterFactoryClasses.isEmpty());
+		while (factoryIterator.hasNext()) {
+			MetricReporterFactory metricReporterFactory = factoryIterator.next();

Review comment:
       ```
   public static void testMetricReporterSetupViaSPI(Class<MetricReporterFactory> clazz) {
   	Set<Class<? extends MetricReporterFactory>> loadedFactories = StreamSupport
   		.stream(ServiceLoader.load(MetricReporterFactory.class).iterator(), false)
   		.map(MetricReporterFactory::getClass)
   		.collect(Collectors.toSet());
   	assertThat(loadedFactories , hasItems(clazz));
   }
   ```

##########
File path: flink-runtime/src/test/java/org/apache/flink/runtime/metrics/MetricReporterSetupTestBase.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.runtime.metrics;
+
+import org.apache.flink.metrics.reporter.MetricReporterFactory;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * The base class to verify metric reporter factory.
+ */
+public abstract class MetricReporterSetupTestBase extends TestLogger {

Review comment:
       Let's not introduce inheritance for this. The test could just be a method that is being called with the factory class.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org