Skip to content

Commit

Permalink
Merge pull request #15 from project-sunbird/release-1.5.1
Browse files Browse the repository at this point in the history
Release 1.5.1
  • Loading branch information
AMIT KUMAR authored Apr 16, 2018
2 parents 0f14a2c + ecf6820 commit 32a14bb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ node('build-slave') {

env.NODE_ENV = "build"
print "Environment will be : ${env.NODE_ENV}"
sh('git submodule foreach git pull origin release-1.5')
sh('git submodule foreach git pull origin release-1.5.1')
sh 'mvn clean install -DskipTests=true '
dir ('service') {
sh 'mvn play2:dist'
Expand Down
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 32a14bb

Please sign in to comment.