Skip to content

Commit 76b0720

Browse files
committed
HBASE-27638 Get slow/large log response that matched the ‘CLIENT_IP' without client port
1 parent 1f605cc commit 76b0720

File tree

4 files changed

+79
-1
lines changed

4 files changed

+79
-1
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/namequeues/LogHandlerUtils.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.ArrayList;
2121
import java.util.List;
2222
import org.apache.commons.lang3.StringUtils;
23+
import org.apache.hadoop.hbase.util.Addressing;
2324
import org.apache.yetus.audience.InterfaceAudience;
2425

2526
import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos;
@@ -68,7 +69,7 @@ private static List<TooSlowLog.SlowLogPayload> filterLogs(
6869
if (tableName != null && slowLogPayload.getRegionName().startsWith(tableName)) {
6970
totalFilterMatches++;
7071
}
71-
if (slowLogPayload.getClientAddress().equals(clientAddress)) {
72+
if (isClientAddressMatched(slowLogPayload, clientAddress)) {
7273
totalFilterMatches++;
7374
}
7475
if (slowLogPayload.getUserName().equals(userName)) {
@@ -92,6 +93,17 @@ private static List<TooSlowLog.SlowLogPayload> filterLogs(
9293
return filteredSlowLogPayloads;
9394
}
9495

96+
private static boolean isClientAddressMatched(TooSlowLog.SlowLogPayload slowLogPayload,
97+
String clientAddress) {
98+
String clientAddressInPayload = slowLogPayload.getClientAddress();
99+
int portPos = clientAddressInPayload.lastIndexOf(Addressing.HOSTNAME_PORT_SEPARATOR);
100+
if (portPos < 1) {
101+
return clientAddressInPayload.equals(clientAddress);
102+
}
103+
return clientAddressInPayload.equals(clientAddress)
104+
|| clientAddressInPayload.substring(0, portPos).equals(clientAddress);
105+
}
106+
95107
public static List<TooSlowLog.SlowLogPayload> getFilteredLogs(
96108
AdminProtos.SlowLogResponseRequest request, List<TooSlowLog.SlowLogPayload> logPayloadList) {
97109
int totalFilters = getTotalFiltersCount(request);

hbase-server/src/test/java/org/apache/hadoop/hbase/namequeues/TestNamedQueueRecorder.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

hbase-shell/src/main/ruby/shell/commands/get_largelog_responses.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ def help
4444
=> get largelog responses only related to meta
4545
region
4646
hbase> get_largelog_responses '*', {'TABLE_NAME' => 't1'} => get largelog responses only related to t1 table
47+
hbase> get_largelog_responses '*', {'CLIENT_IP' => '192.162.1.40'}
48+
=> get largelog responses only related to the given
49+
client IP address
50+
hbase> get_largelog_responses '*', {'CLIENT_IP' => '192.162.1.40:60225'}
51+
=> get largelog responses only related to the given
52+
client IP address and port
4753
hbase> get_largelog_responses '*', {'CLIENT_IP' => '192.162.1.40:60225', 'LIMIT' => 100}
4854
=> get largelog responses with given client
4955
IP address and get 100 records limit

hbase-shell/src/main/ruby/shell/commands/get_slowlog_responses.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ def help
4444
=> get slowlog responses only related to meta
4545
region
4646
hbase> get_slowlog_responses '*', {'TABLE_NAME' => 't1'} => get slowlog responses only related to t1 table
47+
hbase> get_slowlog_responses '*', {'CLIENT_IP' => '192.162.1.40'}
48+
=> get slowlog responses only related to the given
49+
client IP address
50+
hbase> get_slowlog_responses '*', {'CLIENT_IP' => '192.162.1.40:60225'}
51+
=> get slowlog responses only related to the given
52+
client IP address and port
4753
hbase> get_slowlog_responses '*', {'CLIENT_IP' => '192.162.1.40:60225', 'LIMIT' => 100}
4854
=> get slowlog responses with given client
4955
IP address and get 100 records limit

0 commit comments

Comments
 (0)