adoroszlai commented on code in PR #5590:
URL: https://github.com/apache/ozone/pull/5590#discussion_r1393734116


##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/GrpcOmTransport.java:
##########
@@ -175,15 +181,22 @@ public void start() throws IOException {
 
   @Override
   public OMResponse submitRequest(OMRequest payload) throws IOException {
-    OMResponse resp = null;
+    AtomicReference<OMResponse> resp = new AtomicReference<>();
     boolean tryOtherHost = true;
     int expectedFailoverCount = 0;
     ResultCodes resultCode = ResultCodes.INTERNAL_ERROR;
     while (tryOtherHost) {
       tryOtherHost = false;
       expectedFailoverCount = syncFailoverCount.get();
       try {
-        resp = clients.get(host.get()).submitRequest(payload);
+        InetAddress inetAddress = InetAddress.getLocalHost();
+        Context.current()
+            .withValue(GrpcClientConstants.CLIENT_IP_ADDRESS_CTX_KEY,
+                inetAddress.getHostAddress())
+            .withValue(GrpcClientConstants.CLIENT_HOSTNAME_CTX_KEY,
+                inetAddress.getHostName()).run(() -> {
+                  resp.set(clients.get(host.get()).submitRequest(payload));
+                });

Review Comment:
   nit: formatting is a bit misleading, as if `run()` had to do only with 
hostname
   
   ```suggestion
           Context.current()
               .withValue(GrpcClientConstants.CLIENT_IP_ADDRESS_CTX_KEY,
                   inetAddress.getHostAddress())
               .withValue(GrpcClientConstants.CLIENT_HOSTNAME_CTX_KEY,
                   inetAddress.getHostName())
               .run(() ->
                   resp.set(clients.get(host.get()).submitRequest(payload)));
   ```



##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/grpc/package-info.java:
##########
@@ -0,0 +1,22 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.ozone.om.protocolPB.grpc;
+/**
+ * This package contains grpc interceptors and their related classes
+ * to provide specific grpc headers
+ */

Review Comment:
   nit: misplaced javadoc comment
   
   ```suggestion
   /**
    * This package contains grpc interceptors and their related classes
    * to provide specific grpc headers
    */
   package org.apache.hadoop.ozone.om.protocolPB.grpc;
   ```



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataReader.java:
##########
@@ -565,7 +566,11 @@ public boolean checkAcls(OzoneObj obj, RequestContext 
context,
   static String getClientAddress() {

Review Comment:
   Please replace calls to `Server.getRemoteAddress()` with 
`getClientAddress()` in the following places to apply the improved address 
detection to audit log for read requests.
   
   
https://github.com/apache/ozone/blob/fea5c1545fd19355d1c3e7449e9bcc53e5a409de/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataReader.java#L584
   
   
https://github.com/apache/ozone/blob/fea5c1545fd19355d1c3e7449e9bcc53e5a409de/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataReader.java#L597



##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/grpc/ClientAddressClientInterceptor.java:
##########
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one

Review Comment:
   nit: license header is not a javadoc
   
   ```suggestion
   /*
    * Licensed to the Apache Software Foundation (ASF) under one
   ```
   
   Also in other new files.



##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/grpc/ClientAddressClientInterceptor.java:
##########
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.om.protocolPB.grpc;
+
+import io.grpc.CallOptions;
+import io.grpc.Channel;
+import io.grpc.ClientCall;
+import io.grpc.ClientInterceptor;
+import io.grpc.ForwardingClientCall;
+import io.grpc.Metadata;
+import io.grpc.MethodDescriptor;
+
+/**
+ * GRPC client side interceptor to provide client hostname and IP address.
+ */
+public class ClientAddressClientInterceptor implements ClientInterceptor {
+  @Override
+  public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
+      MethodDescriptor<ReqT, RespT> methodDescriptor, CallOptions callOptions,
+      Channel channel) {
+    return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(
+        channel.newCall(methodDescriptor, callOptions)) {
+      @Override
+      public void start(Listener<RespT> responseListener, Metadata headers) {
+        if (GrpcClientConstants.CLIENT_HOSTNAME_CTX_KEY.get() != null) {
+          headers.put(GrpcClientConstants.CLIENT_HOSTNAME_METADATA_KEY,
+              GrpcClientConstants.CLIENT_HOSTNAME_CTX_KEY.get());
+        }

Review Comment:
   nit: save value and reuse
   
   ```suggestion
           String hostname = GrpcClientConstants.CLIENT_HOSTNAME_CTX_KEY.get();
           if (hostname != null) {
             headers.put(GrpcClientConstants.CLIENT_HOSTNAME_METADATA_KEY,
                 hostname);
           }
   ```
   
   Also for IP address.  Also in other files (`OmMetadataReader`, 
`OMClientRequest`, etc.).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to