Skip to content

Commit

Permalink
HBASE-15954 REST server should log requests with TRACE instead of DEBUG
Browse files Browse the repository at this point in the history
  • Loading branch information
enis committed Jun 6, 2016
1 parent b21c56e commit 3d7840a
Show file tree
Hide file tree
Showing 21 changed files with 169 additions and 142 deletions.
Expand Up @@ -86,7 +86,9 @@ public Response get(final @Context UriInfo uriInfo) {
}
model.addRow(rowModel);
} else {
LOG.trace("The row : " + rk + " not found in the table.");
if (LOG.isTraceEnabled()) {
LOG.trace("The row : " + rk + " not found in the table.");
}
}
}

Expand Down
Expand Up @@ -91,8 +91,8 @@ public NamespacesInstanceResource(String namespace, boolean queryTables) throws
MIMETYPE_PROTOBUF_IETF})
public Response get(final @Context ServletContext context,
final @Context UriInfo uriInfo) {
if (LOG.isDebugEnabled()) {
LOG.debug("GET " + uriInfo.getAbsolutePath());
if (LOG.isTraceEnabled()) {
LOG.trace("GET " + uriInfo.getAbsolutePath());
}
servlet.getMetrics().incrementRequests(1);

Expand Down Expand Up @@ -135,8 +135,8 @@ public Response get(final @Context ServletContext context,
@Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
MIMETYPE_PROTOBUF_IETF})
public Response put(final NamespacesInstanceModel model, final @Context UriInfo uriInfo) {
if (LOG.isDebugEnabled()) {
LOG.debug("PUT " + uriInfo.getAbsolutePath());
if (LOG.isTraceEnabled()) {
LOG.trace("PUT " + uriInfo.getAbsolutePath());
}
servlet.getMetrics().incrementRequests(1);
return processUpdate(model, true, uriInfo);
Expand All @@ -151,8 +151,8 @@ public Response put(final NamespacesInstanceModel model, final @Context UriInfo
@PUT
public Response putNoBody(final byte[] message,
final @Context UriInfo uriInfo, final @Context HttpHeaders headers) {
if (LOG.isDebugEnabled()) {
LOG.debug("PUT " + uriInfo.getAbsolutePath());
if (LOG.isTraceEnabled()) {
LOG.trace("PUT " + uriInfo.getAbsolutePath());
}
servlet.getMetrics().incrementRequests(1);
try{
Expand All @@ -176,8 +176,8 @@ public Response putNoBody(final byte[] message,
public Response post(final NamespacesInstanceModel model,
final @Context UriInfo uriInfo) {

if (LOG.isDebugEnabled()) {
LOG.debug("POST " + uriInfo.getAbsolutePath());
if (LOG.isTraceEnabled()) {
LOG.trace("POST " + uriInfo.getAbsolutePath());
}
servlet.getMetrics().incrementRequests(1);
return processUpdate(model, false, uriInfo);
Expand All @@ -192,8 +192,8 @@ public Response post(final NamespacesInstanceModel model,
@POST
public Response postNoBody(final byte[] message,
final @Context UriInfo uriInfo, final @Context HttpHeaders headers) {
if (LOG.isDebugEnabled()) {
LOG.debug("POST " + uriInfo.getAbsolutePath());
if (LOG.isTraceEnabled()) {
LOG.trace("POST " + uriInfo.getAbsolutePath());
}
servlet.getMetrics().incrementRequests(1);
try{
Expand Down Expand Up @@ -287,8 +287,8 @@ private boolean doesNamespaceExist(Admin admin, String namespaceName) throws IOE
@DELETE
public Response deleteNoBody(final byte[] message,
final @Context UriInfo uriInfo, final @Context HttpHeaders headers) {
if (LOG.isDebugEnabled()) {
LOG.debug("DELETE " + uriInfo.getAbsolutePath());
if (LOG.isTraceEnabled()) {
LOG.trace("DELETE " + uriInfo.getAbsolutePath());
}
if (servlet.isReadOnly()) {
servlet.getMetrics().incrementFailedDeleteRequests(1);
Expand Down
Expand Up @@ -64,8 +64,8 @@ public NamespacesResource() throws IOException {
@Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
MIMETYPE_PROTOBUF_IETF})
public Response get(final @Context ServletContext context, final @Context UriInfo uriInfo) {
if (LOG.isDebugEnabled()) {
LOG.debug("GET " + uriInfo.getAbsolutePath());
if (LOG.isTraceEnabled()) {
LOG.trace("GET " + uriInfo.getAbsolutePath());
}
servlet.getMetrics().incrementRequests(1);
try {
Expand Down
Expand Up @@ -49,8 +49,10 @@ protected ProtobufStreamingUtil(ResultScanner scanner, String type, int limit, i
this.contentType = type;
this.limit = limit;
this.fetchSize = fetchSize;
LOG.debug("Created ScanStreamingUtil with content type = " + this.contentType + " user limit : "
+ this.limit + " scan fetch size : " + this.fetchSize);
if (LOG.isTraceEnabled()) {
LOG.trace("Created ScanStreamingUtil with content type = " + this.contentType
+ " user limit : " + this.limit + " scan fetch size : " + this.fetchSize);
}
}

@Override
Expand Down Expand Up @@ -82,7 +84,9 @@ private void writeToStream(CellSetModel model, String contentType, OutputStream
outStream.write(Bytes.toBytes((short)objectBytes.length));
outStream.write(objectBytes);
outStream.flush();
LOG.trace("Wrote " + model.getRows().size() + " rows to stream successfully.");
if (LOG.isTraceEnabled()) {
LOG.trace("Wrote " + model.getRows().size() + " rows to stream successfully.");
}
}

private CellSetModel createModelFromResults(Result[] results) {
Expand Down
Expand Up @@ -168,20 +168,26 @@ private static void parseCommandLine(String[] args, RESTServlet servlet) {
if (commandLine != null && commandLine.hasOption("port")) {
String val = commandLine.getOptionValue("port");
servlet.getConfiguration().setInt("hbase.rest.port", Integer.parseInt(val));
LOG.debug("port set to " + val);
if (LOG.isDebugEnabled()) {
LOG.debug("port set to " + val);
}
}

// check if server should only process GET requests, if so override the conf
if (commandLine != null && commandLine.hasOption("readonly")) {
servlet.getConfiguration().setBoolean("hbase.rest.readonly", true);
LOG.debug("readonly set to true");
if (LOG.isDebugEnabled()) {
LOG.debug("readonly set to true");
}
}

// check for user-defined info server port setting, if so override the conf
if (commandLine != null && commandLine.hasOption("infoport")) {
String val = commandLine.getOptionValue("infoport");
servlet.getConfiguration().setInt("hbase.rest.info.port", Integer.parseInt(val));
LOG.debug("Web UI port set to " + val);
if (LOG.isDebugEnabled()) {
LOG.debug("Web UI port set to " + val);
}
}

@SuppressWarnings("unchecked")
Expand Down
Expand Up @@ -20,6 +20,8 @@

import java.io.IOException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.hbase.client.Admin;
Expand All @@ -30,14 +32,13 @@
import org.apache.hadoop.hbase.util.JvmPauseMonitor;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.security.authorize.ProxyUsers;
import org.apache.log4j.Logger;

/**
* Singleton class encapsulating global REST servlet state and functions.
*/
@InterfaceAudience.Private
public class RESTServlet implements Constants {
private static final Logger LOG = Logger.getLogger(RESTServlet.class);
private static final Log LOG = LogFactory.getLog(RESTServlet.class);
private static RESTServlet INSTANCE;
private final Configuration conf;
private final MetricsREST metrics;
Expand Down
Expand Up @@ -71,8 +71,8 @@ public RegionsResource(TableResource tableResource) throws IOException {
@Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
MIMETYPE_PROTOBUF_IETF})
public Response get(final @Context UriInfo uriInfo) {
if (LOG.isDebugEnabled()) {
LOG.debug("GET " + uriInfo.getAbsolutePath());
if (LOG.isTraceEnabled()) {
LOG.trace("GET " + uriInfo.getAbsolutePath());
}
servlet.getMetrics().incrementRequests(1);
try {
Expand Down
Expand Up @@ -72,8 +72,8 @@ private final TableListModel getTableList() throws IOException {
@Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
MIMETYPE_PROTOBUF_IETF})
public Response get(final @Context UriInfo uriInfo) {
if (LOG.isDebugEnabled()) {
LOG.debug("GET " + uriInfo.getAbsolutePath());
if (LOG.isTraceEnabled()) {
LOG.trace("GET " + uriInfo.getAbsolutePath());
}
servlet.getMetrics().incrementRequests(1);
try {
Expand Down
Expand Up @@ -85,8 +85,8 @@ public RowResource(TableResource tableResource, String rowspec,
@Produces({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
MIMETYPE_PROTOBUF_IETF})
public Response get(final @Context UriInfo uriInfo) {
if (LOG.isDebugEnabled()) {
LOG.debug("GET " + uriInfo.getAbsolutePath());
if (LOG.isTraceEnabled()) {
LOG.trace("GET " + uriInfo.getAbsolutePath());
}
servlet.getMetrics().incrementRequests(1);
MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
Expand Down Expand Up @@ -130,8 +130,8 @@ public Response get(final @Context UriInfo uriInfo) {
@GET
@Produces(MIMETYPE_BINARY)
public Response getBinary(final @Context UriInfo uriInfo) {
if (LOG.isDebugEnabled()) {
LOG.debug("GET " + uriInfo.getAbsolutePath() + " as "+ MIMETYPE_BINARY);
if (LOG.isTraceEnabled()) {
LOG.trace("GET " + uriInfo.getAbsolutePath() + " as "+ MIMETYPE_BINARY);
}
servlet.getMetrics().incrementRequests(1);
// doesn't make sense to use a non specific coordinate as this can only
Expand Down Expand Up @@ -221,8 +221,8 @@ Response update(final CellSetModel model, final boolean replace) {
put.addImmutable(parts[0], parts[1], cell.getTimestamp(), cell.getValue());
}
puts.add(put);
if (LOG.isDebugEnabled()) {
LOG.debug("PUT " + put.toString());
if (LOG.isTraceEnabled()) {
LOG.trace("PUT " + put.toString());
}
}
table = servlet.getTable(tableResource.getName());
Expand Down Expand Up @@ -289,8 +289,8 @@ Response updateBinary(final byte[] message, final HttpHeaders headers,
put.addImmutable(parts[0], parts[1], timestamp, message);
table = servlet.getTable(tableResource.getName());
table.put(put);
if (LOG.isDebugEnabled()) {
LOG.debug("PUT " + put.toString());
if (LOG.isTraceEnabled()) {
LOG.trace("PUT " + put.toString());
}
servlet.getMetrics().incrementSucessfulPutRequests(1);
return Response.ok().build();
Expand All @@ -301,7 +301,7 @@ Response updateBinary(final byte[] message, final HttpHeaders headers,
if (table != null) try {
table.close();
} catch (IOException ioe) {
LOG.debug(ioe);
LOG.debug("Exception received while closing the table", ioe);
}
}
}
Expand All @@ -311,8 +311,8 @@ Response updateBinary(final byte[] message, final HttpHeaders headers,
MIMETYPE_PROTOBUF_IETF})
public Response put(final CellSetModel model,
final @Context UriInfo uriInfo) {
if (LOG.isDebugEnabled()) {
LOG.debug("PUT " + uriInfo.getAbsolutePath()
if (LOG.isTraceEnabled()) {
LOG.trace("PUT " + uriInfo.getAbsolutePath()
+ " " + uriInfo.getQueryParameters());
}
return update(model, true);
Expand All @@ -322,8 +322,8 @@ public Response put(final CellSetModel model,
@Consumes(MIMETYPE_BINARY)
public Response putBinary(final byte[] message,
final @Context UriInfo uriInfo, final @Context HttpHeaders headers) {
if (LOG.isDebugEnabled()) {
LOG.debug("PUT " + uriInfo.getAbsolutePath() + " as "+ MIMETYPE_BINARY);
if (LOG.isTraceEnabled()) {
LOG.trace("PUT " + uriInfo.getAbsolutePath() + " as "+ MIMETYPE_BINARY);
}
return updateBinary(message, headers, true);
}
Expand All @@ -333,8 +333,8 @@ public Response putBinary(final byte[] message,
MIMETYPE_PROTOBUF_IETF})
public Response post(final CellSetModel model,
final @Context UriInfo uriInfo) {
if (LOG.isDebugEnabled()) {
LOG.debug("POST " + uriInfo.getAbsolutePath()
if (LOG.isTraceEnabled()) {
LOG.trace("POST " + uriInfo.getAbsolutePath()
+ " " + uriInfo.getQueryParameters());
}
return update(model, false);
Expand All @@ -344,16 +344,16 @@ public Response post(final CellSetModel model,
@Consumes(MIMETYPE_BINARY)
public Response postBinary(final byte[] message,
final @Context UriInfo uriInfo, final @Context HttpHeaders headers) {
if (LOG.isDebugEnabled()) {
LOG.debug("POST " + uriInfo.getAbsolutePath() + " as "+MIMETYPE_BINARY);
if (LOG.isTraceEnabled()) {
LOG.trace("POST " + uriInfo.getAbsolutePath() + " as "+MIMETYPE_BINARY);
}
return updateBinary(message, headers, false);
}

@DELETE
public Response delete(final @Context UriInfo uriInfo) {
if (LOG.isDebugEnabled()) {
LOG.debug("DELETE " + uriInfo.getAbsolutePath());
if (LOG.isTraceEnabled()) {
LOG.trace("DELETE " + uriInfo.getAbsolutePath());
}
servlet.getMetrics().incrementRequests(1);
if (servlet.isReadOnly()) {
Expand Down Expand Up @@ -397,8 +397,8 @@ public Response delete(final @Context UriInfo uriInfo) {
table = servlet.getTable(tableResource.getName());
table.delete(delete);
servlet.getMetrics().incrementSucessfulDeleteRequests(1);
if (LOG.isDebugEnabled()) {
LOG.debug("DELETE " + delete.toString());
if (LOG.isTraceEnabled()) {
LOG.trace("DELETE " + delete.toString());
}
} catch (Exception e) {
servlet.getMetrics().incrementFailedDeleteRequests(1);
Expand All @@ -407,7 +407,7 @@ public Response delete(final @Context UriInfo uriInfo) {
if (table != null) try {
table.close();
} catch (IOException ioe) {
LOG.debug(ioe);
LOG.debug("Exception received while closing the table", ioe);
}
}
return Response.ok().build();
Expand Down Expand Up @@ -499,8 +499,8 @@ Response checkAndPut(final CellSetModel model) {
.build();
}

if (LOG.isDebugEnabled()) {
LOG.debug("CHECK-AND-PUT " + put.toString() + ", returns " + retValue);
if (LOG.isTraceEnabled()) {
LOG.trace("CHECK-AND-PUT " + put.toString() + ", returns " + retValue);
}
if (!retValue) {
servlet.getMetrics().incrementFailedPutRequests(1);
Expand All @@ -517,7 +517,7 @@ Response checkAndPut(final CellSetModel model) {
} finally {
if (table != null) try {
table.close();
} catch (IOException ioe) {
} catch (IOException ioe) {
LOG.debug("Exception received while closing the table", ioe);
}
}
Expand Down Expand Up @@ -627,8 +627,8 @@ Response checkAndDelete(final CellSetModel model) {
.build();
}

if (LOG.isDebugEnabled()) {
LOG.debug("CHECK-AND-DELETE " + delete.toString() + ", returns "
if (LOG.isTraceEnabled()) {
LOG.trace("CHECK-AND-DELETE " + delete.toString() + ", returns "
+ retValue);
}

Expand Down

0 comments on commit 3d7840a

Please sign in to comment.