YARN-7602. NM should reference the singleton JvmMetrics instance.
(cherry picked from commit 2f6c038be6c23522ea64fc4e415910fb72493eb2)
This commit is contained in:
parent
2a870d91fe
commit
889bebf8bb
@ -200,4 +200,30 @@ public void alert(GcTimeMonitor.GcData gcData) {
|
|||||||
Assert.assertTrue(alerter.numAlerts > 0);
|
Assert.assertTrue(alerter.numAlerts > 0);
|
||||||
Assert.assertTrue(alerter.maxGcTimePercentage >= alertGcPerc);
|
Assert.assertTrue(alerter.maxGcTimePercentage >= alertGcPerc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testJvmMetricsSingletonWithSameProcessName() {
|
||||||
|
JvmMetrics jvmMetrics1 = org.apache.hadoop.metrics2.source.JvmMetrics
|
||||||
|
.initSingleton("test", null);
|
||||||
|
JvmMetrics jvmMetrics2 = org.apache.hadoop.metrics2.source.JvmMetrics
|
||||||
|
.initSingleton("test", null);
|
||||||
|
Assert.assertEquals("initSingleton should return the singleton instance",
|
||||||
|
jvmMetrics1, jvmMetrics2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testJvmMetricsSingletonWithDifferentProcessNames() {
|
||||||
|
final String process1Name = "process1";
|
||||||
|
JvmMetrics jvmMetrics1 = org.apache.hadoop.metrics2.source.JvmMetrics
|
||||||
|
.initSingleton(process1Name, null);
|
||||||
|
final String process2Name = "process2";
|
||||||
|
JvmMetrics jvmMetrics2 = org.apache.hadoop.metrics2.source.JvmMetrics
|
||||||
|
.initSingleton(process2Name, null);
|
||||||
|
Assert.assertEquals("initSingleton should return the singleton instance",
|
||||||
|
jvmMetrics1, jvmMetrics2);
|
||||||
|
Assert.assertEquals("unexpected process name of the singleton instance",
|
||||||
|
process1Name, jvmMetrics1.processName);
|
||||||
|
Assert.assertEquals("unexpected process name of the singleton instance",
|
||||||
|
process1Name, jvmMetrics2.processName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ public class NodeManagerMetrics {
|
|||||||
private long availableMB;
|
private long availableMB;
|
||||||
private long allocatedOpportunisticMB;
|
private long allocatedOpportunisticMB;
|
||||||
|
|
||||||
public NodeManagerMetrics(JvmMetrics jvmMetrics) {
|
private NodeManagerMetrics(JvmMetrics jvmMetrics) {
|
||||||
this.jvmMetrics = jvmMetrics;
|
this.jvmMetrics = jvmMetrics;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,8 +94,8 @@ public static NodeManagerMetrics create() {
|
|||||||
return create(DefaultMetricsSystem.instance());
|
return create(DefaultMetricsSystem.instance());
|
||||||
}
|
}
|
||||||
|
|
||||||
static NodeManagerMetrics create(MetricsSystem ms) {
|
private static NodeManagerMetrics create(MetricsSystem ms) {
|
||||||
JvmMetrics jm = JvmMetrics.create("NodeManager", null, ms);
|
JvmMetrics jm = JvmMetrics.initSingleton("NodeManager", null);
|
||||||
return ms.register(new NodeManagerMetrics(jm));
|
return ms.register(new NodeManagerMetrics(jm));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,19 +19,40 @@
|
|||||||
|
|
||||||
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
|
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
|
||||||
import org.apache.hadoop.metrics2.MetricsRecordBuilder;
|
import org.apache.hadoop.metrics2.MetricsRecordBuilder;
|
||||||
|
import org.apache.hadoop.metrics2.source.JvmMetrics;
|
||||||
import static org.apache.hadoop.test.MetricsAsserts.*;
|
import static org.apache.hadoop.test.MetricsAsserts.*;
|
||||||
import org.apache.hadoop.yarn.api.records.Resource;
|
import org.apache.hadoop.yarn.api.records.Resource;
|
||||||
import org.apache.hadoop.yarn.util.Records;
|
import org.apache.hadoop.yarn.util.Records;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class TestNodeManagerMetrics {
|
public class TestNodeManagerMetrics {
|
||||||
static final int GiB = 1024; // MiB
|
static final int GiB = 1024; // MiB
|
||||||
|
|
||||||
@Test public void testNames() {
|
private NodeManagerMetrics metrics;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
DefaultMetricsSystem.initialize("NodeManager");
|
DefaultMetricsSystem.initialize("NodeManager");
|
||||||
NodeManagerMetrics metrics = NodeManagerMetrics.create();
|
metrics = NodeManagerMetrics.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
DefaultMetricsSystem.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testReferenceOfSingletonJvmMetrics() {
|
||||||
|
JvmMetrics jvmMetrics = JvmMetrics.initSingleton("NodeManagerModule", null);
|
||||||
|
Assert.assertEquals("NodeManagerMetrics should reference the singleton" +
|
||||||
|
" JvmMetrics instance", jvmMetrics, metrics.getJvmMetrics());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test public void testNames() {
|
||||||
Resource total = Records.newRecord(Resource.class);
|
Resource total = Records.newRecord(Resource.class);
|
||||||
total.setMemorySize(8*GiB);
|
total.setMemorySize(8*GiB);
|
||||||
total.setVirtualCores(16);
|
total.setVirtualCores(16);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user