Skip to content

Commit

Permalink
YARN-11579. Fix 'Physical Mem Used' and 'Physical VCores Used' are no…
Browse files Browse the repository at this point in the history
…t displaying data. (#6123) Contributed by Shilun Fan.

Reviewed-by: Inigo Goiri <[email protected]>
Signed-off-by: Shilun Fan <[email protected]>
  • Loading branch information
slfan1989 authored Oct 5, 2023
1 parent ababe3d commit f3a27f2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public class ClusterMetricsInfo {
private int containersPending;

private long totalMB;
private long utilizedMB;
private long totalVirtualCores;
private long utilizedVirtualCores;
private int utilizedMBPercent;
private int utilizedVirtualCoresPercent;
private int rmSchedulerBusyPercent;
Expand Down Expand Up @@ -167,6 +169,7 @@ public ClusterMetricsInfo(final ResourceScheduler rs) {
.getContainerAssignedPerSecond();
this.rmEventQueueSize = clusterMetrics.getRmEventQueueSize();
this.schedulerEventQueueSize = clusterMetrics.getSchedulerEventQueueSize();
this.utilizedVirtualCores = clusterMetrics.getUtilizedVirtualCores();
}

public int getAppsSubmitted() {
Expand Down Expand Up @@ -432,4 +435,20 @@ public int getRmEventQueueSize() {
public int getSchedulerEventQueueSize() {
return schedulerEventQueueSize;
}

public long getUtilizedVirtualCores() {
return utilizedVirtualCores;
}

public void setUtilizedVirtualCores(long utilizedVirtualCores) {
this.utilizedVirtualCores = utilizedVirtualCores;
}

public long getUtilizedMB() {
return utilizedMB;
}

public void setUtilizedMB(long utilizedMB) {
this.utilizedMB = utilizedMB;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ public void verifyClusterMetricsJSON(JSONObject json) throws JSONException,
Exception {
assertEquals("incorrect number of elements", 1, json.length());
JSONObject clusterinfo = json.getJSONObject("clusterMetrics");
assertEquals("incorrect number of elements", 35, clusterinfo.length());
assertEquals("incorrect number of elements", 37, clusterinfo.length());
verifyClusterMetrics(
clusterinfo.getInt("appsSubmitted"), clusterinfo.getInt("appsCompleted"),
clusterinfo.getInt("reservedMB"), clusterinfo.getInt("availableMB"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,10 +506,14 @@ public static void mergeMetrics(ClusterMetricsInfo metrics,

metrics.setTotalMB(metrics.getTotalMB()
+ metricsResponse.getTotalMB());
metrics.setUtilizedMB(metrics.getUtilizedMB()
+ metricsResponse.getUtilizedMB());
metrics.setTotalVirtualCores(metrics.getTotalVirtualCores()
+ metricsResponse.getTotalVirtualCores());
metrics.setTotalNodes(metrics.getTotalNodes()
+ metricsResponse.getTotalNodes());
metrics.setUtilizedVirtualCores(metrics.getUtilizedVirtualCores()
+ metricsResponse.getUtilizedVirtualCores());
metrics.setLostNodes(metrics.getLostNodes()
+ metricsResponse.getLostNodes());
metrics.setUnhealthyNodes(metrics.getUnhealthyNodes()
Expand All @@ -524,6 +528,14 @@ public static void mergeMetrics(ClusterMetricsInfo metrics,
+ metricsResponse.getActiveNodes());
metrics.setShutdownNodes(metrics.getShutdownNodes()
+ metricsResponse.getShutdownNodes());

int utilizedVirtualCoresPercent = metrics.getTotalVirtualCores() <= 0 ? 0 :
(int) (metrics.getUtilizedVirtualCores() * 100 / metrics.getTotalVirtualCores());
metrics.setUtilizedVirtualCoresPercent(utilizedVirtualCoresPercent);

int utilizedMBPercent = metrics.getTotalMB() <= 0 ? 0 :
(int) (metrics.getUtilizedMB() * 100 / metrics.getTotalMB());
metrics.setUtilizedMBPercent(utilizedMBPercent);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,16 @@ public void testMergeMetrics() {
Assert.assertEquals(
metricsResponse.getTotalMB() + metricsClone.getTotalMB(),
metrics.getTotalMB());
Assert.assertEquals(
metricsResponse.getUtilizedMB() + metricsClone.getUtilizedMB(),
metrics.getUtilizedMB());
Assert.assertEquals(
metricsResponse.getTotalVirtualCores()
+ metricsClone.getTotalVirtualCores(),
metrics.getTotalVirtualCores());
Assert.assertEquals(
metricsResponse.getUtilizedVirtualCores() + metricsClone.getUtilizedVirtualCores(),
metrics.getUtilizedVirtualCores());
Assert.assertEquals(
metricsResponse.getTotalNodes() + metricsClone.getTotalNodes(),
metrics.getTotalNodes());
Expand Down Expand Up @@ -544,7 +550,9 @@ private ClusterMetricsInfo createClusterMetricsClone(
metricsClone.setContainersPending(metrics.getPendingContainers());

metricsClone.setTotalMB(metrics.getTotalMB());
metricsClone.setUtilizedMB(metrics.getUtilizedMB());
metricsClone.setTotalVirtualCores(metrics.getTotalVirtualCores());
metricsClone.setUtilizedVirtualCores(metrics.getUtilizedVirtualCores());
metricsClone.setTotalNodes(metrics.getTotalNodes());
metricsClone.setLostNodes(metrics.getLostNodes());
metricsClone.setUnhealthyNodes(metrics.getUnhealthyNodes());
Expand Down Expand Up @@ -580,7 +588,9 @@ private void setUpClusterMetrics(ClusterMetricsInfo metrics, long seed) {
metrics.setContainersPending(rand.nextInt(1000));

metrics.setTotalMB(rand.nextInt(1000));
metrics.setUtilizedMB(metrics.getTotalMB() - rand.nextInt(100));
metrics.setTotalVirtualCores(rand.nextInt(1000));
metrics.setUtilizedVirtualCores(metrics.getUtilizedVirtualCores() - rand.nextInt(100));
metrics.setTotalNodes(rand.nextInt(1000));
metrics.setLostNodes(rand.nextInt(1000));
metrics.setUnhealthyNodes(rand.nextInt(1000));
Expand Down

0 comments on commit f3a27f2

Please sign in to comment.