Skip to content

Commit

Permalink
Issue # SBB-1 feat : merge master to branch 1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
arvindyadav108 committed Apr 16, 2018
2 parents 26d8048 + 32a14bb commit 564bea5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion metadata.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
# return version
echo '{"name":"learner_service","version":"1.5.0","org":"sunbird","hubuser":"purplesunbird"}'
echo '{"name":"learner_service","version":"1.5.1","org":"sunbird","hubuser":"purplesunbird"}'
26 changes: 23 additions & 3 deletions service/app/controllers/BaseController.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,10 @@ public Result createCommonResponse(Object response, String key, Request request)
params.put(JsonKey.LOG_TYPE, JsonKey.API_ACCESS);
params.put(JsonKey.MESSAGE, "");
params.put(JsonKey.METHOD, request.method());
params.put(JsonKey.END_TIME, System.currentTimeMillis());
// calculate the total time consume
long startTime = (Long) params.get(JsonKey.START_TIME);
params.put(JsonKey.DURATION , calculateApiTimeTaken(startTime));
removeFields(params , JsonKey.START_TIME);
params.put(JsonKey.STATUS, String.valueOf(((Response) response).getResponseCode().getResponseCode()));
params.put(JsonKey.LOG_LEVEL, JsonKey.INFO);
req.setRequest(generateTelemetryRequestForController(TelemetryEvents.LOG.getName(), params,
Expand Down Expand Up @@ -294,6 +297,12 @@ public Result createCommonResponse(Object response, String key, Request request)
*/
}

private void removeFields(Map<String, Object> params, String... properties) {
for(String property: properties){
params.remove(property);
}
}

private String generateStackTrace(StackTraceElement[] elements) {
StringBuilder builder = new StringBuilder("");
for (StackTraceElement element : elements) {
Expand Down Expand Up @@ -344,8 +353,10 @@ public Result createCommonExceptionResponse(Exception e, Request request) {
params.put(JsonKey.LOG_TYPE, JsonKey.API_ACCESS);
params.put(JsonKey.MESSAGE, "");
params.put(JsonKey.METHOD, request.method());
long endTime = System.currentTimeMillis();
params.put(JsonKey.END_TIME, endTime);
// calculate the total time consume
long startTime = (Long) params.get(JsonKey.START_TIME);
params.put(JsonKey.DURATION , calculateApiTimeTaken(startTime));
removeFields(params , JsonKey.START_TIME);
params.put(JsonKey.STATUS, String.valueOf(exception.getResponseCode()));
params.put(JsonKey.LOG_LEVEL, "error");
params.put(JsonKey.STACKTRACE, generateStackTrace(exception.getStackTrace()));
Expand All @@ -358,6 +369,15 @@ public Result createCommonExceptionResponse(Exception e, Request request) {
Json.toJson(BaseController.createResponseOnException(req, exception)));
}

private long calculateApiTimeTaken(Long startTime) {

Long timeConsumed=null;
if(null != startTime ){
timeConsumed= System.currentTimeMillis() - startTime;
}
return timeConsumed;
}

/**
* This method will make a call to Akka actor and return promise.
*
Expand Down

0 comments on commit 564bea5

Please sign in to comment.