ndimiduk commented on a change in pull request #754: HBASE-22978 : Online slow 
response log
URL: https://github.com/apache/hbase/pull/754#discussion_r378428516
 
 

 ##########
 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:
   I still think the concerns of logging (`toString`) and the concerns of user 
interaction (shell, pretty-printing or not, field filters or not, field order, 
&c) should be separate.

----------------------------------------------------------------
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

Reply via email to