Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDFS-16495: RBF should prepend the client ip rather than append it. #4054

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ private Object invokeMethod(
+ router.getRouterId());
}

appendClientIpPortToCallerContextIfAbsent();
addClientIpToCallerContext();

Object ret = null;
if (rpcMonitor != null) {
Expand Down Expand Up @@ -590,17 +590,26 @@ private Object invokeMethod(
* It adds trace info "clientIp:ip" and "clientPort:port"
* to caller context if they are absent.
omalley marked this conversation as resolved.
Show resolved Hide resolved
*/
private void appendClientIpPortToCallerContextIfAbsent() {
private void addClientIpToCallerContext() {
CallerContext ctx = CallerContext.getCurrent();
String origContext = ctx == null ? null : ctx.getContext();
byte[] origSignature = ctx == null ? null : ctx.getSignature();
CallerContext.setCurrent(
new CallerContext.Builder(origContext, contextFieldSeparator)
.appendIfAbsent(CLIENT_IP_STR, Server.getRemoteAddress())
.appendIfAbsent(CLIENT_PORT_STR,
CallerContext.Builder builder =
new CallerContext.Builder("", contextFieldSeparator)
.append(CLIENT_IP_STR, Server.getRemoteAddress())
.append(CLIENT_PORT_STR,
Integer.toString(Server.getRemotePort()))
.setSignature(origSignature)
.build());
.setSignature(origSignature);
// Append the original caller context
if (origContext != null) {
for (String part : origContext.split(contextFieldSeparator)) {
if (!part.startsWith(CLIENT_IP_STR) &&
omalley marked this conversation as resolved.
Show resolved Hide resolved
!part.startsWith(CLIENT_PORT_STR)) {
builder.append(part);
}
}
}
CallerContext.setCurrent(builder.build());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1951,8 +1951,9 @@ public void testMkdirsWithCallerContext() throws IOException {
routerProtocol.mkdirs(dirPath, permission, false);

// The audit log should contains "callerContext=clientContext,clientIp:"
omalley marked this conversation as resolved.
Show resolved Hide resolved
assertTrue(auditlog.getOutput()
.contains("callerContext=clientContext,clientIp:"));
final String logOutput = auditlog.getOutput();
assertTrue(logOutput.contains("callerContext=clientIp:"));
assertTrue(logOutput.contains(",clientContext"));
assertTrue(verifyFileExists(routerFS, dirPath));
}

Expand Down Expand Up @@ -1997,9 +1998,9 @@ public void testAddClientIpPortToCallerContext() throws IOException {
// Create a directory via the router.
routerProtocol.getFileInfo(dirPath);

// The audit log should contains the original clientIp and clientPort
// The audit log should not contain the original clientIp and clientPort
// set by client.
assertTrue(auditLog.getOutput().contains("clientIp:1.1.1.1"));
assertTrue(auditLog.getOutput().contains("clientPort:1234"));
assertFalse(auditLog.getOutput().contains("clientIp:1.1.1.1"));
assertFalse(auditLog.getOutput().contains("clientPort:1234"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,8 @@ public void testCallerContextWithMultiDestinations() throws IOException {
for (String line : auditLog.getOutput().split("\n")) {
if (line.contains(auditFlag)) {
// assert origin caller context exist in audit log
assertTrue(line.contains("callerContext=clientContext"));
String callerContext = line.substring(
line.indexOf("callerContext=clientContext"));
String callerContext = line.substring(line.indexOf("callerContext="));
assertTrue(callerContext.contains("clientContext"));
// assert client ip info exist in caller context
assertTrue(callerContext.contains(clientIpInfo));
// assert client ip info appears only once in caller context
Expand Down