[ 
https://issues.apache.org/jira/browse/HDFS-16700?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17576163#comment-17576163
 ] 

ASF GitHub Bot commented on HDFS-16700:
---------------------------------------

jianghuazhu commented on code in PR #4659:
URL: https://github.com/apache/hadoop/pull/4659#discussion_r939508358


##########
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/CallerContext.java:
##########
@@ -121,6 +122,51 @@ public String toString() {
     return str;
   }
 
+  /**
+   * Try to obtain the value corresponding to the key by parsing the content.
+   * @param content the full content to be parsed.
+   * @param key trying to obtain the value of the key.
+   * @return the value corresponding to the key.
+   */
+  @VisibleForTesting
+  public static String parseSpecialValue(String content, String key) {
+    int posn = content.indexOf(key);
+    if (posn != -1) {
+      posn += key.length();
+      int end = content.indexOf(",", posn);
+      return end == -1 ? content.substring(posn) : content.substring(posn, 
end);
+    }
+    return null;
+  }
+
+  /**
+   * Get client ip content from caller context.
+   * @param context The context here is obtained from outside.
+   * @return Filter the value carried by 'clientIp:' from the context.
+   *         If not, return null.
+   */
+  public static String getRealClientIp(String context) {
+    if (context != null && !context.equals("")) {

Review Comment:
   The string here is obtained from outside.



##########
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/CallerContext.java:
##########
@@ -121,6 +122,51 @@ public String toString() {
     return str;
   }
 
+  /**
+   * Try to obtain the value corresponding to the key by parsing the content.
+   * @param content the full content to be parsed.
+   * @param key trying to obtain the value of the key.
+   * @return the value corresponding to the key.
+   */
+  @VisibleForTesting
+  public static String parseSpecialValue(String content, String key) {
+    int posn = content.indexOf(key);
+    if (posn != -1) {
+      posn += key.length();
+      int end = content.indexOf(",", posn);
+      return end == -1 ? content.substring(posn) : content.substring(posn, 
end);
+    }
+    return null;
+  }
+
+  /**
+   * Get client ip content from caller context.
+   * @param context The context here is obtained from outside.
+   * @return Filter the value carried by 'clientIp:' from the context.
+   *         If not, return null.
+   */
+  public static String getRealClientIp(String context) {
+    if (context != null && !context.equals("")) {
+      String ipKey = CLIENT_IP_STR + Builder.KEY_VALUE_SEPARATOR;
+      return parseSpecialValue(context, ipKey);
+    }
+    return null;
+  }
+
+  /**
+   * Get client port content from caller context.
+   * @param context The context here is obtained from outside.
+   * @return Filter the value carried by 'clientPort:' from the context.
+   *         If not, return null.
+   */
+  public static String getRealClientPort(String context) {
+    if (context != null && !context.equals("")) {

Review Comment:
   The string here is obtained from outside.





> RBF: Record the real client IP carried by the Router in the NameNode log
> ------------------------------------------------------------------------
>
>                 Key: HDFS-16700
>                 URL: https://issues.apache.org/jira/browse/HDFS-16700
>             Project: Hadoop HDFS
>          Issue Type: Improvement
>          Components: namenode, rbf
>    Affects Versions: 3.3.3
>            Reporter: JiangHua Zhu
>            Assignee: JiangHua Zhu
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 3h 40m
>  Remaining Estimate: 0h
>
> Here are some logs recorded by the NameNode when using RBF:
> {code:java}
> 2022-07-28 19:31:07,126 INFO ipc.Server: IPC Server handler 8 on default port 
> 8020, call Call#127 Retry#0 
> org.apache.hadoop.hdfs.protocol.ClientProtocol.getFileInfo from 
> 172.10.100.67:58001
> {code}
> The ip information here is still the router. If the real client ip is 
> recorded, it will more clearly express where the request comes from.
> E.g:
> {code:java}
> 2022-07-29 19:31:07,126 INFO ipc.Server: IPC Server handler 8 on default port 
> 8020, call Call#127 Retry#0 
> org.apache.hadoop.hdfs.protocol.ClientProtocol.getFileInfo from 
> 172.10.100.67:58001, client=172.111.65.123:43232
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to