Skip to content

Commit

Permalink
response time as float
Browse files Browse the repository at this point in the history
  • Loading branch information
michalsomora committed Nov 21, 2023
1 parent f77bcdd commit 860707e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,16 @@ public void filter(ClientRequestContext requestContext, ClientResponseContext re
context.close();

if (config.client.end.mdc.enabled) {
MDC.put(config.client.end.mdc.durationName, context.time);
MDC.put(config.client.end.mdc.durationName, context.durationSec);
context.mdcKeys.add(config.client.end.mdc.durationName);

MDC.put(config.client.end.mdc.responseStatusName, status.getStatusCode());
context.mdcKeys.add(config.end.mdc.responseStatusName);
context.mdcKeys.add(config.client.end.mdc.responseStatusName);
}

if (config.client.end.enabled) {
log.info(String.format(config.client.end.template, context.method, context.uri,
context.time, status.getStatusCode(), status.getReasonPhrase()));
context.durationString, status.getStatusCode(), status.getReasonPhrase()));
}
} finally {
// clean up MDC header keys
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.tkit.quarkus.log.rs;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.HashSet;
import java.util.Set;

Expand All @@ -13,19 +15,25 @@ public class RestInterceptorContext {

String path;

String time;

boolean exclude = false;

Set<String> mdcKeys = new HashSet<>();

private final long startTime;

long durationMillis;

double durationSec;

String durationString;

RestInterceptorContext() {
this.startTime = System.currentTimeMillis();
}

public void close() {
time = String.format("%.3f", (System.currentTimeMillis() - startTime) / 1000f);
durationMillis = (System.currentTimeMillis() - startTime);
durationSec = BigDecimal.valueOf(durationMillis / 1000f).setScale(3, RoundingMode.HALF_DOWN).doubleValue();
durationString = String.format("%.3f", durationSec);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void filter(ContainerRequestContext requestContext, ContainerResponseCont
Response.StatusType status = responseContext.getStatusInfo();

if (config.end.mdc.enabled) {
MDC.put(config.end.mdc.durationName, restContext.time);
MDC.put(config.end.mdc.durationName, restContext.durationSec);
restContext.mdcKeys.add(config.end.mdc.durationName);

MDC.put(config.end.mdc.responseStatusName, status.getStatusCode());
Expand All @@ -147,7 +147,7 @@ public void filter(ContainerRequestContext requestContext, ContainerResponseCont

LoggerFactory.getLogger(resourceInfo.getResourceClass())
.info(String.format(config.end.template, restContext.method, restContext.path,
restContext.time, status.getStatusCode(), status.getReasonPhrase(),
restContext.durationString, status.getStatusCode(), status.getReasonPhrase(),
restContext.uri));
}
} finally {
Expand Down

0 comments on commit 860707e

Please sign in to comment.