virajjasani commented on a change in pull request #754: HBASE-22978 : Online slow response log URL: https://github.com/apache/hbase/pull/754#discussion_r371610260
########## File path: hbase-client/src/main/java/org/apache/hadoop/hbase/client/SlowLogPayload.java ########## @@ -0,0 +1,318 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hbase.client; + +import org.apache.hadoop.hbase.util.GsonUtil; +import org.apache.yetus.audience.InterfaceAudience; + +import org.apache.hbase.thirdparty.com.google.gson.Gson; +import org.apache.hbase.thirdparty.com.google.gson.JsonObject; +import org.apache.hbase.thirdparty.com.google.gson.JsonSerializer; + +/** + * SlowLog payload for client + */ +@InterfaceAudience.Private +final public class SlowLogPayload { + + private static final Gson GSON = GsonUtil.createGson() + .setPrettyPrinting() + .registerTypeAdapter(SlowLogPayload.class, (JsonSerializer<SlowLogPayload>) + (slowLogPayload, type, jsonSerializationContext) -> { + Gson gson = new Gson(); + JsonObject jsonObj = (JsonObject) gson.toJsonTree(slowLogPayload); + if (slowLogPayload.getMultiGetsCount() == 0) { + jsonObj.remove("multiGetsCount"); + } + if (slowLogPayload.getMultiMutationsCount() == 0) { + jsonObj.remove("multiMutationsCount"); + } + if (slowLogPayload.getMultiServiceCalls() == 0) { + jsonObj.remove("multiServiceCalls"); + } + return jsonObj; + }).create(); + + private long startTime; + private int processingTime; + private int queueTime; + private long responseSize; + private String clientAddress; + private String serverClass; + private String methodName; + private String callDetails; + private String param; + private transient String regionName; + private String userName; + private int multiGetsCount; + private int multiMutationsCount; + private int multiServiceCalls; + + public long getStartTime() { + return startTime; + } + + public int getProcessingTime() { + return processingTime; + } + + public int getQueueTime() { + return queueTime; + } + + public long getResponseSize() { + return responseSize; + } + + public String getClientAddress() { + return clientAddress; + } + + public String getServerClass() { + return serverClass; + } + + public String getMethodName() { + return methodName; + } + + public String getCallDetails() { + return callDetails; + } + + public String getParam() { + return param; + } + + public String getRegionName() { + return regionName; + } + + public String getUserName() { + return userName; + } + + public int getMultiGetsCount() { + return multiGetsCount; + } + + public int getMultiMutationsCount() { + return multiMutationsCount; + } + + public int getMultiServiceCalls() { + return multiServiceCalls; + } + + private SlowLogPayload(final long startTime, final int processingTime, final int queueTime, + final long responseSize, final String clientAddress, final String serverClass, + final String methodName, final String callDetails, final String param, + final String regionName, final String userName, final int multiGetsCount, + final int multiMutationsCount, final int multiServiceCalls) { + this.startTime = startTime; + this.processingTime = processingTime; + this.queueTime = queueTime; + this.responseSize = responseSize; + this.clientAddress = clientAddress; + this.serverClass = serverClass; + this.methodName = methodName; + this.callDetails = callDetails; + this.param = param; + this.regionName = regionName; + this.userName = userName; + this.multiGetsCount = multiGetsCount; + this.multiMutationsCount = multiMutationsCount; + this.multiServiceCalls = multiServiceCalls; + } + + public static class SlowLogPayloadBuilder { + private long startTime; + private int processingTime; + private int queueTime; + private long responseSize; + private String clientAddress; + private String serverClass; + private String methodName; + private String callDetails; + private String param; + private String regionName; + private String userName; + private int multiGetsCount; + private int multiMutationsCount; + private int multiServiceCalls; + + public SlowLogPayloadBuilder setStartTime(long startTime) { + this.startTime = startTime; + return this; + } + + public SlowLogPayloadBuilder setProcessingTime(int processingTime) { + this.processingTime = processingTime; + return this; + } + + public SlowLogPayloadBuilder setQueueTime(int queueTime) { + this.queueTime = queueTime; + return this; + } + + public SlowLogPayloadBuilder setResponseSize(long responseSize) { + this.responseSize = responseSize; + return this; + } + + public SlowLogPayloadBuilder setClientAddress(String clientAddress) { + this.clientAddress = clientAddress; + return this; + } + + public SlowLogPayloadBuilder setServerClass(String serverClass) { + this.serverClass = serverClass; + return this; + } + + public SlowLogPayloadBuilder setMethodName(String methodName) { + this.methodName = methodName; + return this; + } + + public SlowLogPayloadBuilder setCallDetails(String callDetails) { + this.callDetails = callDetails; + return this; + } + + public SlowLogPayloadBuilder setParam(String param) { + this.param = param; + return this; + } + + public SlowLogPayloadBuilder setRegionName(String regionName) { + this.regionName = regionName; + return this; + } + + public SlowLogPayloadBuilder setUserName(String userName) { + this.userName = userName; + return this; + } + + public SlowLogPayloadBuilder setMultiGetsCount(int multiGetsCount) { + this.multiGetsCount = multiGetsCount; + return this; + } + + public SlowLogPayloadBuilder setMultiMutationsCount(int multiMutationsCount) { + this.multiMutationsCount = multiMutationsCount; + return this; + } + + public SlowLogPayloadBuilder setMultiServiceCalls(int multiServiceCalls) { + this.multiServiceCalls = multiServiceCalls; + return this; + } + + public SlowLogPayload build() { + return new SlowLogPayload(startTime, processingTime, queueTime, responseSize, + clientAddress, serverClass, methodName, callDetails, param, regionName, + userName, multiGetsCount, multiMutationsCount, multiServiceCalls); + } + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + SlowLogPayload that = (SlowLogPayload) o; + + if (startTime != that.startTime) { + return false; + } + if (processingTime != that.processingTime) { + return false; + } + if (queueTime != that.queueTime) { + return false; + } + if (responseSize != that.responseSize) { + return false; + } + if (multiGetsCount != that.multiGetsCount) { + return false; + } + if (multiMutationsCount != that.multiMutationsCount) { + return false; + } + if (multiServiceCalls != that.multiServiceCalls) { + return false; + } + if (clientAddress != null ? !clientAddress.equals(that.clientAddress) + : that.clientAddress != null) { + return false; + } + if (serverClass != null ? !serverClass.equals(that.serverClass) + : that.serverClass != null) { + return false; + } + if (methodName != null ? !methodName.equals(that.methodName) : that.methodName != null) { + return false; + } + if (callDetails != null ? !callDetails.equals(that.callDetails) : that.callDetails != null) { + return false; + } + if (param != null ? !param.equals(that.param) : that.param != null) { + return false; + } + if (userName != null ? !userName.equals(that.userName) : that.userName != null) { + return false; + } + return regionName != null ? regionName.equals(that.regionName) : that.regionName == null; + } + + @Override + public int hashCode() { + int result = (int) (startTime ^ (startTime >>> 32)); + result = 31 * result + processingTime; + result = 31 * result + queueTime; + result = 31 * result + (int) (responseSize ^ (responseSize >>> 32)); + result = 31 * result + (clientAddress != null ? clientAddress.hashCode() : 0); + result = 31 * result + (serverClass != null ? serverClass.hashCode() : 0); + result = 31 * result + (methodName != null ? methodName.hashCode() : 0); + result = 31 * result + (callDetails != null ? callDetails.hashCode() : 0); + result = 31 * result + (param != null ? param.hashCode() : 0); + result = 31 * result + (regionName != null ? regionName.hashCode() : 0); + result = 31 * result + (userName != null ? userName.hashCode() : 0); + result = 31 * result + multiGetsCount; + result = 31 * result + multiMutationsCount; + result = 31 * result + multiServiceCalls; + return result; + } + + @Override + public String toString() { + return GSON.toJson(this); Review comment: This is exactly what gets printed as shell output and we want it as "pretty printed" right? Wouldn't that look good? e.g. ``` hbase(main):001:0> get_slowlog_responses '*' 2020-01-27 12:55:52,323 WARN [main] util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable Retrieved SlowLog Responses from RegionServers..... [{ "startTime": 1580109924370, "processingTime": 16, "queueTime": 0, "responseSize": 0, "clientAddress": "10.195.1.17:60480", "serverClass": "HRegionServer", "methodName": "ExecuteProcedures", "callDetails": "ExecuteProcedures(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos$ExecuteProceduresRequest)", "param": "class org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos$ExecuteProceduresRequest", "userName": "vjasani" }, { "startTime": 1580109925134, "processingTime": 2, "queueTime": 0, "responseSize": 112, "clientAddress": "10.195.1.17:60479", "serverClass": "HRegionServer", "methodName": "Scan", "callDetails": "Scan(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos$ScanRequest)", "param": "region { type: REGION_NAME value: \"hbase:meta,,1\" } scan { column { family: \"ns\" } attribute { name: \"_isolationlevel_\" value: \"\\000\" } time_range { from: 0 to: 9223372036854775807 } max_versions: 1 cache_blocks: true max_result_size: 2097152 caching: 100 include_stop_row: false } number_of_rows: 100 close_scanner: false client_handles_partials: true client_handles_heartbeats: true track_scan_metrics: false", "userName": "vjasani" }] ``` Do you think we should use ToStringBuilder here? Then again we use business logic to remove multiXYZ calls if values are 0 the way we are doing right now for Gson.registerTypeAdapter(). If the shell output is too much to see on single screen, user can redirect the output to a file (similar to MySQL https://dev.mysql.com/doc/refman/8.0/en/mysqldumpslow.html) ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services