HDFS-14685. DefaultAuditLogger doesn't print CallerContext. Contributed by xuzq.

(cherry picked from commit 6757fc1a1d40ffc771bb685886b0d4a16315eca5)
(cherry picked from commit e1659fe009)
This commit is contained in:
Wei-Chiu Chuang 2019-08-02 10:51:04 -07:00
parent 8501bed9cb
commit 68d618acd2
3 changed files with 10 additions and 6 deletions

View File

@ -1065,7 +1065,9 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
// Make sure there is at least one logger installed. // Make sure there is at least one logger installed.
if (auditLoggers.isEmpty()) { if (auditLoggers.isEmpty()) {
auditLoggers.add(new DefaultAuditLogger()); DefaultAuditLogger defaultAuditLogger = new DefaultAuditLogger();
defaultAuditLogger.initialize(conf);
auditLoggers.add(defaultAuditLogger);
} }
// Add audit logger to calculate top users // Add audit logger to calculate top users

View File

@ -61,13 +61,10 @@ public abstract class HdfsAuditLogger implements AuditLogger {
* @param dtSecretManager The token secret manager, or null if not logging * @param dtSecretManager The token secret manager, or null if not logging
* token tracking information * token tracking information
*/ */
public void logAuditEvent(boolean succeeded, String userName, public abstract void logAuditEvent(boolean succeeded, String userName,
InetAddress addr, String cmd, String src, String dst, InetAddress addr, String cmd, String src, String dst,
FileStatus stat, CallerContext callerContext, UserGroupInformation ugi, FileStatus stat, CallerContext callerContext, UserGroupInformation ugi,
DelegationTokenSecretManager dtSecretManager) { DelegationTokenSecretManager dtSecretManager);
logAuditEvent(succeeded, userName, addr, cmd, src, dst, stat,
ugi, dtSecretManager);
}
/** /**
* Same as * Same as

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.hdfs.server.namenode; package org.apache.hadoop.hdfs.server.namenode;
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_CALLER_CONTEXT_ENABLED_KEY;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_EDITS_DIR_KEY; import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_EDITS_DIR_KEY;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY; import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY;
import static org.hamcrest.CoreMatchers.either; import static org.hamcrest.CoreMatchers.either;
@ -242,10 +243,14 @@ public class TestFSNamesystem {
conf.set(DFSConfigKeys.DFS_NAMENODE_AUDIT_LOGGERS_KEY, ""); conf.set(DFSConfigKeys.DFS_NAMENODE_AUDIT_LOGGERS_KEY, "");
// Disable top logger // Disable top logger
conf.setBoolean(DFSConfigKeys.NNTOP_ENABLED_KEY, false); conf.setBoolean(DFSConfigKeys.NNTOP_ENABLED_KEY, false);
conf.setBoolean(HADOOP_CALLER_CONTEXT_ENABLED_KEY, true);
fsn = new FSNamesystem(conf, fsImage); fsn = new FSNamesystem(conf, fsImage);
auditLoggers = fsn.getAuditLoggers(); auditLoggers = fsn.getAuditLoggers();
assertTrue(auditLoggers.size() == 1); assertTrue(auditLoggers.size() == 1);
assertTrue(auditLoggers.get(0) instanceof FSNamesystem.DefaultAuditLogger); assertTrue(auditLoggers.get(0) instanceof FSNamesystem.DefaultAuditLogger);
FSNamesystem.DefaultAuditLogger defaultAuditLogger =
(FSNamesystem.DefaultAuditLogger) auditLoggers.get(0);
assertTrue(defaultAuditLogger.getCallerContextEnabled());
// Not to specify any audit loggers in config // Not to specify any audit loggers in config
conf.set(DFSConfigKeys.DFS_NAMENODE_AUDIT_LOGGERS_KEY, ""); conf.set(DFSConfigKeys.DFS_NAMENODE_AUDIT_LOGGERS_KEY, "");