flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] zentol commented on a change in pull request #6702: [FLINK-10135] The JobManager does not report the cluster-level metrics
Date Mon, 08 Oct 2018 19:13:49 GMT
zentol commented on a change in pull request #6702: [FLINK-10135] The JobManager does not report
the cluster-level metrics
URL: https://github.com/apache/flink/pull/6702#discussion_r223468454
 
 

 ##########
 File path: flink-tests/src/test/java/org/apache/flink/runtime/metrics/JobManagerMetricsITCase.java
 ##########
 @@ -0,0 +1,221 @@
+/*
+ * 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.client.program.MiniClusterClient;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.metrics.Gauge;
+import org.apache.flink.metrics.MetricConfig;
+import org.apache.flink.metrics.reporter.AbstractReporter;
+import org.apache.flink.runtime.execution.Environment;
+import org.apache.flink.runtime.jobgraph.JobGraph;
+import org.apache.flink.runtime.jobgraph.JobStatus;
+import org.apache.flink.runtime.jobgraph.JobVertex;
+import org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable;
+import org.apache.flink.test.util.MiniClusterResource;
+import org.apache.flink.test.util.MiniClusterResourceConfiguration;
+
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.flink.configuration.MetricOptions.REPORTERS_LIST;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/**
+ * Integration tests for proper initialization of the job manager metrics.
+ */
+public class JobManagerMetricsITCase {
+
+	private static final String JOB_MANAGER_METRICS_PREFIX = "localhost.jobmanager.";
+	private static final String TASK_SLOTS_AVAILABLE = "taskSlotsAvailable";
+	private static final String TASK_SLOTS_TOTAL = "taskSlotsTotal";
+	private static final String NUM_REGISTERED_TASK_MANAGERS = "numRegisteredTaskManagers";
+	private static final String NUM_RUNNING_JOBS = "numRunningJobs";
+
+	private static CountDownLatch invokeLatch;
+
+	private MiniClusterClient clusterClient;
+	private JobGraph jobGraph;
+
+	@ClassRule
+	public static final MiniClusterResource MINI_CLUSTER_RESOURCE = new MiniClusterResource(
+		new MiniClusterResourceConfiguration.Builder()
+			.setConfiguration(getConfiguration())
+			.setNumberTaskManagers(1)
+			.setNumberSlotsPerTaskManager(1)
+			.build());
+
+	@Before
+	public void setUp() throws Exception {
+		invokeLatch = new CountDownLatch(1);
+
+		Assume.assumeTrue(
+			"ClusterClient is not an instance of MiniClusterClient",
+			MINI_CLUSTER_RESOURCE.getClusterClient() instanceof MiniClusterClient);
+
+		clusterClient = (MiniClusterClient) MINI_CLUSTER_RESOURCE.getClusterClient();
+		clusterClient.setDetached(true);
+
+		jobGraph = new JobGraph();
+
+		final JobVertex vertex = new JobVertex("testVertex");
+		vertex.setInvokableClass(NoOpBlockingInvokable.class);
+		jobGraph.addVertex(vertex);
+
+		clusterClient.submitJob(jobGraph, ClassLoader.getSystemClassLoader());
+		invokeLatch.await(60, TimeUnit.SECONDS);
+		waitForJob();
+	}
+
+	@Test
+	public void testJobManagerMetrics() throws Exception {
+		assertEquals(1, TestReporter.OPENED_REPORTERS.size());
+		TestReporter reporter = TestReporter.OPENED_REPORTERS.iterator().next();
+
+		List<String> expectedPatterns = getExpectedPatterns();
+
+		Collection<String> gaugeNames = reporter.getGauges().values();
+
+		for (String expectedPattern : expectedPatterns) {
+			boolean found = false;
+			for (String gaugeName : gaugeNames) {
+				if (gaugeName.matches(expectedPattern)) {
+					found = true;
+				}
+			}
+			if (!found) {
+				fail(String.format("Failed to find gauge [%s] in registered gauges [%s]",
+					expectedPattern, gaugeNames));
+			}
+		}
+
+		for (Map.Entry<Gauge<?>, String> entry : reporter.getGauges().entrySet()) {
+			if (entry.getValue().contains(TASK_SLOTS_AVAILABLE)) {
+				assertEquals(0L, entry.getKey().getValue());
+			} else if (entry.getValue().contains(TASK_SLOTS_TOTAL)) {
+				assertEquals(1L, entry.getKey().getValue());
+			} else if (entry.getValue().contains(NUM_REGISTERED_TASK_MANAGERS)) {
+				assertEquals(1L, entry.getKey().getValue());
+			} else if (entry.getValue().contains(NUM_RUNNING_JOBS)) {
+				assertEquals(1L, entry.getKey().getValue());
+			}
+		}
+	}
+
+	private static Configuration getConfiguration() {
+		Configuration configuration = new Configuration();
+		configuration.setString(REPORTERS_LIST, "test_reporter");
 
 Review comment:
   this configuration setting is not necessary anymore, reporter names are automatically detected

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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

Mime
View raw message