@@ -363,6 +363,60 @@ public void testSlowLogFilters() throws Exception {
363363 HBASE_TESTING_UTILITY .waitFor (3000 , () -> getSlowLogPayloads (requestSlowLog ).size () == 15 ));
364364 }
365365
366+ @ Test
367+ public void testSlowLogFilterWithClientAddress () throws Exception {
368+ Configuration conf = applySlowLogRecorderConf (10 );
369+ Constructor <NamedQueueRecorder > constructor =
370+ NamedQueueRecorder .class .getDeclaredConstructor (Configuration .class );
371+ constructor .setAccessible (true );
372+ namedQueueRecorder = constructor .newInstance (conf );
373+ AdminProtos .SlowLogResponseRequest request =
374+ AdminProtos .SlowLogResponseRequest .newBuilder ().build ();
375+ Assert .assertEquals (getSlowLogPayloads (request ).size (), 0 );
376+
377+ String [] clientAddressArray = new String [] { "[127:1:1:1:1:1:1:1]:1" , "[127:1:1:1:1:1:1:1]:2" ,
378+ "[127:1:1:1:1:1:1:1]:3" , "127.0.0.1:1" , "127.0.0.1:2" };
379+ boolean isSlowLog ;
380+ boolean isLargeLog ;
381+ for (int i = 0 ; i < 10 ; i ++) {
382+ if (i % 2 == 0 ) {
383+ isSlowLog = true ;
384+ isLargeLog = false ;
385+ } else {
386+ isSlowLog = false ;
387+ isLargeLog = true ;
388+ }
389+ RpcLogDetails rpcLogDetails = getRpcLogDetails ("userName_" + (i + 1 ),
390+ clientAddressArray [i % 5 ], "class_" + (i + 1 ), isSlowLog , isLargeLog );
391+ namedQueueRecorder .addRecord (rpcLogDetails );
392+ }
393+
394+ AdminProtos .SlowLogResponseRequest largeLogRequestIPv6WithPort =
395+ AdminProtos .SlowLogResponseRequest .newBuilder ()
396+ .setLogType (AdminProtos .SlowLogResponseRequest .LogType .LARGE_LOG )
397+ .setClientAddress ("[127:1:1:1:1:1:1:1]:2" ).build ();
398+ Assert .assertNotEquals (-1 , HBASE_TESTING_UTILITY .waitFor (3000 ,
399+ () -> getSlowLogPayloads (largeLogRequestIPv6WithPort ).size () == 1 ));
400+ AdminProtos .SlowLogResponseRequest largeLogRequestIPv6WithoutPort =
401+ AdminProtos .SlowLogResponseRequest .newBuilder ()
402+ .setLogType (AdminProtos .SlowLogResponseRequest .LogType .LARGE_LOG )
403+ .setClientAddress ("[127:1:1:1:1:1:1:1]" ).build ();
404+ Assert .assertNotEquals (-1 , HBASE_TESTING_UTILITY .waitFor (3000 ,
405+ () -> getSlowLogPayloads (largeLogRequestIPv6WithoutPort ).size () == 3 ));
406+ AdminProtos .SlowLogResponseRequest largeLogRequestIPv4WithPort =
407+ AdminProtos .SlowLogResponseRequest .newBuilder ()
408+ .setLogType (AdminProtos .SlowLogResponseRequest .LogType .LARGE_LOG )
409+ .setClientAddress ("127.0.0.1:1" ).build ();
410+ Assert .assertNotEquals (-1 , HBASE_TESTING_UTILITY .waitFor (3000 ,
411+ () -> getSlowLogPayloads (largeLogRequestIPv4WithPort ).size () == 1 ));
412+ AdminProtos .SlowLogResponseRequest largeLogRequestIPv4WithoutPort =
413+ AdminProtos .SlowLogResponseRequest .newBuilder ()
414+ .setLogType (AdminProtos .SlowLogResponseRequest .LogType .LARGE_LOG )
415+ .setClientAddress ("127.0.0.1" ).build ();
416+ Assert .assertNotEquals (-1 , HBASE_TESTING_UTILITY .waitFor (3000 ,
417+ () -> getSlowLogPayloads (largeLogRequestIPv4WithoutPort ).size () == 2 ));
418+ }
419+
366420 @ Test
367421 public void testConcurrentSlowLogEvents () throws Exception {
368422
0 commit comments