Skip to content

Commit a9b74dd

Browse files
authored
Merge branch 'master' into ygree/bump-jmxfetch-0.49.8
2 parents a0027d1 + 7787af7 commit a9b74dd

File tree

49 files changed

+1071
-58
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1071
-58
lines changed

.circleci/upload_ciapp.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
SERVICE_NAME="dd-trace-java"
3-
PIPELINE_STAGE=$1
3+
CACHE_TYPE=$1
44
TEST_JVM=$2
55

66
# JAVA_???_HOME are set in the base image for each used JDK https://github.com/DataDog/dd-trace-java-docker-build/blob/master/Dockerfile#L86
@@ -23,7 +23,7 @@ junit_upload() {
2323
DD_API_KEY=$1 \
2424
datadog-ci junit upload --service $SERVICE_NAME \
2525
--logs \
26-
--tags "test.traits:{\"marker\":[\"$PIPELINE_STAGE\"]}" \
26+
--tags "test.traits:{\"category\":[\"$CACHE_TYPE\"]}" \
2727
--tags "runtime.name:$(java_prop java.runtime.name)" \
2828
--tags "runtime.vendor:$(java_prop java.vendor)" \
2929
--tags "runtime.version:$(java_prop java.version)" \

.gitlab-ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ muzzle-dep-report:
406406
- .circleci/collect_reports.sh
407407
- if [ "$PROFILE_TESTS" == "true" ]; then .circleci/collect_profiles.sh; fi
408408
- .circleci/collect_results.sh
409-
- .circleci/upload_ciapp.sh tests $testJvm
409+
- .circleci/upload_ciapp.sh $CACHE_TYPE $testJvm
410410
- gitlab_section_end "collect-reports"
411411
- URL_ENCODED_JOB_NAME=$(jq -rn --arg x "$CI_JOB_NAME" '$x|@uri')
412412
- echo -e "${TEXT_BOLD}${TEXT_YELLOW}See test results in Datadog:${TEXT_CLEAR} https://app.datadoghq.com/ci/test/runs?query=test_level%3Atest%20%40test.service%3Add-trace-java%20%40ci.pipeline.id%3A${CI_PIPELINE_ID}%20%40ci.job.name%3A%22${URL_ENCODED_JOB_NAME}%22"
@@ -557,7 +557,9 @@ test_smoke:
557557

558558
test_ssi_smoke:
559559
extends: .test_job
560-
rules: *master_only
560+
rules:
561+
- if: $CI_PIPELINE_SOURCE == "schedule"
562+
when: on_success
561563
variables:
562564
GRADLE_TARGET: "stageMainDist :smokeTest"
563565
CACHE_TYPE: "smoke"

BUILDING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Requirements to build the full project:
6060

6161
### Install the required JDKs
6262

63-
Download and install Eclipse Temurin JDK versions 8, 11, 17 and 21, and GraalVM 17.
63+
Download and install JDK versions 8, 11, 17 and 21, and GraalVM 17 for your OS.
6464

6565
#### macOS
6666

@@ -179,17 +179,17 @@ scoop install git
179179
180180
#### macOS
181181

182-
Download and install Docker Desktop from the offical website:<br/>
182+
Download and install Docker Desktop from the official website:<br/>
183183
https://docs.docker.com/desktop/setup/install/mac-install/
184184

185185
#### Linux
186186

187-
Download and install Docker Desktop from the offical website:<br/>
187+
Download and install Docker Desktop from the official website:<br/>
188188
https://docs.docker.com/desktop/setup/install/linux/
189189

190190
#### Windows
191191

192-
Download and install Docker Desktop from the offical website:<br/>
192+
Download and install Docker Desktop from the official website:<br/>
193193
https://docs.docker.com/desktop/setup/install/windows-install/
194194

195195
<details>

dd-java-agent/agent-bootstrap/build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,11 @@ jmh {
6565
jmhVersion = '1.32'
6666
duplicateClassesStrategy = DuplicatesStrategy.EXCLUDE
6767
}
68+
69+
project.afterEvaluate {
70+
tasks.withType(Test).configureEach {
71+
if (javaLauncher.get().metadata.languageVersion.asInt() >= 16) {
72+
jvmArgs += ['--add-opens', 'java.base/java.net=ALL-UNNAMED'] // for HostNameResolverForkedTest
73+
}
74+
}
75+
}

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/decorator/BaseDecorator.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
import static datadog.trace.api.cache.RadixTreeCache.PORTS;
44
import static datadog.trace.api.cache.RadixTreeCache.UNSET_PORT;
5+
import static datadog.trace.bootstrap.instrumentation.java.net.HostNameResolver.hostName;
56

67
import datadog.context.ContextScope;
78
import datadog.trace.api.Config;
89
import datadog.trace.api.DDTags;
910
import datadog.trace.api.Functions;
10-
import datadog.trace.api.cache.DDCache;
11-
import datadog.trace.api.cache.DDCaches;
1211
import datadog.trace.api.cache.QualifiedClassNameCache;
1312
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
1413
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
@@ -40,8 +39,6 @@ public String apply(Class<?> clazz) {
4039
},
4140
Functions.PrefixJoin.of("."));
4241

43-
private static final DDCache<String, String> HOSTNAME_CACHE = DDCaches.newFixedSizeCache(64);
44-
4542
protected final boolean traceAnalyticsEnabled;
4643
protected final Double traceAnalyticsSampleRate;
4744

@@ -200,11 +197,4 @@ public CharSequence className(final Class<?> clazz) {
200197
String simpleName = clazz.getSimpleName();
201198
return simpleName.isEmpty() ? CLASS_NAMES.getClassName(clazz) : simpleName;
202199
}
203-
204-
private static String hostName(InetAddress remoteAddress, String ip) {
205-
if (null != ip) {
206-
return HOSTNAME_CACHE.computeIfAbsent(ip, _ip -> remoteAddress.getHostName());
207-
}
208-
return remoteAddress.getHostName();
209-
}
210200
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package datadog.trace.bootstrap.instrumentation.java.net;
2+
3+
import datadog.trace.api.cache.DDCache;
4+
import datadog.trace.api.cache.DDCaches;
5+
import datadog.trace.util.MethodHandles;
6+
import java.lang.invoke.MethodHandle;
7+
import java.net.InetAddress;
8+
9+
public final class HostNameResolver {
10+
private static final MethodHandle HOLDER_GET;
11+
private static final MethodHandle HOSTNAME_GET;
12+
13+
private static final DDCache<String, String> HOSTNAME_CACHE = DDCaches.newFixedSizeCache(64);
14+
15+
static {
16+
MethodHandle holderTmp = null, hostnameTmp = null;
17+
try {
18+
final ClassLoader cl = HostNameResolver.class.getClassLoader();
19+
final MethodHandles methodHandles = new MethodHandles(cl);
20+
21+
final Class<?> holderClass =
22+
Class.forName("java.net.InetAddress$InetAddressHolder", false, cl);
23+
holderTmp = methodHandles.method(InetAddress.class, "holder");
24+
if (holderTmp != null) {
25+
hostnameTmp = methodHandles.method(holderClass, "getHostName");
26+
}
27+
} catch (Throwable ignored) {
28+
holderTmp = null;
29+
} finally {
30+
if (holderTmp != null && hostnameTmp != null) {
31+
HOLDER_GET = holderTmp;
32+
HOSTNAME_GET = hostnameTmp;
33+
} else {
34+
HOLDER_GET = null;
35+
HOSTNAME_GET = null;
36+
}
37+
}
38+
}
39+
40+
private HostNameResolver() {}
41+
42+
static String getAlreadyResolvedHostName(InetAddress address) {
43+
if (HOLDER_GET == null) {
44+
return null;
45+
}
46+
try {
47+
final Object holder = HOLDER_GET.invoke(address);
48+
return (String) HOSTNAME_GET.invoke(holder);
49+
} catch (final Throwable ignored) {
50+
}
51+
return null;
52+
}
53+
54+
private static String fromCache(InetAddress remoteAddress, String ip) {
55+
if (null != ip) {
56+
return HOSTNAME_CACHE.computeIfAbsent(ip, _ip -> remoteAddress.getHostName());
57+
}
58+
return remoteAddress.getHostName();
59+
}
60+
61+
public static String hostName(InetAddress address, String ip) {
62+
final String alreadyResolved = getAlreadyResolvedHostName(address);
63+
if (alreadyResolved != null) {
64+
return alreadyResolved;
65+
}
66+
return fromCache(address, ip);
67+
}
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package datadog.trace.bootstrap.instrumentation.java.net
2+
3+
import datadog.trace.test.util.DDSpecification
4+
5+
class HostNameResolverForkedTest extends DDSpecification {
6+
def "should directly get the hostname for already resolved address #address"() {
7+
given:
8+
def host = HostNameResolver.getAlreadyResolvedHostName(address)
9+
expect:
10+
host == expected
11+
where:
12+
address | expected
13+
new Inet4Address("test", InetAddress.getLocalHost().getAddress()) | "test"
14+
new Inet6Address("test", InetAddress.getLocalHost().getAddress()) | "test"
15+
}
16+
17+
def "should return null when directly get the address for unresolved #address"() {
18+
given:
19+
def host = HostNameResolver.getAlreadyResolvedHostName(address)
20+
expect:
21+
host == null
22+
where:
23+
address | _
24+
InetAddress.getByAddress(InetAddress.getLocalHost().getAddress()) | _
25+
new Inet6Address(null, InetAddress.getLocalHost().getAddress()) | _
26+
}
27+
28+
def "should use the cache for unresolved addresses"() {
29+
given:
30+
def inet1 = new Inet4Address(null, InetAddress.getLocalHost().getAddress())
31+
def inet2 = new Inet4Address(null, 0) // this will fail if a resolution will happen
32+
when:
33+
def address = new InetSocketAddress(inet1, 666)
34+
def host = HostNameResolver.hostName(address.getAddress(), "127.0.0.1")
35+
then:
36+
host != null
37+
when:
38+
address = new InetSocketAddress(inet2, 666)
39+
def host2 = HostNameResolver.hostName(address.getAddress(), "127.0.0.1")
40+
then:
41+
host == host2
42+
}
43+
}

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilityRepoServices.java

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ public class CiVisibilityRepoServices {
6565
ciProvider = ciProviderInfo.getProvider();
6666

6767
CIInfo ciInfo = ciProviderInfo.buildCIInfo();
68-
PullRequestInfo pullRequestInfo = buildPullRequestInfo(services.environment, ciProviderInfo);
68+
PullRequestInfo pullRequestInfo =
69+
buildPullRequestInfo(services.config, services.environment, ciProviderInfo);
6970

7071
if (pullRequestInfo.isNotEmpty()) {
7172
LOGGER.info("PR detected: {}", pullRequestInfo);
@@ -110,18 +111,38 @@ public class CiVisibilityRepoServices {
110111

111112
@Nonnull
112113
private static PullRequestInfo buildPullRequestInfo(
113-
CiEnvironment environment, CIProviderInfo ciProviderInfo) {
114-
PullRequestInfo ciProviderPrInfo = ciProviderInfo.buildPullRequestInfo();
115-
if (ciProviderPrInfo.isNotEmpty()) {
116-
return ciProviderPrInfo;
114+
Config config, CiEnvironment environment, CIProviderInfo ciProviderInfo) {
115+
PullRequestInfo info = buildUserPullRequestInfo(config, environment);
116+
117+
if (info.isComplete()) {
118+
return info;
119+
}
120+
121+
// complete with CI vars if user didn't provide all information
122+
return PullRequestInfo.merge(info, ciProviderInfo.buildPullRequestInfo());
123+
}
124+
125+
@Nonnull
126+
private static PullRequestInfo buildUserPullRequestInfo(
127+
Config config, CiEnvironment environment) {
128+
PullRequestInfo userInfo =
129+
new PullRequestInfo(
130+
config.getGitPullRequestBaseBranch(),
131+
config.getGitPullRequestBaseBranchSha(),
132+
config.getGitCommitHeadSha());
133+
134+
if (userInfo.isComplete()) {
135+
return userInfo;
117136
}
118137

119-
// could not get PR info from CI provider,
120-
// check if it was set manually
121-
return new PullRequestInfo(
122-
null,
123-
environment.get(Constants.DDCI_PULL_REQUEST_TARGET_SHA),
124-
environment.get(Constants.DDCI_PULL_REQUEST_SOURCE_SHA));
138+
// logs-backend specific vars
139+
PullRequestInfo ddCiInfo =
140+
new PullRequestInfo(
141+
null,
142+
environment.get(Constants.DDCI_PULL_REQUEST_TARGET_SHA),
143+
environment.get(Constants.DDCI_PULL_REQUEST_SOURCE_SHA));
144+
145+
return PullRequestInfo.merge(userInfo, ddCiInfo);
125146
}
126147

127148
private static String getRepoRoot(CIInfo ciInfo, GitClient.Factory gitClientFactory) {

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/AppVeyorInfo.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import datadog.trace.api.git.GitInfo;
1010
import datadog.trace.api.git.PersonInfo;
1111
import datadog.trace.civisibility.ci.env.CiEnvironment;
12+
import datadog.trace.util.Strings;
1213
import javax.annotation.Nonnull;
1314

1415
class AppVeyorInfo implements CIProviderInfo {
@@ -25,6 +26,8 @@ class AppVeyorInfo implements CIProviderInfo {
2526
public static final String APPVEYOR_REPO_BRANCH = "APPVEYOR_REPO_BRANCH";
2627
public static final String APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH =
2728
"APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH";
29+
public static final String APPVEYOR_PULL_REQUEST_HEAD_COMMIT =
30+
"APPVEYOR_PULL_REQUEST_HEAD_COMMIT";
2831
public static final String APPVEYOR_REPO_TAG_NAME = "APPVEYOR_REPO_TAG_NAME";
2932
public static final String APPVEYOR_REPO_COMMIT_MESSAGE_SUBJECT = "APPVEYOR_REPO_COMMIT_MESSAGE";
3033
public static final String APPVEYOR_REPO_COMMIT_MESSAGE_BODY =
@@ -83,7 +86,15 @@ public CIInfo buildCIInfo() {
8386
@Nonnull
8487
@Override
8588
public PullRequestInfo buildPullRequestInfo() {
86-
return PullRequestInfo.EMPTY;
89+
// check if PR is detected
90+
if (Strings.isNotBlank(environment.get(APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH))) {
91+
return new PullRequestInfo(
92+
normalizeBranch(environment.get(APPVEYOR_REPO_BRANCH)),
93+
null,
94+
environment.get(APPVEYOR_PULL_REQUEST_HEAD_COMMIT));
95+
} else {
96+
return PullRequestInfo.EMPTY;
97+
}
8798
}
8899

89100
private String buildGitBranch(final String repoProvider) {

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BitBucketInfo.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class BitBucketInfo implements CIProviderInfo {
2626
public static final String BITBUCKET_GIT_COMMIT = "BITBUCKET_COMMIT";
2727
public static final String BITBUCKET_GIT_BRANCH = "BITBUCKET_BRANCH";
2828
public static final String BITBUCKET_GIT_TAG = "BITBUCKET_TAG";
29+
public static final String BITBUCKET_PR_DESTINATION_BRANCH = "BITBUCKET_PR_DESTINATION_BRANCH";
2930

3031
private final CiEnvironment environment;
3132

@@ -74,7 +75,8 @@ public CIInfo buildCIInfo() {
7475
@Nonnull
7576
@Override
7677
public PullRequestInfo buildPullRequestInfo() {
77-
return PullRequestInfo.EMPTY;
78+
return new PullRequestInfo(
79+
normalizeBranch(environment.get(BITBUCKET_PR_DESTINATION_BRANCH)), null, null);
7880
}
7981

8082
private String buildPipelineUrl(final String repo, final String number) {

0 commit comments

Comments
 (0)