diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/SchedulerOpMetrics.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/SchedulerOpMetrics.java new file mode 100644 index 00000000000..cbf2142d7dc --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/SchedulerOpMetrics.java @@ -0,0 +1,170 @@ +/** + * 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.hadoop.yarn.server.resourcemanager.scheduler; + +import org.apache.hadoop.classification.InterfaceAudience; +import org.apache.hadoop.classification.InterfaceStability; +import org.apache.hadoop.metrics2.MetricsCollector; +import org.apache.hadoop.metrics2.MetricsInfo; +import org.apache.hadoop.metrics2.MetricsSource; +import org.apache.hadoop.metrics2.MetricsSystem; +import org.apache.hadoop.metrics2.annotation.Metric; +import org.apache.hadoop.metrics2.annotation.Metrics; +import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem; +import org.apache.hadoop.metrics2.lib.MetricsRegistry; +import org.apache.hadoop.metrics2.lib.MutableRate; +import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEventType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.apache.hadoop.metrics2.lib.Interns.info; + +@InterfaceAudience.Private +@InterfaceStability.Unstable +@Metrics(context="yarn") +public class SchedulerOpMetrics implements MetricsSource { + @Metric("Duration for an allocate call") + MutableRate allocateCall; + @Metric("Duration for a NODE_ADDED call") + MutableRate nodeAddedCall; + @Metric("Duration for a NODE_REMOVED call") + MutableRate nodeRemovedCall; + @Metric("Duration for a NODE_UPDATE call") + MutableRate nodeUpdateCall; + @Metric("Duration for a NODE_RESOURCE_UPDATE call") + MutableRate nodeResourceUpdateCall; + @Metric("Duration for a NODE_LABELS_UPDATE call") + MutableRate nodeLabelsUpdateCall; + @Metric("Duration for an APP_ADDED call") + MutableRate appAddedCall; + @Metric("Duration for an APP_REMOVED call") + MutableRate appRemovedCall; + @Metric("Duration for an APP_ATTEMPT_ADDED call") + MutableRate appAttemptAddedCall; + @Metric("Duration for an APP_ATTEMPT_REMOVED call") + MutableRate appAttemptRemovedCall; + @Metric("Duration for a CONTAINER_EXPIRED call") + MutableRate containerExpiredCall; + @Metric("Duration for a RELEASE_CONTAINER call") + MutableRate releaseContainerCall; + @Metric("Duration for a KILL_RESERVED_CONTAINER call") + MutableRate killReservedContainerCall; + @Metric("Duration for a MARK_CONTAINER_FOR_PREEMPTION call") + MutableRate markContainerForPreemptionCall; + @Metric("Duration for a MARK_CONTAINER_FOR_KILLABLE call") + MutableRate markContainerForKillableCall; + @Metric("Duration for a MARK_CONTAINER_FOR_NONKILLABLE call") + MutableRate markContainerForNonKillableCall; + @Metric("Duration for a MANAGE_QUEUE call") + MutableRate manageQueueCall; + + private static final Logger LOG = + LoggerFactory.getLogger(SchedulerOpMetrics.class); + private static final MetricsInfo RECORD_INFO = info("SchedulerOpMetrics", + "Metrics for scheduler operation calls"); + + protected final MetricsRegistry registry; + protected final MetricsSystem metricsSystem; + + private static SchedulerOpMetrics INSTANCE = null; + + public static SchedulerOpMetrics getInstance() { + if (INSTANCE == null) { + INSTANCE = new SchedulerOpMetrics(); + } + return INSTANCE; + } + + private SchedulerOpMetrics() { + this(DefaultMetricsSystem.instance()); + } + + protected SchedulerOpMetrics(MetricsSystem ms) { + registry = new MetricsRegistry("SchedulerOpMetrics"); + metricsSystem = ms; + metricsSystem.register(RECORD_INFO.name(), + RECORD_INFO.description(), this); + allocateCall.setExtended(true); + } + + @Override + public void getMetrics(MetricsCollector collector, boolean all) { + registry.snapshot(collector.addRecord(registry.info()), all); + } + + public void addAllocateCallDuration(long value) { + allocateCall.add(value); + } + + public void addSchedulerEventCallDuration( + SchedulerEventType eventType, long value) { + switch (eventType) { + case NODE_ADDED: + nodeAddedCall.add(value); + break; + case NODE_REMOVED: + nodeRemovedCall.add(value); + break; + case NODE_UPDATE: + nodeUpdateCall.add(value); + break; + case NODE_RESOURCE_UPDATE: + nodeResourceUpdateCall.add(value); + break; + case NODE_LABELS_UPDATE: + nodeLabelsUpdateCall.add(value); + break; + case APP_ADDED: + appAddedCall.add(value); + break; + case APP_REMOVED: + appRemovedCall.add(value); + break; + case APP_ATTEMPT_ADDED: + appAttemptAddedCall.add(value); + break; + case APP_ATTEMPT_REMOVED: + appAttemptRemovedCall.add(value); + break; + case CONTAINER_EXPIRED: + containerExpiredCall.add(value); + break; + case RELEASE_CONTAINER: + releaseContainerCall.add(value); + break; + case KILL_RESERVED_CONTAINER: + killReservedContainerCall.add(value); + break; + case MARK_CONTAINER_FOR_PREEMPTION: + markContainerForPreemptionCall.add(value); + break; + case MARK_CONTAINER_FOR_KILLABLE: + markContainerForKillableCall.add(value); + break; + case MARK_CONTAINER_FOR_NONKILLABLE: + markContainerForNonKillableCall.add(value); + break; + case MANAGE_QUEUE: + manageQueueCall.add(value); + break; + default: + LOG.warn("Unable to find corresponding MutableRate " + + "for scheduler event type {}", eventType); + } + } +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CSOpMetrics.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CSOpMetrics.java new file mode 100644 index 00000000000..f9dee5eb8fd --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CSOpMetrics.java @@ -0,0 +1,42 @@ +/** + * 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.hadoop.yarn.server.resourcemanager.scheduler.capacity; + +import org.apache.hadoop.metrics2.MetricsSystem; +import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem; +import org.apache.hadoop.yarn.server.resourcemanager.scheduler.SchedulerOpMetrics; + +public class CSOpMetrics extends SchedulerOpMetrics { + + private static CSOpMetrics INSTANCE; + + public static CSOpMetrics getInstance() { + if (INSTANCE == null) { + INSTANCE = new CSOpMetrics(); + } + return INSTANCE; + } + + private CSOpMetrics() { + this(DefaultMetricsSystem.instance()); + } + + private CSOpMetrics(MetricsSystem ms) { + super(ms); + } +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacityScheduler.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacityScheduler.java index 03ca507bd6f..219f0c9f5ac 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacityScheduler.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacityScheduler.java @@ -180,6 +180,10 @@ private CSConfigurationProvider csConfProvider; + private CSOpMetrics csOpMetrics; + + private boolean csOpMetricsOn; + @Override public void setConf(Configuration conf) { yarnConf = conf; @@ -364,6 +368,11 @@ void initScheduler(Configuration configuration) throws // Setup how many containers we can allocate for each round offswitchPerHeartbeatLimit = this.conf.getOffSwitchPerHeartbeatLimit(); + this.csOpMetricsOn = this.conf.getEnableOperationMetrics(); + if (this.csOpMetricsOn) { + this.csOpMetrics = CSOpMetrics.getInstance(); + } + LOG.info("Initialized CapacityScheduler with " + "calculator=" + getResourceCalculator().getClass() + ", " + "minimumAllocation=<" + getMinimumResourceCapability() + ">, " + "maximumAllocation=<" @@ -1055,6 +1064,7 @@ public Allocation allocate(ApplicationAttemptId applicationAttemptId, List ask, List release, List blacklistAdditions, List blacklistRemovals, ContainerUpdates updateRequests) { + long start = getClock().getTime(); FiCaSchedulerApp application = getApplicationAttempt(applicationAttemptId); if (application == null) { LOG.error("Calling allocate on removed or non existent application " + @@ -1127,6 +1137,12 @@ public Allocation allocate(ApplicationAttemptId applicationAttemptId, updateDemandForQueue.getOrderingPolicy().demandUpdated(application); } + // Duration metric + if (csOpMetricsOn) { + long duration = getClock().getTime() - start; + csOpMetrics.addAllocateCallDuration(duration); + } + return allocation; } @@ -1565,6 +1581,7 @@ CSAssignment allocateContainersToNode( @Override public void handle(SchedulerEvent event) { + long start = getClock().getTime(); switch(event.getType()) { case NODE_ADDED: { @@ -1727,6 +1744,12 @@ public void handle(SchedulerEvent event) { default: LOG.error("Invalid eventtype " + event.getType() + ". Ignoring!"); } + + // Add duration metric + if (csOpMetricsOn) { + long duration = getClock().getTime() - start; + csOpMetrics.addSchedulerEventCallDuration(event.getType(), duration); + } } /** diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerConfiguration.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerConfiguration.java index e609be905df..a3de6774b46 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerConfiguration.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerConfiguration.java @@ -194,6 +194,12 @@ PREFIX +"user-metrics.enable"; @Private public static final boolean DEFAULT_ENABLE_USER_METRICS = false; + @Private + public static final String ENABLE_OPERATION_METRICS = + PREFIX + "operation-metrics.enable"; + @Private + public static final boolean DEFAULT_ENABLED_OPERATION_METRICS = false; + /** ResourceComparator for scheduling. */ @Private public static final String RESOURCE_CALCULATOR_CLASS = PREFIX + "resource-calculator"; @@ -901,6 +907,10 @@ public boolean getEnableUserMetrics() { return getBoolean(ENABLE_USER_METRICS, DEFAULT_ENABLE_USER_METRICS); } + public boolean getEnableOperationMetrics() { + return getBoolean(ENABLE_OPERATION_METRICS, DEFAULT_ENABLED_OPERATION_METRICS); + } + public int getOffSwitchPerHeartbeatLimit() { int limit = getInt(OFFSWITCH_PER_HEARTBEAT_LIMIT, DEFAULT_OFFSWITCH_PER_HEARTBEAT_LIMIT); diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FSOpMetrics.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FSOpMetrics.java new file mode 100644 index 00000000000..a0193b251cc --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FSOpMetrics.java @@ -0,0 +1,53 @@ +/** + * 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.hadoop.yarn.server.resourcemanager.scheduler.fair; + +import org.apache.hadoop.metrics2.MetricsSystem; +import org.apache.hadoop.metrics2.annotation.Metric; +import org.apache.hadoop.metrics2.annotation.Metrics; +import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem; +import org.apache.hadoop.metrics2.lib.MutableRate; +import org.apache.hadoop.yarn.server.resourcemanager.scheduler.SchedulerOpMetrics; + +@Metrics(context="yarn") +public class FSOpMetrics extends SchedulerOpMetrics { + + @Metric("Duration for a update thread run") + MutableRate updateThreadRun; + + private static FSOpMetrics INSTANCE; + + public static FSOpMetrics getInstance() { + if (INSTANCE == null) { + INSTANCE = new FSOpMetrics(); + } + return INSTANCE; + } + + private FSOpMetrics() { + this(DefaultMetricsSystem.instance()); + } + + private FSOpMetrics(MetricsSystem ms) { + super(ms); + } + + public void addUpdateThreadRunDuration(long value) { + updateThreadRun.add(value); + } +} \ No newline at end of file diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FairScheduler.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FairScheduler.java index e2a62ecd179..34806dd818e 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FairScheduler.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FairScheduler.java @@ -162,6 +162,8 @@ // Aggregate metrics FSQueueMetrics rootMetrics; FSOpDurations fsOpDurations; + FSOpMetrics fsOpMetrics; + boolean fsOpMetricOn; private float reservableNodesRatio; // percentage of available nodes // an app can be reserved on @@ -368,6 +370,7 @@ public void update() { readLock.unlock(); } fsOpDurations.addUpdateThreadRunDuration(getClock().getTime() - start); + fsOpMetrics.addUpdateThreadRunDuration(getClock().getTime() - start); } public RMContainerTokenSecretManager @@ -1121,6 +1124,7 @@ public QueueMetrics getRootQueueMetrics() { @Override public void handle(SchedulerEvent event) { + long start = getClock().getTime(); switch (event.getType()) { case NODE_ADDED: if (!(event instanceof NodeAddedSchedulerEvent)) { @@ -1225,6 +1229,12 @@ public void handle(SchedulerEvent event) { default: LOG.error("Unknown event arrived at FairScheduler: " + event.toString()); } + + // Duration metric + if (fsOpMetricOn) { + long duration = getClock().getTime() - start; + fsOpMetrics.addSchedulerEventCallDuration(event.getType(), duration); + } } private String resolveReservationQueueName(String queueName, @@ -1329,6 +1339,11 @@ private void initScheduler(Configuration conf) throws IOException { rootMetrics = FSQueueMetrics.forQueue("root", null, true, conf); fsOpDurations = FSOpDurations.getInstance(true); + fsOpMetricOn = this.conf.isOperationMetricsEnabled(); + if (fsOpMetricOn) { + fsOpMetrics = FSOpMetrics.getInstance(); + } + // This stores per-application scheduling information this.applications = new ConcurrentHashMap<>(); diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FairSchedulerConfiguration.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FairSchedulerConfiguration.java index b50e4bbe317..d4144a40fa4 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FairSchedulerConfiguration.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FairSchedulerConfiguration.java @@ -213,6 +213,11 @@ CONF_PREFIX + "reservable-nodes"; public static final float RESERVABLE_NODES_DEFAULT = 0.05f; + /** Whether enable scheduler operation metrics. */ + public static final String ENABLE_OPERATION_METRICS = + CONF_PREFIX + "operation-metrics.enable"; + public static final boolean DEFAULT_ENABLE_OPERATION_METRICS = false; + public FairSchedulerConfiguration() { super(); } @@ -483,4 +488,9 @@ private static int findResource(String val, String units) } return Integer.parseInt(matcher.group(1)); } + + public boolean isOperationMetricsEnabled() { + return getBoolean( + ENABLE_OPERATION_METRICS, DEFAULT_ENABLE_OPERATION_METRICS); + } } diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/TestSchedulerOpMetrics.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/TestSchedulerOpMetrics.java new file mode 100644 index 00000000000..b26ad1fa502 --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/TestSchedulerOpMetrics.java @@ -0,0 +1,93 @@ +/** + * 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.hadoop.yarn.server.resourcemanager.scheduler; + +import org.apache.hadoop.metrics2.MetricsRecord; +import org.apache.hadoop.metrics2.impl.MetricsCollectorImpl; +import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEventType; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.apache.hadoop.metrics2.impl.MetricsRecords.assertMetric; + +public class TestSchedulerOpMetrics { + + @Test + public void testSchedulerOpMetrics() { + SchedulerOpMetrics opMetrics = SchedulerOpMetrics.getInstance(); + + // For allocate call + opMetrics.addAllocateCallDuration(1L); + opMetrics.addAllocateCallDuration(2L); + opMetrics.addAllocateCallDuration(3L); + + // For scheduler event, create some random numbers + Map eventCounts = + new HashMap(); + for (SchedulerEventType eventType : SchedulerEventType.values()) { + long nums = (long)(Math.random() * 10) + 1; + for (long i = 0; i < nums; i++) { + opMetrics.addSchedulerEventCallDuration(eventType, 1L); + } + eventCounts.put(eventType, nums); + } + + // Verify + MetricsCollectorImpl collector = new MetricsCollectorImpl(); + opMetrics.getMetrics(collector, true); + + MetricsRecord metricsRecord = collector.getRecords().get(0); + assertMetric(metricsRecord, "AllocateCallNumOps", 3L); + assertMetric(metricsRecord, "AllocateCallAvgTime", 2.0); + + assertMetric(metricsRecord, "NodeAddedCallNumOps", + eventCounts.get(SchedulerEventType.NODE_ADDED)); + assertMetric(metricsRecord, "NodeRemovedCallNumOps", + eventCounts.get(SchedulerEventType.NODE_REMOVED)); + assertMetric(metricsRecord, "NodeUpdateCallNumOps", + eventCounts.get(SchedulerEventType.NODE_UPDATE)); + assertMetric(metricsRecord, "NodeResourceUpdateCallNumOps", + eventCounts.get(SchedulerEventType.NODE_RESOURCE_UPDATE)); + assertMetric(metricsRecord, "NodeLabelsUpdateCallNumOps", + eventCounts.get(SchedulerEventType.NODE_LABELS_UPDATE)); + assertMetric(metricsRecord, "AppAddedCallNumOps", + eventCounts.get(SchedulerEventType.APP_ADDED)); + assertMetric(metricsRecord, "AppRemovedCallNumOps", + eventCounts.get(SchedulerEventType.APP_REMOVED)); + assertMetric(metricsRecord, "AppAttemptAddedCallNumOps", + eventCounts.get(SchedulerEventType.APP_ATTEMPT_ADDED)); + assertMetric(metricsRecord, "AppAttemptRemovedCallNumOps", + eventCounts.get(SchedulerEventType.APP_ATTEMPT_REMOVED)); + assertMetric(metricsRecord, "ContainerExpiredCallNumOps", + eventCounts.get(SchedulerEventType.CONTAINER_EXPIRED)); + assertMetric(metricsRecord, "ReleaseContainerCallNumOps", + eventCounts.get(SchedulerEventType.RELEASE_CONTAINER)); + assertMetric(metricsRecord, "KillReservedContainerCallNumOps", + eventCounts.get(SchedulerEventType.KILL_RESERVED_CONTAINER)); + assertMetric(metricsRecord, "MarkContainerForPreemptionCallNumOps", + eventCounts.get(SchedulerEventType.MARK_CONTAINER_FOR_PREEMPTION)); + assertMetric(metricsRecord, "MarkContainerForKillableCallNumOps", + eventCounts.get(SchedulerEventType.MARK_CONTAINER_FOR_KILLABLE)); + assertMetric(metricsRecord, "MarkContainerForNonKillableCallNumOps", + eventCounts.get(SchedulerEventType.MARK_CONTAINER_FOR_NONKILLABLE)); + assertMetric(metricsRecord, "ManageQueueCallNumOps", + eventCounts.get(SchedulerEventType.MANAGE_QUEUE)); + } +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCSOpMetrics.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCSOpMetrics.java new file mode 100644 index 00000000000..4cd5eacdcc5 --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCSOpMetrics.java @@ -0,0 +1,56 @@ +/** + * 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.hadoop.yarn.server.resourcemanager.scheduler.capacity; + +import org.apache.hadoop.metrics2.MetricsRecord; +import org.apache.hadoop.metrics2.impl.MetricsCollectorImpl; +import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEventType; +import org.junit.Test; + +import static org.apache.hadoop.metrics2.impl.MetricsRecords.assertMetric; + +public class TestCSOpMetrics { + + @Test + public void testFSOpMetrics() { + CSOpMetrics opMetrics = CSOpMetrics.getInstance(); + + // For allocate call + opMetrics.addAllocateCallDuration(1L); + opMetrics.addAllocateCallDuration(2L); + opMetrics.addAllocateCallDuration(3L); + + // Add some scheduler events + opMetrics.addSchedulerEventCallDuration(SchedulerEventType.NODE_ADDED, 5L); + opMetrics.addSchedulerEventCallDuration(SchedulerEventType.APP_ADDED, 2L); + opMetrics.addSchedulerEventCallDuration(SchedulerEventType.APP_ADDED, 4L); + + // Verify + MetricsCollectorImpl collector = new MetricsCollectorImpl(); + opMetrics.getMetrics(collector, true); + + MetricsRecord metricsRecord = collector.getRecords().get(0); + assertMetric(metricsRecord, "AllocateCallNumOps", 3L); + assertMetric(metricsRecord, "AllocateCallAvgTime", 2.0); + + assertMetric(metricsRecord, "NodeAddedCallNumOps", 1L); + assertMetric(metricsRecord, "NodeAddedCallAvgTime", 5.0); + assertMetric(metricsRecord, "AppAddedCallNumOps", 2L); + assertMetric(metricsRecord, "AppAddedCallAvgTime", 3.0); + } +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestFSOpMetrics.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestFSOpMetrics.java new file mode 100644 index 00000000000..0e45e4c523a --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestFSOpMetrics.java @@ -0,0 +1,63 @@ +/** + * 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.hadoop.yarn.server.resourcemanager.scheduler.fair; + +import org.apache.hadoop.metrics2.MetricsRecord; +import org.apache.hadoop.metrics2.impl.MetricsCollectorImpl; +import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEventType; +import org.junit.Test; + +import static org.apache.hadoop.metrics2.impl.MetricsRecords.assertMetric; + +public class TestFSOpMetrics { + + @Test + public void testFSOpMetrics() { + FSOpMetrics opMetrics = FSOpMetrics.getInstance(); + + // For allocate call + opMetrics.addAllocateCallDuration(1L); + opMetrics.addAllocateCallDuration(2L); + opMetrics.addAllocateCallDuration(3L); + + // Add some scheduler events + opMetrics.addSchedulerEventCallDuration(SchedulerEventType.NODE_ADDED, 5L); + opMetrics.addSchedulerEventCallDuration(SchedulerEventType.APP_ADDED, 2L); + opMetrics.addSchedulerEventCallDuration(SchedulerEventType.APP_ADDED, 4L); + + // FS's update thread + opMetrics.addUpdateThreadRunDuration(3L); + opMetrics.addUpdateThreadRunDuration(4L); + + // Verify + MetricsCollectorImpl collector = new MetricsCollectorImpl(); + opMetrics.getMetrics(collector, true); + + MetricsRecord metricsRecord = collector.getRecords().get(0); + assertMetric(metricsRecord, "AllocateCallNumOps", 3L); + assertMetric(metricsRecord, "AllocateCallAvgTime", 2.0); + + assertMetric(metricsRecord, "NodeAddedCallNumOps", 1L); + assertMetric(metricsRecord, "NodeAddedCallAvgTime", 5.0); + assertMetric(metricsRecord, "AppAddedCallNumOps", 2L); + assertMetric(metricsRecord, "AppAddedCallAvgTime", 3.0); + + assertMetric(metricsRecord, "UpdateThreadRunNumOps", 2L); + assertMetric(metricsRecord, "UpdateThreadRunAvgTime", 3.5); + } +}