hbase2.x rest server的优化改进
作者 伍增田 Tommy WU
1 增加request log记录功能
RESTServer.java
public static void main(String[] args) throws Exception
// Put up info server.
int port = conf.getInt("hbase.rest.info.port", 8085);
if (port >= 0) {
conf.setLong("startcode", System.currentTimeMillis());
String a = conf.get("hbase.rest.info.bindAddress", "0.0.0.0");
InfoServer infoServer = new InfoServer("rest", a, port, false, conf);
infoServer.setAttribute("hbase.conf", conf);
infoServer.start();
}
// new add
if(conf.getBoolean("hbase.rest.http-request-log", false) ) {
// restserver http request log
org.eclipse.jetty.server.NCSARequestLog ncsaRequestLog = new org.eclipse.jetty.server.NCSARequestLog();
ncsaRequestLog.setFilename(System.getProperty("hbase.log.dir") + "/yyyy_mm_dd_hh.request.log");
ncsaRequestLog.setFilenameDateFormat("yyyy-MM-dd");
ncsaRequestLog.setAppend(true);
ncsaRequestLog.setRetainDays(conf.getInt("hbase.rest.http-request-log.retaindays", 15));
ncsaRequestLog.setExtended(true);
ncsaRequestLog.setLogCookies(true);
ncsaRequestLog.setLogLatency(true);
ncsaRequestLog.setLogServer(true);
ncsaRequestLog.setPreferProxiedForAddress(true);
ncsaRequestLog.setLogTimeZone(java.util.TimeZone.getDefault().getID());
ncsaRequestLog.setLogDateFormat("yyyy_MM_dd HH:mm:ss.SSS Z");
server.setRequestLog(ncsaRequestLog);
}
2 异常exception log记录
ResourceBase.java
protected Response processException(Throwable exp) {
Throwable curr = exp;
LOG.error(exp.toString(), exp);
3 GET响应增加 Content-Length head
RowResource.java
@GET
@Produces(MIMETYPE_BINARY)
public Response getBinary(final @Context UriInfo uriInfo)
ResponseBuilder response = Response.ok(CellUtil.cloneValue(value));
response.header("X-Timestamp", value.getTimestamp());
response.header("Content-Length", value.getValueLength());
[root@localhost logs]# curl -vi -H “Accept: Application/octet-stream” 10.101.14.46:8080/alerts_7/0201342e48_SDH290721495000_20240321101926P.jpg/data: | wc -c
- About to connect() to 10.101.14.46 port 8080 (#0)
- Trying 10.101.14.46…
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:–:-- --:–:-- --:–:-- 0* Connected to 10.101.14.46 (10.101.14.46) port 8080 (#0)
GET /alerts_7/0201342e48_SDH290721495000_20240321101926P.jpg/data: HTTP/1.1
User-Agent: curl/7.29.0
Host: 10.101.14.46:8080
Accept: Application/octet-stream
< HTTP/1.1 200 OK
< X-Timestamp: 1710987566260
< Content-Type: Application/octet-stream
< Content-Length: 15352
<
{ [data not shown]