Add response time to tx log

This commit is contained in:
Grahame Grieve 2024-09-24 20:25:02 -04:00
parent b37073592b
commit a1f014730e
16 changed files with 19 additions and 18 deletions

View File

@ -683,7 +683,7 @@ public class ClientUtils {
for (Header h : response.getAllHeaders()) {
headers.add(h.toString());
}
logger.logResponse(response.getStatusLine().toString(), headers, cnt);
logger.logResponse(response.getStatusLine().toString(), headers, cnt, 0);
}
return cnt;
}

View File

@ -625,7 +625,7 @@ public class ClientUtils {
for (Header h : response.getAllHeaders()) {
headers.add(h.toString());
}
logger.logResponse(response.getStatusLine().toString(), headers, cnt);
logger.logResponse(response.getStatusLine().toString(), headers, cnt, 0);
}
return cnt;
}

View File

@ -371,7 +371,7 @@ public class FhirRequestBuilder {
try {
if (logger != null) {
logger.logResponse(Integer.toString(responseCode), headerList, responseBody);
logger.logResponse(Integer.toString(responseCode), headerList, responseBody, 0);
}
} catch (Exception e) {
System.out.println("Error parsing response body passed in to logger ->\n" + e.getLocalizedMessage());

View File

@ -95,13 +95,13 @@ public class FhirRequestBuilderTests {
Mockito.doReturn(parser).when(fhirRequestBuilder).getParser(ArgumentMatchers.eq("json"));
fhirRequestBuilder.unmarshalReference(response, "json");
Mockito.verify(logger).logResponse(ArgumentMatchers.eq("200"), ArgumentMatchers.anyList(), AdditionalMatchers.aryEq(RESPONSE_BODY_STRING.getBytes()));
Mockito.verify(logger).logResponse(ArgumentMatchers.eq("200"), ArgumentMatchers.anyList(), AdditionalMatchers.aryEq(RESPONSE_BODY_STRING.getBytes()), 0);
}
@Test
public void testUnmarshallFeedLogging() {
fhirRequestBuilder.unmarshalFeed(response, "application/json");
Mockito.verify(logger).logResponse(ArgumentMatchers.eq("200"), ArgumentMatchers.anyList(), AdditionalMatchers.aryEq(RESPONSE_BODY_STRING.getBytes()));
Mockito.verify(logger).logResponse(ArgumentMatchers.eq("200"), ArgumentMatchers.anyList(), AdditionalMatchers.aryEq(RESPONSE_BODY_STRING.getBytes()), 0);
}
}

View File

@ -77,7 +77,7 @@ public class HTMLClientLogger implements ToolingClientLogger {
}
@Override
public void logResponse(String outcome, List<String> headers, byte[] body) {
public void logResponse(String outcome, List<String> headers, byte[] body, long start) {
if (file == null)
return;
file.println("<pre>");

View File

@ -64,7 +64,7 @@ public class FhirLoggingInterceptor implements Interceptor {
headerMap.keySet().forEach(key -> headerMap.get(key).forEach(value -> headerList.add(key + ":" + value)));
if (logger != null) {
logger.logResponse(Integer.toString(response.code()), headerList, bodyBytes);
logger.logResponse(Integer.toString(response.code()), headerList, bodyBytes, 0);
}
// Reading byte[] clears body. Need to recreate.

View File

@ -85,7 +85,7 @@ public class HTMLClientLogger extends BaseLogger implements ToolingClientLogger
}
@Override
public void logResponse(String outcome, List<String> headers, byte[] body) {
public void logResponse(String outcome, List<String> headers, byte[] body, long start) {
if (DEBUG) {
System.out.println(" txlog resp: " + outcome + " " + present(body));
}

View File

@ -72,7 +72,7 @@ public class TextClientLogger extends BaseLogger implements ToolingClientLogger
}
@Override
public void logResponse(String outcome, List<String> headers, byte[] body) {
public void logResponse(String outcome, List<String> headers, byte[] body, long start) {
if (file == null)
return;
file.println("\r\n\r\nResponse: \r\n");

View File

@ -59,7 +59,7 @@ public class FhirLoggingInterceptor implements Interceptor {
headerMap.keySet().forEach(key -> headerMap.get(key).forEach(value -> headerList.add(key + ":" + value)));
if (logger != null) {
logger.logResponse(Integer.toString(response.code()), headerList, bodyBytes);
logger.logResponse(Integer.toString(response.code()), headerList, bodyBytes, 0);
}
// Reading byte[] clears body. Need to recreate.

View File

@ -134,6 +134,6 @@ class ClientTest {
server.takeRequest();
Mockito.verify(mockLogger, Mockito.times(1)).logRequest(Mockito.anyString(), Mockito.anyString(), Mockito.anyList(),
Mockito.any());
Mockito.verify(mockLogger, Mockito.times(1)).logResponse(Mockito.anyString(), Mockito.anyList(), Mockito.any());
Mockito.verify(mockLogger, Mockito.times(1)).logResponse(Mockito.anyString(), Mockito.anyList(), Mockito.any(), 0);
}
}

View File

@ -87,7 +87,7 @@ public class HTMLClientLogger extends BaseLogger implements ToolingClientLogger
}
@Override
public void logResponse(String outcome, List<String> headers, byte[] body) {
public void logResponse(String outcome, List<String> headers, byte[] body, long start) {
if (DEBUG) {
System.out.println(" txlog resp: " +outcome+" "+present(body));
}

View File

@ -76,10 +76,10 @@ public class TextClientLogger extends BaseLogger implements ToolingClientLogger
}
@Override
public void logResponse(String outcome, List<String> headers, byte[] body) {
public void logResponse(String outcome, List<String> headers, byte[] body, long length) {
if (file == null)
return;
file.println("\r\n\r\nResponse: \r\n");
file.println("\r\n\r\nResponse ("+Utilities.describeDuration(length)+"): \r\n");
file.println(outcome);
for (String s : headers)
file.println(s);

View File

@ -59,7 +59,8 @@ public class FhirLoggingInterceptor implements Interceptor {
headerMap.keySet().forEach(key -> headerMap.get(key).forEach(value -> headerList.add(key + ":" + value)));
if (logger != null) {
logger.logResponse(Integer.toString(response.code()), headerList, bodyBytes);
long responseTimeInMillis = response.receivedResponseAtMillis() - response.sentRequestAtMillis();
logger.logResponse(Integer.toString(response.code()), headerList, bodyBytes, responseTimeInMillis);
}
// Reading byte[] clears body. Need to recreate.

View File

@ -172,6 +172,6 @@ class ClientTest {
Mockito.verify(mockLogger, Mockito.times(1))
.logRequest(Mockito.anyString(), Mockito.anyString(), Mockito.anyList(), Mockito.any());
Mockito.verify(mockLogger, Mockito.times(1))
.logResponse(Mockito.anyString(), Mockito.anyList(), Mockito.any());
.logResponse(Mockito.anyString(), Mockito.anyList(), Mockito.any(), Mockito.anyLong());
}
}

View File

@ -36,7 +36,7 @@ import java.util.List;
public interface ToolingClientLogger {
void logRequest(String method, String url, List<String> headers, byte[] body);
void logResponse(String outcome, List<String> headers, byte[] body);
void logResponse(String outcome, List<String> headers, byte[] body, long length);
String getLastId();
void clearLastId();

View File

@ -33,7 +33,7 @@ public class CacheVerificationLogger implements ToolingClientLogger {
}
@Override
public void logResponse(String outcome, List<String> headers, byte[] body) {
public void logResponse(String outcome, List<String> headers, byte[] body, long start) {
}