Skip to content

Commit

Permalink
[feature] adding response status code to the statistics filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdollahi authored and Abdollahi committed Mar 6, 2024
1 parent 4c569c3 commit 876d3d4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.8</version>
<version>3.1.9</version>
<relativePath />
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,25 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
try {
filterChain.doFilter(request, response);
} finally {
end(serviceName, startTime);
end(serviceName, response.getStatus(), startTime);
}
}

private void start(String serviceName) {
final Map<String, Object> inwardLog = new LinkedHashMap<>();
inwardLog.put("+service", serviceName);
inwardLog.put("active requests", activeRequestsCount.incrementAndGet());
inwardLog.put("active-requests", activeRequestsCount.incrementAndGet());
LOGGER.info(writeJson(inwardLog));
}

private void end(String serviceName, long startTime) {
private void end(String serviceName, int statusCode, long startTime) {
double duration = (System.currentTimeMillis() - startTime) / 1000.0;
final Map<String, Object> outwardLog = new LinkedHashMap<>();
outwardLog.put("-service", serviceName);
outwardLog.put("status", statusCode);
List<ServiceExecutionInfo> serviceExecutionInfos = Statistics.getApplicationStatistics().getServiceExecutionsInfo();
outwardLog.put("duration", duration + "s");
outwardLog.put("active requests", activeRequestsCount.decrementAndGet());
outwardLog.put("active-requests", activeRequestsCount.decrementAndGet());
if (!serviceExecutionInfos.isEmpty()) {
outwardLog.put("statistics", generateStatisticsDetail(serviceExecutionInfos));
}
Expand Down

0 comments on commit 876d3d4

Please sign in to comment.