Skip to content

Commit e7dbc55

Browse files
Use slf4j-simple instead of logback that has a high chance of getting stuck in a deadlock on CI. (#10390)
* Use slf4j-simple as default; logback has a high chance of getting stuck in a deadlock on CI. * Relaxed checks for Logback. * Minor.
1 parent 5c6f495 commit e7dbc55

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

dd-java-agent/agent-iast/iast-test-fixtures/src/main/groovy/com/datadog/iast/test/IastRequestContextPreparationTrait.groovy

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@ import com.datadog.iast.IastSystem
55
import com.datadog.iast.model.Range
66
import com.datadog.iast.taint.TaintedObject
77
import com.datadog.iast.taint.TaintedObjects
8-
import datadog.trace.api.gateway.*
8+
import datadog.trace.api.gateway.CallbackProvider
9+
import datadog.trace.api.gateway.EventType
10+
import datadog.trace.api.gateway.Events
11+
import datadog.trace.api.gateway.Flow
12+
import datadog.trace.api.gateway.IGSpanInfo
13+
import datadog.trace.api.gateway.RequestContext
14+
import datadog.trace.api.gateway.RequestContextSlot
915
import datadog.trace.api.iast.InstrumentationBridge
1016
import datadog.trace.bootstrap.instrumentation.api.AgentTracer
11-
import org.slf4j.Logger
12-
import org.slf4j.LoggerFactory
13-
1417
import java.util.function.BiFunction
1518
import java.util.function.Supplier
19+
import org.slf4j.Logger
20+
import org.slf4j.LoggerFactory
1621

1722
trait IastRequestContextPreparationTrait {
1823

@@ -73,7 +78,9 @@ trait IastRequestContextPreparationTrait {
7378

7479
private static Logger withLogger(final String name) {
7580
final logger = LoggerFactory.getLogger(name)
76-
if (logger instanceof ch.qos.logback.classic.Logger) {
81+
82+
// Check logger class by name to avoid NoClassDefFoundError at runtime for tests without Logback.
83+
if (logger.class.name == "ch.qos.logback.classic.Logger") {
7784
((ch.qos.logback.classic.Logger) logger).level = ch.qos.logback.classic.Level.DEBUG
7885
}
7986
return logger

dd-java-agent/instrumentation/vertx/vertx-web/vertx-web-3.4/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
apply from: "$rootDir/gradle/java.gradle"
2+
// Use slf4j-simple as default; logback has a high chance of getting stuck in a deadlock on CI.
3+
apply from: "$rootDir/gradle/slf4j-simple.gradle"
24

35
testJvmConstraints {
46
// TODO Java 17: This version of vertx-web doesn't support Java 17
@@ -49,3 +51,4 @@ dependencies {
4951
latestDepTestImplementation group: 'io.vertx', name: 'vertx-web', version: '3.+'
5052
latestDepTestImplementation group: 'io.vertx', name: 'vertx-web-client', version: '3.+'
5153
}
54+

internal-api/src/main/java/datadog/trace/api/iast/Taintable.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,23 @@ class DebugLogger {
3030
private static final Logger LOGGER;
3131

3232
static {
33-
try {
34-
LOGGER = LoggerFactory.getLogger("Taintable tainted objects");
35-
Class<?> levelCls = Class.forName("ch.qos.logback.classic.Level");
36-
Method setLevel = LOGGER.getClass().getMethod("setLevel", levelCls);
37-
Object debugLevel = levelCls.getField("DEBUG").get(null);
38-
setLevel.invoke(LOGGER, debugLevel);
39-
} catch (IllegalAccessException
40-
| NoSuchFieldException
41-
| ClassNotFoundException
42-
| NoSuchMethodException
43-
| InvocationTargetException e) {
44-
throw new RuntimeException(e);
33+
LOGGER = LoggerFactory.getLogger("Taintable tainted objects");
34+
35+
// Check logger class by name to avoid NoClassDefFoundError at runtime
36+
// for tests without Logback.
37+
if (LOGGER.getClass().getName().equals("ch.qos.logback.classic.Logger")) {
38+
try {
39+
Class<?> levelCls = Class.forName("ch.qos.logback.classic.Level");
40+
Method setLevel = LOGGER.getClass().getMethod("setLevel", levelCls);
41+
Object debugLevel = levelCls.getField("DEBUG").get(null);
42+
setLevel.invoke(LOGGER, debugLevel);
43+
} catch (IllegalAccessException
44+
| NoSuchFieldException
45+
| ClassNotFoundException
46+
| NoSuchMethodException
47+
| InvocationTargetException e) {
48+
throw new RuntimeException(e);
49+
}
4550
}
4651
}
4752

0 commit comments

Comments
 (0)