From 31a06baca0a126d349e050dea5c996a9efee77e3 Mon Sep 17 00:00:00 2001 From: Jason Lowe Date: Mon, 18 Dec 2017 14:28:27 -0600 Subject: [PATCH] YARN-7661. NodeManager metrics return wrong value after update node resource. Contributed by Yang Wang (cherry picked from commit 811fabdebe881248756c0165bf7667bfc22be9bb) --- .../yarn/server/nodemanager/metrics/NodeManagerMetrics.java | 2 +- .../server/nodemanager/metrics/TestNodeManagerMetrics.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/metrics/NodeManagerMetrics.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/metrics/NodeManagerMetrics.java index a59bb5c6098..21e5140b91f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/metrics/NodeManagerMetrics.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/metrics/NodeManagerMetrics.java @@ -198,7 +198,7 @@ public class NodeManagerMetrics { public void addResource(Resource res) { availableMB = availableMB + res.getMemorySize(); - availableGB.incr((int)Math.floor(availableMB/1024d)); + availableGB.set((int)Math.floor(availableMB/1024d)); availableVCores.incr(res.getVirtualCores()); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/metrics/TestNodeManagerMetrics.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/metrics/TestNodeManagerMetrics.java index a08ee82e759..5dead916c28 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/metrics/TestNodeManagerMetrics.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/metrics/TestNodeManagerMetrics.java @@ -84,6 +84,12 @@ public class TestNodeManagerMetrics { // allocatedGB: 3.75GB allocated memory is shown as 4GB // availableGB: 4.25GB available memory is shown as 4GB checkMetrics(10, 1, 1, 1, 1, 1, 4, 7, 4, 13, 3); + + // Update resource and check available resource again + metrics.addResource(total); + MetricsRecordBuilder rb = getMetrics("NodeManagerMetrics"); + assertGauge("AvailableGB", 12, rb); + assertGauge("AvailableVCores", 19, rb); } private void checkMetrics(int launched, int completed, int failed, int killed,