Skip to content

Commit df76cdc

Browse files
committed
YARN-6695. Fixed NPE in publishing appFinished events to ATSv2.
Contributed by Prabhu Joseph
1 parent b979fdd commit df76cdc

File tree

3 files changed

+56
-12
lines changed

3 files changed

+56
-12
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/metrics/TimelineServiceV2Publisher.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,10 +473,15 @@ private void putEntity(TimelineEntity entity, ApplicationId appId) {
473473
}
474474
TimelineCollector timelineCollector =
475475
rmTimelineCollectorManager.get(appId);
476-
TimelineEntities entities = new TimelineEntities();
477-
entities.addEntity(entity);
478-
timelineCollector.putEntities(entities,
479-
UserGroupInformation.getCurrentUser());
476+
if (timelineCollector != null) {
477+
TimelineEntities entities = new TimelineEntities();
478+
entities.addEntity(entity);
479+
timelineCollector.putEntities(entities,
480+
UserGroupInformation.getCurrentUser());
481+
} else {
482+
LOG.debug("Cannot find active collector while publishing entity "
483+
+ entity);
484+
}
480485
} catch (IOException e) {
481486
LOG.error("Error when publishing entity " + entity);
482487
LOG.debug("Error when publishing entity {}", entity, e);

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/metrics/TestSystemMetricsPublisherForV2.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,17 @@
2828
import java.io.File;
2929
import java.io.FileReader;
3030
import java.io.IOException;
31+
import java.util.ArrayList;
3132
import java.util.Collections;
3233
import java.util.HashMap;
34+
import java.util.List;
3335
import java.util.Map;
3436
import java.util.concurrent.ConcurrentHashMap;
3537
import java.util.concurrent.ConcurrentMap;
3638

39+
import org.apache.log4j.AppenderSkeleton;
40+
import org.apache.log4j.Logger;
41+
import org.apache.log4j.spi.LoggingEvent;
3742
import org.apache.hadoop.conf.Configuration;
3843
import org.apache.hadoop.fs.FileContext;
3944
import org.apache.hadoop.fs.Path;
@@ -293,6 +298,48 @@ public void testPublishContainerMetrics() throws Exception {
293298
TimelineServiceHelper.invertLong(containerId.getContainerId()));
294299
}
295300

301+
@Test(timeout = 10000)
302+
public void testPutEntityWhenNoCollector() throws Exception {
303+
// Validating the logs as DrainDispatcher won't throw exception
304+
class TestAppender extends AppenderSkeleton {
305+
private final List<LoggingEvent> log = new ArrayList<>();
306+
307+
@Override
308+
public boolean requiresLayout() {
309+
return false;
310+
}
311+
312+
@Override
313+
protected void append(final LoggingEvent loggingEvent) {
314+
log.add(loggingEvent);
315+
}
316+
317+
@Override
318+
public void close() {
319+
}
320+
321+
public List<LoggingEvent> getLog() {
322+
return new ArrayList<>(log);
323+
}
324+
}
325+
326+
TestAppender appender = new TestAppender();
327+
final Logger logger = Logger.getRootLogger();
328+
logger.addAppender(appender);
329+
330+
try {
331+
RMApp app = createRMApp(ApplicationId.newInstance(0, 1));
332+
metricsPublisher.appCreated(app, app.getStartTime());
333+
dispatcher.await();
334+
for (LoggingEvent event : appender.getLog()) {
335+
assertFalse("Dispatcher Crashed",
336+
event.getRenderedMessage().contains("Error in dispatcher thread"));
337+
}
338+
} finally {
339+
logger.removeAppender(appender);
340+
}
341+
}
342+
296343
private RMApp createAppAndRegister(ApplicationId appId) {
297344
RMApp app = createRMApp(appId);
298345

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/TimelineServiceV2.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,6 @@ Following are the basic configurations to start Timeline service v.2:
330330
<name>yarn.system-metrics-publisher.enabled</name>
331331
<value>true</value>
332332
</property>
333-
334-
<property>
335-
<description>The setting that controls whether yarn container events are
336-
published to the timeline service or not by RM. This configuration setting
337-
is for ATS V2.</description>
338-
<name>yarn.rm.system-metrics-publisher.emit-container-events</name>
339-
<value>true</value>
340-
</property>
341333
```
342334

343335
If using an aux services manifest instead of setting aux services through the Configuration, ensure that the manifest services array includes the timeline\_collector service as follows:

0 commit comments

Comments
 (0)