You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-issues@hadoop.apache.org by GitBox <gi...@apache.org> on 2022/06/15 00:30:14 UTC

[GitHub] [hadoop] goiri commented on a diff in pull request #4426: YARN-10883. [Router] Router Audit Log Add Client IP Address.

goiri commented on code in PR #4426:
URL: https://github.com/apache/hadoop/pull/4426#discussion_r897423212


##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/TestRouterAuditLogger.java:
##########
@@ -143,18 +168,75 @@ private void testFailureLogFormatHelper(ApplicationId appId,
    * Test the AuditLog format for failure events with the various
    * parameters.
    */
-  private void testFailureLogFormat() {
-    testFailureLogFormatHelper(null, null);
-    testFailureLogFormatHelper(APPID, null);
-    testFailureLogFormatHelper(null, SUBCLUSTERID);
-    testFailureLogFormatHelper(APPID, SUBCLUSTERID);
+  private void testFailureLogFormat(boolean checkIP) {
+    testFailureLogFormatHelper(checkIP, null, null);
+    testFailureLogFormatHelper(checkIP, APPID, null);
+    testFailureLogFormatHelper(checkIP, null, SUBCLUSTERID);
+    testFailureLogFormatHelper(checkIP, APPID, SUBCLUSTERID);
   }
 
   /**
    *  Test {@link RouterAuditLogger}.
    */
-  @Test public void testRouterAuditLogger() throws Exception {
-    testSuccessLogFormat();
-    testFailureLogFormat();
+  @Test
+  public void testRouterAuditLoggerWithOutIP() throws Exception {
+    testSuccessLogFormat(false);
+    testFailureLogFormat(false);
+  }
+
+  /**
+   * A special extension of {@link TestRPC.TestImpl} RPC server with
+   * {@link TestRPC.TestImpl#ping()} testing the audit logs.
+   */
+  private class MyTestRouterRPCServer extends TestRpcBase.PBServerImpl {
+    @Override
+    public TestProtos.EmptyResponseProto ping(
+            RpcController unused, TestProtos.EmptyRequestProto request)
+            throws ServiceException {
+      // Ensure clientId is received
+      byte[] clientId = Server.getClientId();
+      Assert.assertNotNull(clientId);
+      Assert.assertEquals(ClientId.BYTE_LENGTH, clientId.length);
+      // test with ip set
+      testSuccessLogFormat(true);
+      testFailureLogFormat(true);
+      return TestProtos.EmptyResponseProto.newBuilder().build();
+    }
+  }
+
+  /**
+   * Test {@link RouterAuditLogger} with IP set.
+   */
+  @Test
+  public void testRouterAuditLoggerWithIP() throws Exception {
+    Configuration conf = new Configuration();
+    RPC.setProtocolEngine(conf, TestRpcBase.TestRpcService.class, ProtobufRpcEngine2.class);
+
+    // Create server side implementation
+    MyTestRouterRPCServer serverImpl = new MyTestRouterRPCServer();
+    BlockingService service = TestRpcServiceProtos.TestProtobufRpcProto
+            .newReflectiveBlockingService(serverImpl);
+
+    // start the IPC server
+    Server server = new RPC.Builder(conf)
+            .setProtocol(TestRpcBase.TestRpcService.class)
+            .setInstance(service).setBindAddress("0.0.0.0")
+            .setPort(0).setNumHandlers(5).setVerbose(true).build();
+
+    server.start();
+
+    InetSocketAddress addr = NetUtils.getConnectAddress(server);
+
+    // Make a client connection and test the audit log
+    TestRpcBase.TestRpcService proxy = RPC.getProxy(TestRpcBase.TestRpcService.class,
+            TestRPC.TestProtocol.versionID, addr, conf);
+
+    // Start the testcase
+    TestProtos.EmptyRequestProto pingRequest =
+            TestProtos.EmptyRequestProto.newBuilder().build();
+    proxy.ping(null, pingRequest);
+
+    server.stop();

Review Comment:
   This should be in a finally or similar to avoid leaking in case of failure.



-- 
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: common-issues-unsubscribe@hadoop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org