YARN-4203. Add request/response logging & timing for each REST endpoint call (Varun Saxena via vrushali)
This commit is contained in:
parent
d95dc89a02
commit
da2b7bd08e
@ -44,6 +44,7 @@
|
|||||||
import org.apache.hadoop.classification.InterfaceAudience.Private;
|
import org.apache.hadoop.classification.InterfaceAudience.Private;
|
||||||
import org.apache.hadoop.classification.InterfaceStability.Unstable;
|
import org.apache.hadoop.classification.InterfaceStability.Unstable;
|
||||||
import org.apache.hadoop.security.UserGroupInformation;
|
import org.apache.hadoop.security.UserGroupInformation;
|
||||||
|
import org.apache.hadoop.util.Time;
|
||||||
import org.apache.hadoop.yarn.api.records.timeline.TimelineAbout;
|
import org.apache.hadoop.yarn.api.records.timeline.TimelineAbout;
|
||||||
import org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity;
|
import org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity;
|
||||||
import org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntityType;
|
import org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntityType;
|
||||||
@ -68,6 +69,7 @@ public class TimelineReaderWebServices {
|
|||||||
|
|
||||||
private static final String COMMA_DELIMITER = ",";
|
private static final String COMMA_DELIMITER = ",";
|
||||||
private static final String COLON_DELIMITER = ":";
|
private static final String COLON_DELIMITER = ":";
|
||||||
|
private static final String QUERY_STRING_SEP = "?";
|
||||||
|
|
||||||
private void init(HttpServletResponse response) {
|
private void init(HttpServletResponse response) {
|
||||||
response.setContentType(null);
|
response.setContentType(null);
|
||||||
@ -185,14 +187,24 @@ private static UserGroupInformation getUser(HttpServletRequest req) {
|
|||||||
return callerUGI;
|
return callerUGI;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getUserName(UserGroupInformation callerUGI) {
|
||||||
|
return ((callerUGI != null) ? callerUGI.getUserName().trim() : "");
|
||||||
|
}
|
||||||
|
|
||||||
private TimelineReaderManager getTimelineReaderManager() {
|
private TimelineReaderManager getTimelineReaderManager() {
|
||||||
return (TimelineReaderManager)
|
return (TimelineReaderManager)
|
||||||
ctxt.getAttribute(TimelineReaderServer.TIMELINE_READER_MANAGER_ATTR);
|
ctxt.getAttribute(TimelineReaderServer.TIMELINE_READER_MANAGER_ATTR);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void handleException(Exception e) throws BadRequestException,
|
private static void handleException(Exception e, String url, long startTime,
|
||||||
|
String invalidNumMsg) throws BadRequestException,
|
||||||
WebApplicationException {
|
WebApplicationException {
|
||||||
if (e instanceof IllegalArgumentException) {
|
long endTime = Time.monotonicNow();
|
||||||
|
LOG.info("Processed URL " + url + " but encountered exception (Took " +
|
||||||
|
(endTime - startTime) + " ms.)");
|
||||||
|
if (e instanceof NumberFormatException) {
|
||||||
|
throw new BadRequestException(invalidNumMsg + " is not a numeric value.");
|
||||||
|
} else if (e instanceof IllegalArgumentException) {
|
||||||
throw new BadRequestException("Requested Invalid Field.");
|
throw new BadRequestException("Requested Invalid Field.");
|
||||||
} else {
|
} else {
|
||||||
LOG.error("Error while processing REST request", e);
|
LOG.error("Error while processing REST request", e);
|
||||||
@ -273,9 +285,14 @@ public Set<TimelineEntity> getEntities(
|
|||||||
@QueryParam("metricfilters") String metricfilters,
|
@QueryParam("metricfilters") String metricfilters,
|
||||||
@QueryParam("eventfilters") String eventfilters,
|
@QueryParam("eventfilters") String eventfilters,
|
||||||
@QueryParam("fields") String fields) {
|
@QueryParam("fields") String fields) {
|
||||||
|
String url = req.getRequestURI() +
|
||||||
|
(null == req.getQueryString() ? "" :
|
||||||
|
QUERY_STRING_SEP + req.getQueryString());
|
||||||
|
UserGroupInformation callerUGI = getUser(req);
|
||||||
|
LOG.info("Received URL " + url + " from user " + getUserName(callerUGI));
|
||||||
|
long startTime = Time.monotonicNow();
|
||||||
init(res);
|
init(res);
|
||||||
TimelineReaderManager timelineReaderManager = getTimelineReaderManager();
|
TimelineReaderManager timelineReaderManager = getTimelineReaderManager();
|
||||||
UserGroupInformation callerUGI = getUser(req);
|
|
||||||
Set<TimelineEntity> entities = null;
|
Set<TimelineEntity> entities = null;
|
||||||
try {
|
try {
|
||||||
entities = timelineReaderManager.getEntities(
|
entities = timelineReaderManager.getEntities(
|
||||||
@ -291,16 +308,16 @@ public Set<TimelineEntity> getEntities(
|
|||||||
parseValuesStr(metricfilters, COMMA_DELIMITER),
|
parseValuesStr(metricfilters, COMMA_DELIMITER),
|
||||||
parseValuesStr(eventfilters, COMMA_DELIMITER),
|
parseValuesStr(eventfilters, COMMA_DELIMITER),
|
||||||
parseFieldsStr(fields, COMMA_DELIMITER));
|
parseFieldsStr(fields, COMMA_DELIMITER));
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
throw new BadRequestException(
|
|
||||||
"createdTime or modifiedTime start/end or limit or flowId is not" +
|
|
||||||
" a numeric value.");
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleException(e);
|
handleException(e, url, startTime,
|
||||||
|
"createdTime or modifiedTime start/end or limit or flowId");
|
||||||
}
|
}
|
||||||
|
long endTime = Time.monotonicNow();
|
||||||
if (entities == null) {
|
if (entities == null) {
|
||||||
entities = Collections.emptySet();
|
entities = Collections.emptySet();
|
||||||
}
|
}
|
||||||
|
LOG.info("Processed URL " + url +
|
||||||
|
" (Took " + (endTime - startTime) + " ms.)");
|
||||||
return entities;
|
return entities;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -342,24 +359,32 @@ public TimelineEntity getEntity(
|
|||||||
@QueryParam("flowid") String flowId,
|
@QueryParam("flowid") String flowId,
|
||||||
@QueryParam("flowrunid") String flowRunId,
|
@QueryParam("flowrunid") String flowRunId,
|
||||||
@QueryParam("fields") String fields) {
|
@QueryParam("fields") String fields) {
|
||||||
|
String url = req.getRequestURI() +
|
||||||
|
(null == req.getQueryString() ? "" :
|
||||||
|
QUERY_STRING_SEP + req.getQueryString());
|
||||||
|
UserGroupInformation callerUGI = getUser(req);
|
||||||
|
LOG.info("Received URL " + url + " from user " + getUserName(callerUGI));
|
||||||
|
long startTime = Time.monotonicNow();
|
||||||
init(res);
|
init(res);
|
||||||
TimelineReaderManager timelineReaderManager = getTimelineReaderManager();
|
TimelineReaderManager timelineReaderManager = getTimelineReaderManager();
|
||||||
UserGroupInformation callerUGI = getUser(req);
|
|
||||||
TimelineEntity entity = null;
|
TimelineEntity entity = null;
|
||||||
try {
|
try {
|
||||||
entity = timelineReaderManager.getEntity(
|
entity = timelineReaderManager.getEntity(
|
||||||
parseUser(callerUGI, userId), parseStr(clusterId), parseStr(flowId),
|
parseUser(callerUGI, userId), parseStr(clusterId), parseStr(flowId),
|
||||||
parseLongStr(flowRunId), parseStr(appId), parseStr(entityType),
|
parseLongStr(flowRunId), parseStr(appId), parseStr(entityType),
|
||||||
parseStr(entityId), parseFieldsStr(fields, COMMA_DELIMITER));
|
parseStr(entityId), parseFieldsStr(fields, COMMA_DELIMITER));
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
throw new BadRequestException("flowrunid is not a numeric value.");
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleException(e);
|
handleException(e, url, startTime, "flowrunid");
|
||||||
}
|
}
|
||||||
|
long endTime = Time.monotonicNow();
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
|
LOG.info("Processed URL " + url + " but entity not found" + " (Took " +
|
||||||
|
(endTime - startTime) + " ms.)");
|
||||||
throw new NotFoundException("Timeline entity {id: " + parseStr(entityId) +
|
throw new NotFoundException("Timeline entity {id: " + parseStr(entityId) +
|
||||||
", type: " + parseStr(entityType) + " } is not found");
|
", type: " + parseStr(entityType) + " } is not found");
|
||||||
}
|
}
|
||||||
|
LOG.info("Processed URL " + url +
|
||||||
|
" (Took " + (endTime - startTime) + " ms.)");
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -394,9 +419,14 @@ public TimelineEntity getFlowRun(
|
|||||||
@PathParam("flowrunid") String flowRunId,
|
@PathParam("flowrunid") String flowRunId,
|
||||||
@QueryParam("userid") String userId,
|
@QueryParam("userid") String userId,
|
||||||
@QueryParam("fields") String fields) {
|
@QueryParam("fields") String fields) {
|
||||||
|
String url = req.getRequestURI() +
|
||||||
|
(null == req.getQueryString() ? "" :
|
||||||
|
QUERY_STRING_SEP + req.getQueryString());
|
||||||
|
UserGroupInformation callerUGI = getUser(req);
|
||||||
|
LOG.info("Received URL " + url + " from user " + getUserName(callerUGI));
|
||||||
|
long startTime = Time.monotonicNow();
|
||||||
init(res);
|
init(res);
|
||||||
TimelineReaderManager timelineReaderManager = getTimelineReaderManager();
|
TimelineReaderManager timelineReaderManager = getTimelineReaderManager();
|
||||||
UserGroupInformation callerUGI = getUser(req);
|
|
||||||
TimelineEntity entity = null;
|
TimelineEntity entity = null;
|
||||||
try {
|
try {
|
||||||
entity = timelineReaderManager.getEntity(
|
entity = timelineReaderManager.getEntity(
|
||||||
@ -404,15 +434,18 @@ public TimelineEntity getFlowRun(
|
|||||||
parseStr(flowId), parseLongStr(flowRunId), null,
|
parseStr(flowId), parseLongStr(flowRunId), null,
|
||||||
TimelineEntityType.YARN_FLOW_RUN.toString(), null,
|
TimelineEntityType.YARN_FLOW_RUN.toString(), null,
|
||||||
parseFieldsStr(fields, COMMA_DELIMITER));
|
parseFieldsStr(fields, COMMA_DELIMITER));
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
throw new BadRequestException("flowRunId is not a numeric value.");
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleException(e);
|
handleException(e, url, startTime, "flowrunid");
|
||||||
}
|
}
|
||||||
|
long endTime = Time.monotonicNow();
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
|
LOG.info("Processed URL " + url + " but flowrun not found (Took " +
|
||||||
|
(endTime - startTime) + " ms.)");
|
||||||
throw new NotFoundException("Flow run {flow id: " + parseStr(flowId) +
|
throw new NotFoundException("Flow run {flow id: " + parseStr(flowId) +
|
||||||
", run id: " + parseLongStr(flowRunId) + " } is not found");
|
", run id: " + parseLongStr(flowRunId) + " } is not found");
|
||||||
}
|
}
|
||||||
|
LOG.info("Processed URL " + url +
|
||||||
|
" (Took " + (endTime - startTime) + " ms.)");
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -443,6 +476,12 @@ public Set<TimelineEntity> getFlows(
|
|||||||
@PathParam("clusterid") String clusterId,
|
@PathParam("clusterid") String clusterId,
|
||||||
@QueryParam("limit") String limit,
|
@QueryParam("limit") String limit,
|
||||||
@QueryParam("fields") String fields) {
|
@QueryParam("fields") String fields) {
|
||||||
|
String url = req.getRequestURI() +
|
||||||
|
(null == req.getQueryString() ? "" :
|
||||||
|
QUERY_STRING_SEP + req.getQueryString());
|
||||||
|
UserGroupInformation callerUGI = getUser(req);
|
||||||
|
LOG.info("Received URL " + url + " from user " + getUserName(callerUGI));
|
||||||
|
long startTime = Time.monotonicNow();
|
||||||
init(res);
|
init(res);
|
||||||
TimelineReaderManager timelineReaderManager = getTimelineReaderManager();
|
TimelineReaderManager timelineReaderManager = getTimelineReaderManager();
|
||||||
Set<TimelineEntity> entities = null;
|
Set<TimelineEntity> entities = null;
|
||||||
@ -452,14 +491,15 @@ null, parseStr(clusterId), null, null, null,
|
|||||||
TimelineEntityType.YARN_FLOW_ACTIVITY.toString(), parseLongStr(limit),
|
TimelineEntityType.YARN_FLOW_ACTIVITY.toString(), parseLongStr(limit),
|
||||||
null, null, null, null, null, null, null, null, null, null,
|
null, null, null, null, null, null, null, null, null, null,
|
||||||
parseFieldsStr(fields, COMMA_DELIMITER));
|
parseFieldsStr(fields, COMMA_DELIMITER));
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
throw new BadRequestException("limit is not a numeric value.");
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleException(e);
|
handleException(e, url, startTime, "limit");
|
||||||
}
|
}
|
||||||
|
long endTime = Time.monotonicNow();
|
||||||
if (entities == null) {
|
if (entities == null) {
|
||||||
entities = Collections.emptySet();
|
entities = Collections.emptySet();
|
||||||
}
|
}
|
||||||
|
LOG.info("Processed URL " + url +
|
||||||
|
" (Took " + (endTime - startTime) + " ms.)");
|
||||||
return entities;
|
return entities;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user