Skip to content

Commit

Permalink
Gt 1361 correlation id preserving (#373)
Browse files Browse the repository at this point in the history
* CQL issue with connection pool exhaustion

* GT-1361 preserving correlationId into the calls done to other HTTP compnoents
  • Loading branch information
marianbuenosayres authored Aug 22, 2023
1 parent 8ddc061 commit 2cefeca
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.kie.api.runtime.process.WorkItemManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
Expand Down Expand Up @@ -131,7 +132,9 @@ else if (token != null){
else {
logger.warn("No authentication for the rest api request " + url);
}

if (!headers.containsKey("X-Correlation-ID")) {
headers.add("X-Correlation-ID", MDC.get("correlationId"));
}

HttpEntity<?> entity = new HttpEntity<>(body, headers);
logger.debug("Prepared http entity");
Expand Down
2 changes: 1 addition & 1 deletion fhir-helpers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.elimu.a2d2</groupId>
<artifactId>fhir-helpers</artifactId>
<version>0.0.14</version>
<version>0.0.15</version>
<packaging>jar</packaging>
<name>fhir-helpers</name>
<url>http://maven.apache.org</url>
Expand Down
2 changes: 1 addition & 1 deletion fhir-query-helper-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</parent>

<artifactId>fhir-query-helper-base</artifactId>
<version>0.0.14</version>
<version>0.0.15</version>
<description>CDS Helper base</description>

<properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.elimu.a2d2.cds.fhir.helper;

import org.slf4j.MDC;

import ca.uhn.fhir.rest.client.interceptor.SimpleRequestHeaderInterceptor;

public class CorrelationIdInterceptor extends SimpleRequestHeaderInterceptor {

private static final String CORRELATION_ID_HEADER_NAME = "X-Correlation-ID";
private static final String CORRELATION_ID_LOG_VAR_NAME = "correlationId";

public CorrelationIdInterceptor() {
super(CORRELATION_ID_HEADER_NAME, MDC.get(CORRELATION_ID_LOG_VAR_NAME));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,10 @@ protected <S> FhirResponse<S> runWithInterceptors(QueryingCallback<S> callback,
client.registerInterceptor(i);
}
SingleAuthInterceptor singleAuth = new SingleAuthInterceptor();
CorrelationIdInterceptor correlationId = new CorrelationIdInterceptor();
client.registerInterceptor(singleAuth);
client.registerInterceptor(tracker);
client.registerInterceptor(correlationId);
try {
result = callback.execute(client);
} catch (RuntimeException t) {
Expand All @@ -312,8 +314,8 @@ protected <S> FhirResponse<S> runWithInterceptors(QueryingCallback<S> callback,
log.debug("Unregistering interceptor " + i);
client.unregisterInterceptor(i);
}
client.unregisterInterceptor(correlationId);
client.unregisterInterceptor(singleAuth);

client.unregisterInterceptor(tracker);
};
} finally {
Expand Down
2 changes: 1 addition & 1 deletion fhir-query-helper-dstu2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</parent>

<artifactId>fhir-query-helper-dstu2</artifactId>
<version>0.0.14</version>
<version>0.0.15</version>
<packaging>jar</packaging>
<description>CDS Helper</description>

Expand Down
2 changes: 1 addition & 1 deletion fhir-query-helper-dstu3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</parent>

<artifactId>fhir-query-helper-dstu3</artifactId>
<version>0.0.14</version>
<version>0.0.15</version>
<packaging>jar</packaging>
<description>CDS Helper DSTU3</description>

Expand Down
2 changes: 1 addition & 1 deletion fhir-query-helper-r4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</parent>

<artifactId>fhir-query-helper-r4</artifactId>
<version>0.0.14</version>
<version>0.0.15</version>
<packaging>jar</packaging>
<description>CDS Helper R4</description>

Expand Down
2 changes: 1 addition & 1 deletion oauth-helpers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</parent>

<artifactId>oauth-helpers</artifactId>
<version>0.0.14</version>
<version>0.0.15</version>
<description>OAuth Helper</description>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<protobuf-java.version>3.21.8</protobuf-java.version>
<mockito.version>2.23.0</mockito.version>
<jedis.version>4.0.1</jedis.version>
<cds.helper.version>0.0.14</cds.helper.version>
<cds.helper.version>0.0.15</cds.helper.version>
<freemarker.version>2.3.30</freemarker.version>
<jacoco.version>0.8.7</jacoco.version>
<jaxb.api.version>2.3.1</jaxb.api.version>
Expand Down

0 comments on commit 2cefeca

Please sign in to comment.