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 2019/04/08 09:26:55 UTC

[GitHub] [flink] tillrohrmann commented on a change in pull request #8002: [FLINK-11923][metrics] MetricRegistryConfiguration provides MetricReporters Suppliers

tillrohrmann commented on a change in pull request #8002: [FLINK-11923][metrics] MetricRegistryConfiguration provides MetricReporters Suppliers
URL: https://github.com/apache/flink/pull/8002#discussion_r272956271
 
 

 ##########
 File path: flink-runtime/src/test/java/org/apache/flink/runtime/metrics/ReporterSetupTest.java
 ##########
 @@ -0,0 +1,213 @@
+/*
+ * 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.configuration.ConfigConstants;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.MetricOptions;
+import org.apache.flink.metrics.MetricConfig;
+import org.apache.flink.metrics.reporter.MetricReporter;
+import org.apache.flink.runtime.metrics.util.TestReporter;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.List;
+import java.util.Optional;
+
+import static org.hamcrest.core.IsInstanceOf.instanceOf;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for the {@link ReporterSetup}.
+ */
+public class ReporterSetupTest extends TestLogger {
+
+	/**
+	 * TestReporter1 class only for type differentiation.
+	 */
+	static class TestReporter1 extends TestReporter {
+	}
+
+	/**
+	 * TestReporter2 class only for type differentiation.
+	 */
+	static class TestReporter2 extends TestReporter {
+	}
+
+	/**
+	 * Verifies that a reporter can be configured with all it's arguments being forwarded.
+	 */
+	@Test
+	public void testReporterArgumentForwarding() {
+		final Configuration config = new Configuration();
+
+		config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "reporter." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, ReporterSetupTest.TestReporter1.class.getName());
+		config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "reporter.arg1", "value1");
+		config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "reporter.arg2", "value2");
+
+		final List<ReporterSetup> reporterSetups = ReporterSetup.fromConfiguration(config);
+
+		Assert.assertEquals(1, reporterSetups.size());
+
+		final ReporterSetup reporterSetup = reporterSetups.get(0);
+		Assert.assertEquals("reporter", reporterSetup.getName());
+		Assert.assertEquals("value1", reporterSetup.getConfiguration().getString("arg1", null));
+		Assert.assertEquals("value2", reporterSetup.getConfiguration().getString("arg2", null));
+		Assert.assertEquals(ReporterSetupTest.TestReporter1.class.getName(), reporterSetup.getConfiguration().getString("class", null));
+	}
+
+	/**
+	 * Verifies that multiple reporters can be configured with all their arguments being forwarded.
+	 */
+	@Test
+	public void testSeveralReportersWithArgumentForwarding() {
+		final Configuration config = new Configuration();
+
+		config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "reporter1." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, ReporterSetupTest.TestReporter1.class.getName());
+		config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "reporter1.arg1", "value1");
+		config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "reporter1.arg2", "value2");
+
+		config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "reporter2." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, ReporterSetupTest.TestReporter2.class.getName());
+		config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "reporter2.arg1", "value1");
+		config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "reporter2.arg3", "value3");
+
+		final List<ReporterSetup> reporterSetups = ReporterSetup.fromConfiguration(config);
+
+		Assert.assertEquals(2, reporterSetups.size());
+
+		final Optional<ReporterSetup> reporter1Config = reporterSetups.stream()
+			.filter(c -> "reporter1".equals(c.getName()))
+			.findFirst();
+		Assert.assertTrue(reporter1Config.isPresent());
+		Assert.assertEquals("reporter1", reporter1Config.get().getName());
+		Assert.assertEquals("value1", reporter1Config.get().getConfiguration().getString("arg1", ""));
+		Assert.assertEquals("value2", reporter1Config.get().getConfiguration().getString("arg2", ""));
+		Assert.assertEquals(ReporterSetupTest.TestReporter1.class.getName(), reporter1Config.get().getConfiguration().getString("class", null));
+
+		final Optional<ReporterSetup> reporter2Config = reporterSetups.stream()
+			.filter(c -> "reporter2".equals(c.getName()))
+			.findFirst();
+		Assert.assertTrue(reporter1Config.isPresent());
+		Assert.assertEquals("reporter2", reporter2Config.get().getName());
+		Assert.assertEquals("value1", reporter2Config.get().getConfiguration().getString("arg1", null));
+		Assert.assertEquals("value3", reporter2Config.get().getConfiguration().getString("arg3", null));
+		Assert.assertEquals(ReporterSetupTest.TestReporter2.class.getName(), reporter2Config.get().getConfiguration().getString("class", null));
+	}
+
+	/**
+	 * Verifies that {@link MetricOptions#REPORTERS_LIST} is correctly used to filter configured reporters.
+	 */
+	@Test
+	public void testActivateOneReporterAmongTwoDeclared() {
+		final Configuration config = new Configuration();
+
+		config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "reporter1." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter1.class.getName());
+		config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "reporter1.arg1", "value1");
+		config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "reporter1.arg2", "value2");
+
+		config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "reporter2." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter2.class.getName());
+		config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "reporter2.arg1", "value1");
+		config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "reporter2.arg3", "value3");
 
 Review comment:
   The setup code could be factored out because it seems to be duplicate code.

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


With regards,
Apache Git Services