Skip to content

Commit

Permalink
rsOperationDetails UI fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ray Mattingly committed Jul 31, 2023
1 parent db79ecf commit 5a5fe19
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@

import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.GsonUtil;
import org.apache.yetus.audience.InterfaceAudience;
import org.apache.yetus.audience.InterfaceStability;
Expand All @@ -32,6 +30,8 @@
import org.apache.hbase.thirdparty.com.google.gson.JsonObject;
import org.apache.hbase.thirdparty.com.google.gson.JsonSerializer;

import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;

/**
* Slow/Large Log payload for hbase-client, to be used by Admin API get_slow_responses and
* get_large_responses
Expand Down Expand Up @@ -59,14 +59,14 @@ final public class OnlineLogRecord extends LogEntry {
if (slowLogPayload.getRequestAttributes().isEmpty()) {
jsonObj.remove("requestAttributes");
} else {
jsonObj.add("requestAttributes",
gson.toJsonTree(deserializeAttributes(slowLogPayload.getRequestAttributes())));
jsonObj.add("requestAttributes", gson
.toJsonTree(ProtobufUtil.deserializeAttributes(slowLogPayload.getRequestAttributes())));
}
if (slowLogPayload.getConnectionAttributes().isEmpty()) {
jsonObj.remove("connectionAttributes");
} else {
jsonObj.add("connectionAttributes",
gson.toJsonTree(deserializeAttributes(slowLogPayload.getConnectionAttributes())));
jsonObj.add("connectionAttributes", gson.toJsonTree(
ProtobufUtil.deserializeAttributes(slowLogPayload.getConnectionAttributes())));
}
if (slowLogPayload.getScan().isPresent()) {
jsonObj.add("scan", gson.toJsonTree(slowLogPayload.getScan().get().toMap()));
Expand Down Expand Up @@ -378,9 +378,4 @@ public String toString() {
.append("connectionAttributes", connectionAttributes).toString();
}

public static Map<String, String> deserializeAttributes(Map<String, byte[]> attributes) {
return attributes.entrySet().stream().collect(
Collectors.toMap(Map.Entry::getKey, entry -> Bytes.toStringBinary(entry.getValue())));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2196,6 +2196,25 @@ public static SlowLogParams getSlowLogParams(Message message, boolean slowLogSca
return new SlowLogParams(params);
}

/**
* Convert a List<NameBytesPair> to a more readable CSV
*/
public static String convertAttributesToCsv(List<NameBytesPair> attributes) {
if (attributes.isEmpty()) {
return HConstants.EMPTY_STRING;
}
return deserializeAttributes(convertNameBytesPairsToMap(attributes)).entrySet().stream()
.map(entry -> entry.getKey() + " = " + entry.getValue()).collect(Collectors.joining(", "));
}

/**
* Convert a Map<String, byte[]> to a more readable Map<String, String>
*/
public static Map<String, String> deserializeAttributes(Map<String, byte[]> attributes) {
return attributes.entrySet().stream().collect(
Collectors.toMap(Map.Entry::getKey, entry -> Bytes.toStringBinary(entry.getValue())));
}

/**
* Print out some subset of a MutationProto rather than all of it and its data
* @param proto Protobuf to print out
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.util.Collections;
import java.util.Map;
import java.util.Set;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.ClientTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
Expand All @@ -29,6 +30,7 @@
import org.junit.experimental.categories.Category;

import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap;
import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableSet;

@Category({ ClientTests.class, SmallTests.class })
public class TestOnlineLogRecord {
Expand Down Expand Up @@ -62,16 +64,14 @@ public void itSerializesScan() {
public void itSerializesRequestAttributes() {
Map<String, byte[]> requestAttributes = ImmutableMap.<String, byte[]> builder()
.put("r", Bytes.toBytes("1")).put("2", Bytes.toBytes(0.0)).build();
String expectedOutput = "{\n" + " \"startTime\": 1,\n" + " \"processingTime\": 2,\n"
+ " \"queueTime\": 3,\n" + " \"responseSize\": 4,\n" + " \"blockBytesScanned\": 5,\n"
+ " \"multiGetsCount\": 6,\n" + " \"multiMutationsCount\": 7,\n"
+ " \"requestAttributes\": {\n" + " \"r\": \"1\",\n"
+ " \"2\": \"\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\"\n" + " }\n" + "}";
Set<String> expectedOutputs =
ImmutableSet.<String> builder().add("requestAttributes").add("\"r\": \"1\"")
.add("\"2\": \"\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\"").build();
OnlineLogRecord o = new OnlineLogRecord(1, 2, 3, 4, 5, null, null, null, null, null, null, null,
6, 7, 0, null, requestAttributes, Collections.emptyMap());
String actualOutput = o.toJsonPrettyPrint();
System.out.println(actualOutput);
Assert.assertEquals(actualOutput, expectedOutput);
expectedOutputs.forEach(expected -> Assert.assertTrue(actualOutput.contains(expected)));
}

@Test
Expand All @@ -87,17 +87,14 @@ public void itOmitsEmptyRequestAttributes() {
public void itSerializesConnectionAttributes() {
Map<String, byte[]> connectionAttributes = ImmutableMap.<String, byte[]> builder()
.put("c", Bytes.toBytes("1")).put("2", Bytes.toBytes(0.0)).build();
String expectedOutput = "{\n" + " \"startTime\": 1,\n" + " \"processingTime\": 2,\n"
+ " \"queueTime\": 3,\n" + " \"responseSize\": 4,\n" + " \"blockBytesScanned\": 5,\n"
+ " \"multiGetsCount\": 6,\n" + " \"multiMutationsCount\": 7,\n"
+ " \"connectionAttributes\": {\n"
+ " \"2\": \"\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\",\n"
+ " \"c\": \"1\"\n" + " }\n" + "}";
Set<String> expectedOutputs =
ImmutableSet.<String> builder().add("requestAttributes").add("\"c\": \"1\"")
.add("\"2\": \"\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\"").build();
OnlineLogRecord o = new OnlineLogRecord(1, 2, 3, 4, 5, null, null, null, null, null, null, null,
6, 7, 0, null, Collections.emptyMap(), connectionAttributes);
String actualOutput = o.toJsonPrettyPrint();
System.out.println(actualOutput);
Assert.assertEquals(actualOutput, expectedOutput);
expectedOutputs.forEach(expected -> Assert.assertTrue(actualOutput.contains(expected)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import="org.apache.hadoop.util.StringUtils"
import="org.apache.hadoop.hbase.regionserver.HRegionServer"
import="org.apache.hadoop.hbase.HConstants"
import="org.apache.hadoop.hbase.client.OnlineLogRecord.deserializeAttributes"
import="org.apache.hadoop.hbase.shaded.protobuf.generated.TooSlowLog"
import="org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil"
import="org.apache.hadoop.hbase.namequeues.NamedQueueRecorder"
import="org.apache.hadoop.hbase.namequeues.RpcLogDetails"
import="org.apache.hadoop.hbase.namequeues.request.NamedQueueGetRequest"
Expand Down Expand Up @@ -130,8 +130,8 @@
<td><%=r.getMultiServiceCalls()%></td>
<td><%=r.getCallDetails()%></td>
<td><%=r.getParam()%></td>
<td><%=deserializeAttributes(r.getRequestAttributes())%></td>
<td><%=deserializeAttributes(r.getConnectionAttributes())%></td>
<td><%=ProtobufUtil.convertAttributesToCsv(r.getRequestAttributeList())%></td>
<td><%=ProtobufUtil.convertAttributesToCsv(r.getConnectionAttributeList())%></td>
</tr>
<% } %>
<% } %>
Expand Down Expand Up @@ -177,8 +177,8 @@
<td><%=r.getMultiServiceCalls()%></td>
<td><%=r.getCallDetails()%></td>
<td><%=r.getParam()%></td>
<td><%=deserializeAttributes(r.getRequestAttributes())%></td>
<td><%=deserializeAttributes(r.getConnectionAttributes())%></td>
<td><%=ProtobufUtil.convertAttributesToCsv(r.getRequestAttributeList())%></td>
<td><%=ProtobufUtil.convertAttributesToCsv(r.getConnectionAttributeList())%></td>
</tr>
<% } %>
<% } %>
Expand Down

0 comments on commit 5a5fe19

Please sign in to comment.