Skip to content

Commit 7bb0b24

Browse files
committed
HBASE-27638 Get slow/large log response that matched the ‘CLIENT_IP' without client port
1 parent 027a119 commit 7bb0b24

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
@@ -380,6 +380,60 @@ public void testSlowLogFilters() throws Exception {
380380
HBASE_TESTING_UTILITY.waitFor(3000, () -> getSlowLogPayloads(requestSlowLog).size() == 15));
381381
}
382382

383+
@Test
384+
public void testSlowLogFilterWithClientAddress() throws Exception {
385+
Configuration conf = applySlowLogRecorderConf(10);
386+
Constructor<NamedQueueRecorder> constructor =
387+
NamedQueueRecorder.class.getDeclaredConstructor(Configuration.class);
388+
constructor.setAccessible(true);
389+
namedQueueRecorder = constructor.newInstance(conf);
390+
AdminProtos.SlowLogResponseRequest request =
391+
AdminProtos.SlowLogResponseRequest.newBuilder().build();
392+
Assert.assertEquals(getSlowLogPayloads(request).size(), 0);
393+
394+
String[] clientAddressArray = new String[] { "[127:1:1:1:1:1:1:1]:1", "[127:1:1:1:1:1:1:1]:2",
395+
"[127:1:1:1:1:1:1:1]:3", "127.0.0.1:1", "127.0.0.1:2" };
396+
boolean isSlowLog;
397+
boolean isLargeLog;
398+
for (int i = 0; i < 10; i++) {
399+
if (i % 2 == 0) {
400+
isSlowLog = true;
401+
isLargeLog = false;
402+
} else {
403+
isSlowLog = false;
404+
isLargeLog = true;
405+
}
406+
RpcLogDetails rpcLogDetails = getRpcLogDetails("userName_" + (i + 1),
407+
clientAddressArray[i % 5], "class_" + (i + 1), isSlowLog, isLargeLog);
408+
namedQueueRecorder.addRecord(rpcLogDetails);
409+
}
410+
411+
AdminProtos.SlowLogResponseRequest largeLogRequestIPv6WithPort =
412+
AdminProtos.SlowLogResponseRequest.newBuilder()
413+
.setLogType(AdminProtos.SlowLogResponseRequest.LogType.LARGE_LOG)
414+
.setClientAddress("[127:1:1:1:1:1:1:1]:2").build();
415+
Assert.assertNotEquals(-1, HBASE_TESTING_UTILITY.waitFor(3000,
416+
() -> getSlowLogPayloads(largeLogRequestIPv6WithPort).size() == 1));
417+
AdminProtos.SlowLogResponseRequest largeLogRequestIPv6WithoutPort =
418+
AdminProtos.SlowLogResponseRequest.newBuilder()
419+
.setLogType(AdminProtos.SlowLogResponseRequest.LogType.LARGE_LOG)
420+
.setClientAddress("[127:1:1:1:1:1:1:1]").build();
421+
Assert.assertNotEquals(-1, HBASE_TESTING_UTILITY.waitFor(3000,
422+
() -> getSlowLogPayloads(largeLogRequestIPv6WithoutPort).size() == 3));
423+
AdminProtos.SlowLogResponseRequest largeLogRequestIPv4WithPort =
424+
AdminProtos.SlowLogResponseRequest.newBuilder()
425+
.setLogType(AdminProtos.SlowLogResponseRequest.LogType.LARGE_LOG)
426+
.setClientAddress("127.0.0.1:1").build();
427+
Assert.assertNotEquals(-1, HBASE_TESTING_UTILITY.waitFor(3000,
428+
() -> getSlowLogPayloads(largeLogRequestIPv4WithPort).size() == 1));
429+
AdminProtos.SlowLogResponseRequest largeLogRequestIPv4WithoutPort =
430+
AdminProtos.SlowLogResponseRequest.newBuilder()
431+
.setLogType(AdminProtos.SlowLogResponseRequest.LogType.LARGE_LOG)
432+
.setClientAddress("127.0.0.1").build();
433+
Assert.assertNotEquals(-1, HBASE_TESTING_UTILITY.waitFor(3000,
434+
() -> getSlowLogPayloads(largeLogRequestIPv4WithoutPort).size() == 2));
435+
}
436+
383437
@Test
384438
public void testConcurrentSlowLogEvents() throws Exception {
385439

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)