[ 
https://issues.apache.org/jira/browse/FLINK-10135?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16642334#comment-16642334
 ] 

ASF GitHub Bot commented on FLINK-10135:
----------------------------------------

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_r223469702
 
 

 ##########
 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");
+               configuration.setString("metrics.reporter.test_reporter.class", 
TestReporter.class.getName());
+               return configuration;
+       }
+
+       private void waitForJob() throws Exception {
 
 Review comment:
   This method should be called `waitForJobRunning()`; however this entire 
logic can be implemented more nicely with a 
[BlockerSync](https://github.com/apache/flink/blob/master/flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/core/testutils/BlockerSync.java)
 anyway. The UDF would wait until the test thread calls `block`, and then you 
reverse this for unblocking the thread.
   
   This method could then be removed.

----------------------------------------------------------------
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:
us...@infra.apache.org


> The JobManager doesn't report the cluster-level metrics
> -------------------------------------------------------
>
>                 Key: FLINK-10135
>                 URL: https://issues.apache.org/jira/browse/FLINK-10135
>             Project: Flink
>          Issue Type: Bug
>          Components: JobManager, Metrics
>    Affects Versions: 1.5.0, 1.6.0, 1.7.0
>            Reporter: Joey Echeverria
>            Assignee: vinoyang
>            Priority: Critical
>              Labels: pull-request-available
>
> In [the documentation for 
> metrics|https://ci.apache.org/projects/flink/flink-docs-release-1.5/monitoring/metrics.html#cluster]
>  in the Flink 1.5.0 release, it says that the following metrics are reported 
> by the JobManager:
> {noformat}
> numRegisteredTaskManagers
> numRunningJobs
> taskSlotsAvailable
> taskSlotsTotal
> {noformat}
> In the job manager REST endpoint 
> ({{http://<job-manager>:8081/jobmanager/metrics}}), those metrics don't 
> appear.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to