Skip to content

Commit

Permalink
passing MDC context from Cinder
Browse files Browse the repository at this point in the history
  • Loading branch information
nayanika-u committed Sep 5, 2023
1 parent 1c4f393 commit 9999b2f
Show file tree
Hide file tree
Showing 13 changed files with 210 additions and 34 deletions.
18 changes: 18 additions & 0 deletions hollow-diff-ui/dependencies.lock
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@
"com.netflix.hollow:hollow-ui-tools"
],
"locked": "2.3"
},
"org.slf4j:jul-to-slf4j": {
"firstLevelTransitive": [
"com.netflix.hollow:hollow"
],
"locked": "2.0.9"
}
},
"testCompileClasspath": {
Expand Down Expand Up @@ -145,6 +151,12 @@
"com.netflix.hollow:hollow-ui-tools"
],
"locked": "2.3"
},
"org.slf4j:jul-to-slf4j": {
"firstLevelTransitive": [
"com.netflix.hollow:hollow"
],
"locked": "2.0.9"
}
},
"toolsCompileClasspath": {
Expand Down Expand Up @@ -222,6 +234,12 @@
"com.netflix.hollow:hollow-ui-tools"
],
"locked": "2.3"
},
"org.slf4j:jul-to-slf4j": {
"firstLevelTransitive": [
"com.netflix.hollow:hollow"
],
"locked": "2.0.9"
}
}
}
18 changes: 18 additions & 0 deletions hollow-explorer-ui/dependencies.lock
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
"com.netflix.hollow:hollow-ui-tools"
],
"locked": "2.3"
},
"org.slf4j:jul-to-slf4j": {
"firstLevelTransitive": [
"com.netflix.hollow:hollow"
],
"locked": "2.0.9"
}
},
"testCompileClasspath": {
Expand Down Expand Up @@ -125,6 +131,12 @@
"com.netflix.hollow:hollow-ui-tools"
],
"locked": "2.3"
},
"org.slf4j:jul-to-slf4j": {
"firstLevelTransitive": [
"com.netflix.hollow:hollow"
],
"locked": "2.0.9"
}
},
"toolsCompileClasspath": {
Expand Down Expand Up @@ -192,6 +204,12 @@
"com.netflix.hollow:hollow-ui-tools"
],
"locked": "2.3"
},
"org.slf4j:jul-to-slf4j": {
"firstLevelTransitive": [
"com.netflix.hollow:hollow"
],
"locked": "2.0.9"
}
}
}
12 changes: 12 additions & 0 deletions hollow-jsonadapter/dependencies.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
},
"commons-lang:commons-lang": {
"locked": "2.6"
},
"org.slf4j:jul-to-slf4j": {
"firstLevelTransitive": [
"com.netflix.hollow:hollow"
],
"locked": "2.0.9"
}
},
"testCompileClasspath": {
Expand Down Expand Up @@ -71,6 +77,12 @@
},
"junit:junit": {
"locked": "4.11"
},
"org.slf4j:jul-to-slf4j": {
"firstLevelTransitive": [
"com.netflix.hollow:hollow"
],
"locked": "2.0.9"
}
}
}
18 changes: 18 additions & 0 deletions hollow-perf/dependencies.lock
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
},
"org.openjdk.jmh:jmh-generator-bytecode": {
"locked": "1.25"
},
"org.slf4j:jul-to-slf4j": {
"firstLevelTransitive": [
"com.netflix.hollow:hollow"
],
"locked": "2.0.9"
}
},
"runtimeClasspath": {
Expand All @@ -49,6 +55,12 @@
},
"org.openjdk.jmh:jmh-core": {
"locked": "1.21"
},
"org.slf4j:jul-to-slf4j": {
"firstLevelTransitive": [
"com.netflix.hollow:hollow"
],
"locked": "2.0.9"
}
},
"testCompileClasspath": {
Expand All @@ -65,6 +77,12 @@
},
"org.openjdk.jmh:jmh-core": {
"locked": "1.21"
},
"org.slf4j:jul-to-slf4j": {
"firstLevelTransitive": [
"com.netflix.hollow:hollow"
],
"locked": "2.0.9"
}
}
}
12 changes: 12 additions & 0 deletions hollow-test/dependencies.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
"runtimeClasspath": {
"com.netflix.hollow:hollow": {
"project": true
},
"org.slf4j:jul-to-slf4j": {
"firstLevelTransitive": [
"com.netflix.hollow:hollow"
],
"locked": "2.0.9"
}
},
"testCompileClasspath": {
Expand All @@ -23,6 +29,12 @@
},
"junit:junit": {
"locked": "4.11"
},
"org.slf4j:jul-to-slf4j": {
"firstLevelTransitive": [
"com.netflix.hollow:hollow"
],
"locked": "2.0.9"
}
}
}
18 changes: 18 additions & 0 deletions hollow-ui-tools/dependencies.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
},
"org.apache.velocity:velocity-engine-core": {
"locked": "2.3"
},
"org.slf4j:jul-to-slf4j": {
"firstLevelTransitive": [
"com.netflix.hollow:hollow"
],
"locked": "2.0.9"
}
},
"testCompileClasspath": {
Expand Down Expand Up @@ -83,6 +89,12 @@
},
"org.apache.velocity:velocity-engine-core": {
"locked": "2.3"
},
"org.slf4j:jul-to-slf4j": {
"firstLevelTransitive": [
"com.netflix.hollow:hollow"
],
"locked": "2.0.9"
}
},
"toolsCompileClasspath": {
Expand Down Expand Up @@ -129,6 +141,12 @@
},
"org.apache.velocity:velocity-engine-core": {
"locked": "2.3"
},
"org.slf4j:jul-to-slf4j": {
"firstLevelTransitive": [
"com.netflix.hollow:hollow"
],
"locked": "2.0.9"
}
}
}
12 changes: 12 additions & 0 deletions hollow-zenoadapter/dependencies.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
},
"com.netflix.zeno:netflix-zeno": {
"locked": "2.22.3"
},
"org.slf4j:jul-to-slf4j": {
"firstLevelTransitive": [
"com.netflix.hollow:hollow"
],
"locked": "2.0.9"
}
},
"testCompileClasspath": {
Expand All @@ -35,6 +41,12 @@
},
"junit:junit": {
"locked": "4.11"
},
"org.slf4j:jul-to-slf4j": {
"firstLevelTransitive": [
"com.netflix.hollow:hollow"
],
"locked": "2.0.9"
}
}
}
1 change: 1 addition & 0 deletions hollow/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dependencies {
testImplementation 'org.mockito:mockito-core:2.15.0'
testImplementation 'com.github.spotbugs:spotbugs:4.2.1'
testImplementation 'org.assertj:assertj-core:3.15.0'
implementation group: 'org.slf4j', name: 'jul-to-slf4j', version: '2.0.9'
}

tasks.withType(JavaCompile).configureEach {
Expand Down
19 changes: 19 additions & 0 deletions hollow/dependencies.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
{
"compileClasspath": {
"org.slf4j:jul-to-slf4j": {
"locked": "2.0.9"
}
},
"runtimeClasspath": {
"org.slf4j:jul-to-slf4j": {
"locked": "2.0.9"
}
},
"testCompileClasspath": {
"com.github.spotbugs:spotbugs": {
"locked": "4.2.1"
Expand All @@ -14,6 +24,9 @@
},
"org.mockito:mockito-core": {
"locked": "2.15.0"
},
"org.slf4j:jul-to-slf4j": {
"locked": "2.0.9"
}
},
"testRuntimeClasspath": {
Expand All @@ -37,6 +50,12 @@
},
"org.mockito:mockito-core": {
"locked": "2.15.0"
},
"org.slf4j:jul-to-slf4j": {
"firstLevelTransitive": [
"com.netflix.hollow:hollow"
],
"locked": "2.0.9"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

import com.netflix.hollow.api.consumer.HollowConsumer;
import com.netflix.hollow.core.HollowConstants;
import org.slf4j.MDC;

import java.util.Map;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -129,16 +132,23 @@ public void triggerAsyncRefreshWithRandomDelay(int maxDelayMillis) {
public void triggerAsyncRefreshWithDelay(int delayMillis) {
final HollowClient client = this.client;
final long targetBeginTime = System.currentTimeMillis() + delayMillis;

// Capture MDC context on the original thread
final Map<String, String> mdcContext = MDC.getCopyOfContextMap();
refreshExecutor.execute(new Runnable() {
public void run() {
// Set MDC context on the new thread
if (mdcContext != null) {
MDC.setContextMap(mdcContext);
}
try {
long delay = targetBeginTime - System.currentTimeMillis();
if(delay > 0)
Thread.sleep(delay);
client.triggerRefresh();
} catch(Throwable th) {
log.log(Level.SEVERE, "Async refresh failed", th);
} finally {
MDC.clear();
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import com.netflix.hollow.core.util.DefaultHashCodeFinder;
import com.netflix.hollow.core.util.HollowObjectHashCodeFinder;
import com.netflix.hollow.tools.history.HollowHistory;
import org.slf4j.MDC;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -258,25 +260,36 @@ public void triggerAsyncRefresh() {
*/
public void triggerAsyncRefreshWithDelay(int delayMillis) {
final long targetBeginTime = System.currentTimeMillis() + delayMillis;
// Capture MDC context on the original thread
final Map<String, String> mdcContext = MDC.getCopyOfContextMap();

refreshExecutor.execute(() -> {
try {
long delay = targetBeginTime - System.currentTimeMillis();
if (delay > 0)
Thread.sleep(delay);
} catch (InterruptedException e) {
// Interrupting, such as shutting down the executor pool,
// cancels the trigger
LOG.log(Level.INFO, "Async refresh interrupted before trigger, refresh cancelled", e);
return;
// Set MDC context on the new thread
if (mdcContext != null) {
MDC.setContextMap(mdcContext);
}

try {
triggerRefresh();
} catch (Error | RuntimeException e) {
// Ensure exceptions are propagated to the executor
LOG.log(Level.SEVERE, "Async refresh failed", e);
throw e;
try {
long delay = targetBeginTime - System.currentTimeMillis();
if (delay > 0)
Thread.sleep(delay);
} catch (InterruptedException e) {
// Interrupting, such as shutting down the executor pool,
// cancels the trigger
LOG.log(Level.INFO, "Async refresh interrupted before trigger, refresh cancelled", e);
return;
}

try {
triggerRefresh();
} catch (Error | RuntimeException e) {
// Ensure exceptions are propagated to the executor
LOG.log(Level.SEVERE, "Async refresh failed", e);
throw e;
}
} finally {
// clear MDC context when entire task is done
MDC.clear();
}
});
}
Expand Down
Loading

0 comments on commit 9999b2f

Please sign in to comment.