Fix tests
This commit is contained in:
parent
988a3d0fdf
commit
aad3746c2b
|
@ -38,9 +38,10 @@ class VersionScanPlugin implements Plugin<Project> {
|
||||||
description = "Queries for all versions of configured modules and finds key classes"
|
description = "Queries for all versions of configured modules and finds key classes"
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!project.gradle.startParameter.taskNames.each { it.endsWith('scanVersions') }.any()) {
|
if (!project.gradle.startParameter.taskNames.contains('scanVersions')) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
println "Adding scan tasks for $project"
|
||||||
|
|
||||||
Set<String> allInclude = Sets.newConcurrentHashSet()
|
Set<String> allInclude = Sets.newConcurrentHashSet()
|
||||||
Set<String> allExclude = Sets.newConcurrentHashSet()
|
Set<String> allExclude = Sets.newConcurrentHashSet()
|
||||||
|
|
|
@ -17,6 +17,8 @@ whitelistedInstructionClasses += whitelistedBranchClasses += [
|
||||||
'com.datadoghq.trace.agent.InstrumentationChecker',
|
'com.datadoghq.trace.agent.InstrumentationChecker',
|
||||||
'com.datadoghq.trace.agent.DDJavaAgentInfo',
|
'com.datadoghq.trace.agent.DDJavaAgentInfo',
|
||||||
'io.opentracing.contrib.mongo.TracingCommandListenerFactory',
|
'io.opentracing.contrib.mongo.TracingCommandListenerFactory',
|
||||||
|
'com.datadoghq.trace.agent.InstrumentationChecker.1',
|
||||||
|
'com.datadoghq.trace.agent.InstrumentationChecker.ArtifactSupport',
|
||||||
]
|
]
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class InstrumentationChecker {
|
||||||
this.classLoader = classLoader;
|
this.classLoader = classLoader;
|
||||||
rules =
|
rules =
|
||||||
FactoryUtils.loadConfigFromResource(
|
FactoryUtils.loadConfigFromResource(
|
||||||
CONFIG_FILE, new TypeReference<Map<String, List<Map<String, String>>>>() {});
|
CONFIG_FILE, new TypeReference<Map<String, List<ArtifactSupport>>>() {});
|
||||||
frameworks = scanLoadedLibraries();
|
frameworks = scanLoadedLibraries();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,9 @@ opentracing-apache-httpclient:
|
||||||
- artifact: httpclient
|
- artifact: httpclient
|
||||||
supported_version: 4\.[3|4|5]\..*
|
supported_version: 4\.[3|4|5]\..*
|
||||||
identifying_present_classes:
|
identifying_present_classes:
|
||||||
- org.apache.http.conn.SchemePortResolver
|
- org.apache.http.conn.SchemePortResolver
|
||||||
- org.apache.http.config.Lookup
|
- org.apache.http.config.Lookup
|
||||||
- org.apache.http.conn.ssl.SSLContexts
|
- org.apache.http.conn.ssl.SSLContexts
|
||||||
|
|
||||||
- artifact: commons-httpclient
|
- artifact: commons-httpclient
|
||||||
supported_version: none
|
supported_version: none
|
||||||
|
@ -22,52 +22,52 @@ opentracing-aws-sdk:
|
||||||
- artifact: aws-java-sdk
|
- artifact: aws-java-sdk
|
||||||
supported_version: 1\.11\..*
|
supported_version: 1\.11\..*
|
||||||
identifying_present_classes:
|
identifying_present_classes:
|
||||||
- com.amazonaws.http.client.HttpClientFactory
|
- com.amazonaws.http.client.HttpClientFactory
|
||||||
- com.amazonaws.http.apache.utils.ApacheUtils
|
- com.amazonaws.http.apache.utils.ApacheUtils
|
||||||
- com.amazonaws.http.request.HttpRequestFactory
|
- com.amazonaws.http.request.HttpRequestFactory
|
||||||
|
|
||||||
opentracing-cassandra-driver:
|
opentracing-cassandra-driver:
|
||||||
- artifact: cassandra-driver-core
|
- artifact: cassandra-driver-core
|
||||||
supported_version: 3\.2.*
|
supported_version: 3\.2.*
|
||||||
identifying_present_classes:
|
identifying_present_classes:
|
||||||
- com.datastax.driver.core.utils.MoreObjects
|
- com.datastax.driver.core.utils.MoreObjects
|
||||||
- com.datastax.driver.core.RemoteEndpointAwareNettySSLOptions
|
- com.datastax.driver.core.RemoteEndpointAwareNettySSLOptions
|
||||||
- com.datastax.driver.core.GuavaCompatibility
|
- com.datastax.driver.core.GuavaCompatibility
|
||||||
|
|
||||||
opentracing-web-servlet-filter:
|
opentracing-web-servlet-filter:
|
||||||
- artifact: jetty-server
|
- artifact: jetty-server
|
||||||
supported_version: (8\.|9\.).*
|
supported_version: (8\.|9\.).*
|
||||||
identifying_present_classes:
|
# identifying_present_classes:
|
||||||
|
|
||||||
- artifact: tomcat_catalina
|
- artifact: tomcat_catalina
|
||||||
supported_version: (8\.|9\.).*
|
supported_version: (8\.|9\.).*
|
||||||
identifying_present_classes:
|
identifying_present_classes:
|
||||||
- org.apache.catalina.WebResource
|
- org.apache.catalina.WebResource
|
||||||
- org.apache.catalina.webresources.TrackedInputStream
|
- org.apache.catalina.webresources.TrackedInputStream
|
||||||
- org.apache.catalina.webresources.AbstractArchiveResource
|
- org.apache.catalina.webresources.AbstractArchiveResource
|
||||||
|
|
||||||
- artifact: tomcat-embed-core
|
- artifact: tomcat-embed-core
|
||||||
supported_version: (8\.|9\.).*
|
supported_version: (8\.|9\.).*
|
||||||
identifying_present_classes:
|
identifying_present_classes:
|
||||||
- org.apache.catalina.WebResource
|
- org.apache.catalina.WebResource
|
||||||
- org.apache.catalina.webresources.TrackedInputStream
|
- org.apache.catalina.webresources.TrackedInputStream
|
||||||
- org.apache.catalina.webresources.AbstractArchiveResource
|
- org.apache.catalina.webresources.AbstractArchiveResource
|
||||||
|
|
||||||
opentracing-okhttp3:
|
opentracing-okhttp3:
|
||||||
- artifact: okhttp
|
- artifact: okhttp
|
||||||
supported_version: 3\..*
|
supported_version: 3\..*
|
||||||
identifying_present_classes:
|
identifying_present_classes:
|
||||||
- okhttp3.Cookie
|
- okhttp3.Cookie
|
||||||
- okhttp3.ConnectionPool
|
- okhttp3.ConnectionPool
|
||||||
- okhttp3.Headers
|
- okhttp3.Headers
|
||||||
|
|
||||||
# For rules opentracing-jms-2_{consumer,producer}
|
# For rules opentracing-jms-2_{consumer,producer}
|
||||||
opentracing-jms-2:
|
opentracing-jms-2:
|
||||||
- artifact: javax.jms-api
|
- artifact: javax.jms-api
|
||||||
supported_version: 2\..*
|
supported_version: 2\..*
|
||||||
identifying_present_classes
|
identifying_present_classes:
|
||||||
- javax.jms.JMSContext
|
- javax.jms.JMSContext
|
||||||
- javax.jms.CompletionListener
|
- javax.jms.CompletionListener
|
||||||
|
|
||||||
opentracing-mongo-driver:
|
opentracing-mongo-driver:
|
||||||
- artifact: mongo-java-driver
|
- artifact: mongo-java-driver
|
||||||
|
|
|
@ -7,7 +7,7 @@ import spock.lang.Specification
|
||||||
class InstrumentationCheckerTest extends Specification {
|
class InstrumentationCheckerTest extends Specification {
|
||||||
Map<String, List<Map<String, String>>> rules =
|
Map<String, List<Map<String, String>>> rules =
|
||||||
FactoryUtils.loadConfigFromResource("supported-version-test", new TypeReference<Map<String, List<InstrumentationChecker.ArtifactSupport>>>() {
|
FactoryUtils.loadConfigFromResource("supported-version-test", new TypeReference<Map<String, List<InstrumentationChecker.ArtifactSupport>>>() {
|
||||||
});
|
})
|
||||||
Map<String, String> frameworks = [
|
Map<String, String> frameworks = [
|
||||||
"artifact-1": "1.2.3.1232",
|
"artifact-1": "1.2.3.1232",
|
||||||
"artifact-2": "4.y.z",
|
"artifact-2": "4.y.z",
|
||||||
|
@ -18,7 +18,7 @@ class InstrumentationCheckerTest extends Specification {
|
||||||
|
|
||||||
def "test rules"() {
|
def "test rules"() {
|
||||||
setup:
|
setup:
|
||||||
def rules = InstrumentationChecker.getUnsupportedRules(java.lang.ClassLoader.getSystemClassLoader());
|
def rules = InstrumentationChecker.getUnsupportedRules(java.lang.ClassLoader.getSystemClassLoader())
|
||||||
|
|
||||||
expect:
|
expect:
|
||||||
rules.size() == 3
|
rules.size() == 3
|
||||||
|
|
|
@ -15,6 +15,7 @@ whitelistedInstructionClasses += whitelistedBranchClasses += [
|
||||||
'com.datadoghq.trace.DDTags',
|
'com.datadoghq.trace.DDTags',
|
||||||
'com.datadoghq.trace.DDTraceInfo',
|
'com.datadoghq.trace.DDTraceInfo',
|
||||||
'com.datadoghq.trace.util.Clock',
|
'com.datadoghq.trace.util.Clock',
|
||||||
|
'com.datadoghq.trace.resolver.FactoryUtils',
|
||||||
]
|
]
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
|
@ -15,8 +15,18 @@ public class FactoryUtils {
|
||||||
|
|
||||||
public static <A> A loadConfigFromFilePropertyOrResource(
|
public static <A> A loadConfigFromFilePropertyOrResource(
|
||||||
final String systemProperty, final String resourceName, final Class<A> targetClass) {
|
final String systemProperty, final String resourceName, final Class<A> targetClass) {
|
||||||
return loadConfigFromFilePropertyOrResource(
|
final String filePath = System.getProperty(systemProperty);
|
||||||
systemProperty, resourceName, new TypeReference<A>() {});
|
if (filePath != null) {
|
||||||
|
try {
|
||||||
|
log.info("Loading config from file " + filePath);
|
||||||
|
return objectMapper.readValue(new File(filePath), targetClass);
|
||||||
|
} catch (final Exception e) {
|
||||||
|
log.error(
|
||||||
|
"Cannot read provided configuration file " + filePath + ". Using the default one.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return loadConfigFromResource(resourceName, targetClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <A> A loadConfigFromFilePropertyOrResource(
|
public static <A> A loadConfigFromFilePropertyOrResource(
|
||||||
|
@ -37,7 +47,31 @@ public class FactoryUtils {
|
||||||
|
|
||||||
public static <A> A loadConfigFromResource(
|
public static <A> A loadConfigFromResource(
|
||||||
final String resourceName, final Class<A> targetClass) {
|
final String resourceName, final Class<A> targetClass) {
|
||||||
return loadConfigFromResource(resourceName, new TypeReference<A>() {});
|
A config = null;
|
||||||
|
|
||||||
|
// Try loading both suffixes
|
||||||
|
if (!resourceName.endsWith(".yaml") && !resourceName.endsWith(".yml")) {
|
||||||
|
config = loadConfigFromResource(resourceName + ".yaml", targetClass);
|
||||||
|
if (config == null) {
|
||||||
|
config = loadConfigFromResource(resourceName + ".yml", targetClass);
|
||||||
|
}
|
||||||
|
if (config != null) {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||||
|
final URL resource = classLoader.getResource(resourceName);
|
||||||
|
if (resource != null) {
|
||||||
|
log.info("Loading config from resource " + resource);
|
||||||
|
config = objectMapper.readValue(resource.openStream(), targetClass);
|
||||||
|
}
|
||||||
|
} catch (final IOException e) {
|
||||||
|
log.warn("Could not load configuration file {}.", resourceName);
|
||||||
|
log.error("Error when loading config file", e);
|
||||||
|
}
|
||||||
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <A> A loadConfigFromResource(final String resourceName, final TypeReference type) {
|
public static <A> A loadConfigFromResource(final String resourceName, final TypeReference type) {
|
||||||
|
|
Loading…
Reference in New Issue