YARN-4795. ContainerMetrics drops records. (Daniel Templeton via kasha)

This commit is contained in:
Karthik Kambatla 2016-04-26 06:15:36 -07:00
parent 4b1dcbbe0c
commit 1a3f1482e2
2 changed files with 9 additions and 13 deletions

View File

@ -121,11 +121,10 @@ public class ContainerMetrics implements MetricsSource {
final MetricsSystem metricsSystem; final MetricsSystem metricsSystem;
// Metrics publishing status // Metrics publishing status
private long flushPeriodMs; private final long flushPeriodMs;
private final long unregisterDelayMs;
private boolean flushOnPeriod = false; // true if period elapsed private boolean flushOnPeriod = false; // true if period elapsed
private boolean finished = false; // true if container finished private boolean finished = false; // true if container finished
private boolean unregister = false; // unregister
private long unregisterDelayMs;
private Timer timer; // lazily initialized private Timer timer; // lazily initialized
/** /**
@ -227,17 +226,11 @@ synchronized static void unregisterContainerMetrics(ContainerMetrics cm) {
@Override @Override
public synchronized void getMetrics(MetricsCollector collector, boolean all) { public synchronized void getMetrics(MetricsCollector collector, boolean all) {
//Container goes through registered -> finished -> unregistered. //Container goes through registered -> finished -> unregistered.
if (unregister) {
return;
}
if (finished || flushOnPeriod) { if (finished || flushOnPeriod) {
registry.snapshot(collector.addRecord(registry.info()), all); registry.snapshot(collector.addRecord(registry.info()), all);
} }
if (finished) { if (!finished && flushOnPeriod) {
this.unregister = true;
} else if (flushOnPeriod) {
flushOnPeriod = false; flushOnPeriod = false;
scheduleTimerTaskIfRequired(); scheduleTimerTaskIfRequired();
} }
@ -301,6 +294,7 @@ private synchronized void scheduleTimerTaskIfRequired() {
if (timer == null) { if (timer == null) {
this.timer = new Timer("Metrics flush checker", true); this.timer = new Timer("Metrics flush checker", true);
} }
TimerTask timerTask = new TimerTask() { TimerTask timerTask = new TimerTask() {
@Override @Override
public void run() { public void run() {
@ -311,6 +305,7 @@ public void run() {
} }
} }
}; };
timer.schedule(timerTask, flushPeriodMs); timer.schedule(timerTask, flushPeriodMs);
} }
} }

View File

@ -77,11 +77,12 @@ public void testContainerMetricsFlow() throws InterruptedException {
collector.clear(); collector.clear();
metrics.getMetrics(collector, true); metrics.getMetrics(collector, true);
assertEquals(ERR, 0, collector.getRecords().size()); assertEquals(ERR, 1, collector.getRecords().size());
collector.clear();
Thread.sleep(110); Thread.sleep(110);
metrics.getMetrics(collector, true); metrics.getMetrics(collector, true);
assertEquals(ERR, 0, collector.getRecords().size()); assertEquals(ERR, 1, collector.getRecords().size());
} }
@Test @Test
@ -134,7 +135,7 @@ public void testContainerMetricsLimit() throws InterruptedException {
public void testContainerMetricsFinished() throws InterruptedException { public void testContainerMetricsFinished() throws InterruptedException {
MetricsSystemImpl system = new MetricsSystemImpl(); MetricsSystemImpl system = new MetricsSystemImpl();
system.init("test"); system.init("test");
MetricsCollectorImpl collector = new MetricsCollectorImpl();
ApplicationId appId = ApplicationId.newInstance(1234, 3); ApplicationId appId = ApplicationId.newInstance(1234, 3);
ApplicationAttemptId appAttemptId = ApplicationAttemptId appAttemptId =
ApplicationAttemptId.newInstance(appId, 4); ApplicationAttemptId.newInstance(appId, 4);