Skip to content

Commit fde0164

Browse files
authored
Merge branch 'master' into alejandro.gonzalez/add-http-route-play-in-iast
2 parents ff31a0f + 956f570 commit fde0164

File tree

54 files changed

+2900
-170
lines changed

Some content is hidden

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

54 files changed

+2900
-170
lines changed

.github/CODEOWNERS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,9 @@
110110
/internal-api/src/main/java/datadog/trace/api/EndpointCheckpointer.java @DataDog/profiling-java
111111
/internal-api/src/main/java/datadog/trace/api/EndpointTracker.java @DataDog/profiling-java
112112
/dd-smoke-tests/profiling-integration-tests/ @DataDog/profiling-java
113+
114+
# @DataDog/ml-observability
115+
dd-trace-api/src/main/java/datadog/trace/api/llmobs/ @DataDog/ml-observability
116+
dd-java-agent/agent-llmobs/ @DataDog/ml-observability
117+
dd-trace-core/src/main/java/datadog/trace/llmobs/ @DataDog/ml-observability
118+
dd-trace-core/src/test/groovy/datadog/trace/llmobs/ @DataDog/ml-observability

.gitlab-ci.yml

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,11 @@ default:
119119

120120
.gitlab_base_ref_params: &gitlab_base_ref_params
121121
- |
122-
# FIXME: Disabled until we find a way to not hit GitHub API rate limit
123-
if false && [[ ! $CI_COMMIT_BRANCH =~ ^(master|release/.*)$ ]]; then
124-
export GIT_BASE_REF=$(.gitlab/find-gh-base-ref.sh)
125-
if [[ -n "$GIT_BASE_REF" ]]; then
126-
export GRADLE_PARAMS="$GRADLE_PARAMS -PgitBaseRef=origin/$GIT_BASE_REF"
127-
else
128-
echo "Failed to find base ref for PR" >&2
129-
fi
122+
export GIT_BASE_REF=$(.gitlab/find-gh-base-ref.sh)
123+
if [[ -n "$GIT_BASE_REF" ]]; then
124+
export GRADLE_PARAMS="$GRADLE_PARAMS -PgitBaseRef=origin/$GIT_BASE_REF"
125+
else
126+
echo "Failed to find base ref for PR" >&2
130127
fi
131128
132129
.gradle_build: &gradle_build
@@ -149,6 +146,7 @@ default:
149146
- .gradle/caches
150147
- .gradle/notifications
151148
policy: $DEPENDENCY_CACHE_POLICY
149+
unprotect: true
152150
fallback_keys: # Use fallback keys because all cache types are not populated. See note under: populate_dep_cache
153151
- '$CI_SERVER_VERSION-base'
154152
- '$CI_SERVER_VERSION-lib'
@@ -158,15 +156,19 @@ default:
158156
- .gradle/$GRADLE_VERSION/executionHistory
159157
- workspace
160158
policy: $BUILD_CACHE_POLICY
159+
unprotect: true
161160
before_script:
162161
- source .gitlab/gitlab-utils.sh
162+
# Akka token added to SSM from https://account.akka.io/token
163+
- export AKKA_REPO_TOKEN=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.akka_repo_token --with-decryption --query "Parameter.Value" --out text)
163164
- mkdir -p .gradle
164165
- export GRADLE_USER_HOME=$(pwd)/.gradle
165166
- |
166167
# Don't put jvm args here as it will be picked up by child gradle processes used in tests
167168
cat << EOF > $GRADLE_USER_HOME/gradle.properties
168169
mavenRepositoryProxy=$MAVEN_REPOSITORY_PROXY
169170
gradlePluginProxy=$GRADLE_PLUGIN_PROXY
171+
akkaRepositoryToken=$AKKA_REPO_TOKEN
170172
EOF
171173
- |
172174
# replace maven central part by MAVEN_REPOSITORY_PROXY in .mvn/wrapper/maven-wrapper.properties
@@ -198,11 +200,11 @@ pre-release-checks:
198200
allow_failure: false
199201
script:
200202
- |
201-
SONATYPE_USERNAME=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.central_username --with-decryption --query "Parameter.Value" --out text)
202-
SONATYPE_PASSWORD=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.central_password --with-decryption --query "Parameter.Value" --out text)
203+
MAVEN_CENTRAL_USERNAME=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.central_username --with-decryption --query "Parameter.Value" --out text)
204+
MAVEN_CENTRAL_PASSWORD=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.central_password --with-decryption --query "Parameter.Value" --out text)
203205
# See https://central.sonatype.org/publish/publish-portal-api/
204206
# 15e0cbbb-deff-421e-9e02-296a24d0cada is deployment, any deployment id listed in central work, the idea is to check whether the token can authenticate
205-
curl --request POST --include --fail https://central.sonatype.com/api/v1/publisher/status?id=15e0cbbb-deff-421e-9e02-296a24d0cada --header "Authorization: Bearer $(printf "$SONATYPE_USERNAME:$SONATYPE_PASSWORD" | base64)"
207+
curl --request POST --include --fail https://central.sonatype.com/api/v1/publisher/status?id=15e0cbbb-deff-421e-9e02-296a24d0cada --header "Authorization: Bearer $(printf "$MAVEN_CENTRAL_USERNAME:$MAVEN_CENTRAL_PASSWORD" | base64)"
206208
if [ $? -ne 0 ]; then
207209
echo "Failed to authenticate against central. Check credentials, see https://datadoghq.atlassian.net/wiki/x/Oog5OgE"
208210
exit 1
@@ -766,8 +768,8 @@ deploy_to_di_backend:manual:
766768
UPSTREAM_COMMIT_AUTHOR: $CI_COMMIT_AUTHOR
767769
UPSTREAM_COMMIT_SHORT_SHA: $CI_COMMIT_SHORT_SHA
768770

769-
# If the deploy_to_sonatype job is re-run, re-trigger the deploy_artifacts_to_github job as well so that the artifacts match.
770-
deploy_to_sonatype:
771+
# If the deploy_to_maven_central job is re-run, re-trigger the deploy_artifacts_to_github job as well so that the artifacts match.
772+
deploy_to_maven_central:
771773
extends: .gradle_build
772774
stage: publish
773775
needs: [ build ]
@@ -784,8 +786,8 @@ deploy_to_sonatype:
784786
- when: manual
785787
allow_failure: true
786788
script:
787-
- export SONATYPE_USERNAME=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.central_username --with-decryption --query "Parameter.Value" --out text)
788-
- export SONATYPE_PASSWORD=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.central_password --with-decryption --query "Parameter.Value" --out text)
789+
- export MAVEN_CENTRAL_USERNAME=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.central_username --with-decryption --query "Parameter.Value" --out text)
790+
- export MAVEN_CENTRAL_PASSWORD=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.central_password --with-decryption --query "Parameter.Value" --out text)
789791
- export GPG_PRIVATE_KEY=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.signing.gpg_private_key --with-decryption --query "Parameter.Value" --out text)
790792
- export GPG_PASSWORD=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.signing.gpg_passphrase --with-decryption --query "Parameter.Value" --out text)
791793
- ./gradlew -PbuildInfo.build.number=$CI_JOB_ID publishToSonatype closeSonatypeStagingRepository -PskipTests $GRADLE_ARGS
@@ -803,11 +805,11 @@ deploy_artifacts_to_github:
803805
when: never
804806
- if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/'
805807
when: on_success
806-
# Requires the deploy_to_sonatype job to have run first (the UP-TO-DATE gradle check across jobs is broken)
808+
# Requires the deploy_to_maven_central job to have run first (the UP-TO-DATE gradle check across jobs is broken)
807809
# This will deploy the artifacts built from the publishToSonatype task to the GitHub release
808810
needs:
809-
- job: deploy_to_sonatype
810-
# The deploy_to_sonatype job is not run for release candidate versions
811+
- job: deploy_to_maven_central
812+
# The deploy_to_maven_central job is not run for release candidate versions
811813
optional: true
812814
script:
813815
- aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.gh_release_token --with-decryption --query "Parameter.Value" --out text > github-token.txt

.gitlab/benchmarks.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ check-big-regressions:
7676
when: on_success
7777
tags: ["arch:amd64"]
7878
rules:
79+
- if: '$POPULATE_CACHE'
80+
when: never
7981
- if: '$CI_COMMIT_BRANCH !~ /^(master|release\/)/'
8082
when: on_success
8183
- when: never

.gitlab/find-gh-base-ref.sh

Lines changed: 57 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22
# Determines the base branch for the current PR (if we are running in a PR).
33
set -euo pipefail
44

5+
if [[ -n "${CI_COMMIT_BRANCH:-}" ]]; then
6+
echo "CI_COMMIT_BRANCH is set to $CI_COMMIT_BRANCH" >&2
7+
else
8+
echo "CI_COMMIT_BRANCH is not set, skipping base ref detection" >&2
9+
exit 1
10+
fi
11+
12+
if [[ $CI_COMMIT_BRANCH =~ ^(master|release/.*)$ ]]; then
13+
echo "CI_COMMIT_BRANCH is a master or release branch, skipping base ref detection" >&2
14+
exit 1
15+
fi
16+
517
CURRENT_HEAD_SHA="$(git rev-parse HEAD)"
618
if [[ -z "${CURRENT_HEAD_SHA:-}" ]]; then
719
echo "Failed to determine current HEAD SHA" >&2
@@ -33,81 +45,61 @@ if [[ -f $CACHE_PATH ]]; then
3345
fi
3446

3547
# Happy path: if we're just one commit away from master, base ref is master.
36-
if [[ $(git log --pretty=oneline origin/master..HEAD | wc -l) -eq 1 ]]; then
48+
if [[ $(git rev-list --count origin/master..HEAD) -eq 1 ]]; then
3749
echo "We are just one commit away from master, base ref is master" >&2
3850
save_cache "master" "$CURRENT_HEAD_SHA"
3951
echo "master"
4052
exit 0
4153
fi
4254

43-
# In GitLab: we have no reference to the base branch or even the PR number.
44-
# We have to find it from the current branch name, which is defined in
45-
# CI_COMMIT_REF_NAME.
46-
if [[ -z "${CI_COMMIT_REF_NAME}" ]]; then
47-
echo "CI_COMMIT_REF_NAME is not set, not running in GitLab CI?" >&2
48-
exit 1
49-
fi
55+
get_distance_from_merge_base() {
56+
local candidate_base="$1"
57+
local merge_base_sha
58+
local distance
59+
merge_base_sha=$(git merge-base "$candidate_base" HEAD)
60+
distance=$(git rev-list --count "$merge_base_sha".."$CURRENT_HEAD_SHA")
61+
echo "Distance from $candidate_base is $distance" >&2
62+
echo "$distance"
63+
}
5064

51-
# In GitLab, CI_PROJECT_NAME is set, otherwise, set it for testing.
52-
export CI_PROJECT_NAME="${CI_PROJECT_NAME:-dd-trace-java}"
65+
# Find the best base ref: the master/release branch whose merge base is closest to HEAD.
66+
# If there are multiple candidates (e.g. immediately after a release branch is created), we cannot
67+
# disambiguate and return an error.
68+
# NOTE: GitHub API is more robust for this task, but we hit rate limits.
69+
BEST_CANDIDATES=(origin/master)
70+
BEST_DISTANCE=$(get_distance_from_merge_base origin/master)
5371

54-
if [[ -z "${GITHUB_TOKEN:-}" ]]; then
55-
echo "GITHUB_TOKEN is not set, fetching from AWS SSM" >&2
56-
if ! command -v aws >/dev/null 2>&1; then
57-
echo "aws is not installed, please install it" >&2
58-
exit 1
59-
fi
60-
set +e
61-
GITHUB_TOKEN=$(aws ssm get-parameter --name "ci.$CI_PROJECT_NAME.gh_release_token" --with-decryption --query "Parameter.Value" --output text)
62-
set -e
63-
if [[ -z "${GITHUB_TOKEN:-}" ]]; then
64-
echo "Failed to fetch GITHUB_TOKEN from AWS SSM" >&2
65-
exit 1
66-
fi
67-
export GITHUB_TOKEN
72+
# If the current branch is not a project/ branch, project/ branches are candidates.
73+
# This accounts for the case when the project/ branch is being merged to master.
74+
if [[ ! "$CI_COMMIT_BRANCH" =~ ^project/.*$ ]]; then
75+
mapfile -t CANDIDATE_BASES < <(git branch -a --sort=committerdate --format='%(refname:short)' --list 'origin/release/v*' --list 'origin/project/*' | tac)
76+
else
77+
mapfile -t CANDIDATE_BASES < <(git branch -a --sort=committerdate --format='%(refname:short)' --list 'origin/release/v*' | tac)
6878
fi
6979

70-
if ! command -v curl >/dev/null 2>&1; then
71-
echo "curl is not installed, please install it" >&2
72-
exit 1
73-
fi
80+
for candidate_base in "${CANDIDATE_BASES[@]}"; do
81+
distance=$(get_distance_from_merge_base "$candidate_base")
82+
if [[ $distance -lt $BEST_DISTANCE ]]; then
83+
BEST_DISTANCE=$distance
84+
BEST_CANDIDATES=("$candidate_base")
85+
elif [[ $distance -eq $BEST_DISTANCE ]]; then
86+
BEST_CANDIDATES+=("$candidate_base")
87+
fi
88+
done
7489

75-
if ! command -v jq >/dev/null 2>&1; then
76-
echo "jq is not installed, please install it" >&2
77-
exit 1
90+
if [[ ${#BEST_CANDIDATES[@]} -eq 1 ]]; then
91+
# Remote the origin/ prefix
92+
base_ref="${BEST_CANDIDATES[0]#origin/}"
93+
echo "Base ref is ${base_ref}" >&2
94+
save_cache "${base_ref}" "$CURRENT_HEAD_SHA"
95+
echo "${base_ref}"
96+
exit 0
7897
fi
7998

80-
while true; do
81-
set +e
82-
PR_DATA=$(curl \
83-
-XGET \
84-
--silent \
85-
--include \
86-
--fail-with-body \
87-
-H 'Accept: application/vnd.github+json' \
88-
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
89-
-H "X-GitHub-Api-Version: 2022-11-28" \
90-
"https://api.github.com/repos/datadog/dd-trace-java/pulls?head=DataDog:${CI_COMMIT_REF_NAME}&sort=updated&direction=desc")
91-
exit_code=$?
92-
set -e
93-
if [[ ${exit_code} -eq 0 ]]; then
94-
PR_NUMBER=$(echo "$PR_DATA" | sed '1,/^[[:space:]]*$/d' | jq -r '.[].number')
95-
PR_BASE_REF=$(echo "$PR_DATA" | sed '1,/^[[:space:]]*$/d' | jq -r '.[].base.ref')
96-
if [[ -n "${PR_BASE_REF:-}" ]]; then
97-
echo "PR is https://github.com/datadog/dd-trace-java/pull/${PR_NUMBER} and base ref is ${PR_BASE_REF}">&2
98-
save_cache "${PR_BASE_REF}" "$CURRENT_HEAD_SHA"
99-
echo "${PR_BASE_REF}"
100-
exit 0
101-
fi
102-
fi
103-
if echo "$PR_DATA" | grep -q "^x-ratelimit-reset:"; then
104-
reset_timestamp=$(echo -n "$PR_DATA" | grep "^x-ratelimit-reset:" | sed -e 's/^x-ratelimit-reset: //' -e 's/\r//')
105-
now=$(date +%s)
106-
sleep_time=$((reset_timestamp - now + 1))
107-
echo "GitHub rate limit exceeded, sleeping for ${sleep_time} seconds" >&2
108-
sleep "${sleep_time}"
109-
continue
110-
fi
111-
echo -e "GitHub request failed for an unknown reason:\n$(echo "$PR_DATA" | sed '/^$/q')" >&2
112-
exit 1
113-
done
99+
# If base ref is ambiguous, we cannot determine the correct one.
100+
# Example: a release branch is created, and a PR is opened starting from the
101+
# commit where the release branch was created. The distance to the merge base
102+
# for both master and the release branch is the same. In this case, we bail
103+
# out, and make no assumption on which is the correct base ref.
104+
echo "Base ref is ambiguous, candidates are: ${BEST_CANDIDATES[*]}" >&2
105+
exit 1

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ nexusPublishing {
110110
sonatype {
111111
nexusUrl.set(uri("https://ossrh-staging-api.central.sonatype.com/service/local/"))
112112
snapshotRepositoryUrl.set(uri("https://central.sonatype.com/repository/maven-snapshots/"))
113-
username = System.getenv("SONATYPE_USERNAME")
114-
password = System.getenv("SONATYPE_PASSWORD")
113+
username = System.getenv("MAVEN_CENTRAL_USERNAME")
114+
password = System.getenv("MAVEN_CENTRAL_PASSWORD")
115115
}
116116
}
117117
}

communication/src/main/java/datadog/communication/BackendApiFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ private HttpUrl getAgentlessUrl(Intake intake) {
7272

7373
public enum Intake {
7474
API("api", "v2", Config::isCiVisibilityAgentlessEnabled, Config::getCiVisibilityAgentlessUrl),
75+
LLMOBS_API("api", "v2", Config::isLlmObsAgentlessEnabled, Config::getLlMObsAgentlessUrl),
7576
LOGS(
7677
"http-intake.logs",
7778
"v2",

communication/src/main/java/datadog/communication/ddagent/SharedCommunicationObjects.java

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class SharedCommunicationObjects {
3030
public OkHttpClient okHttpClient;
3131
public HttpUrl agentUrl;
3232
public Monitoring monitoring;
33-
private DDAgentFeaturesDiscovery featuresDiscovery;
33+
private volatile DDAgentFeaturesDiscovery featuresDiscovery;
3434
private ConfigurationPoller configurationPoller;
3535

3636
public SharedCommunicationObjects() {
@@ -139,28 +139,34 @@ public void setFeaturesDiscovery(DDAgentFeaturesDiscovery featuresDiscovery) {
139139
}
140140

141141
public DDAgentFeaturesDiscovery featuresDiscovery(Config config) {
142-
if (featuresDiscovery == null) {
143-
createRemaining(config);
144-
featuresDiscovery =
145-
new DDAgentFeaturesDiscovery(
146-
okHttpClient,
147-
monitoring,
148-
agentUrl,
149-
config.isTraceAgentV05Enabled(),
150-
config.isTracerMetricsEnabled());
151-
152-
if (paused) {
153-
// defer remote discovery until remote I/O is allowed
154-
} else {
155-
if (AGENT_THREAD_GROUP.equals(Thread.currentThread().getThreadGroup())) {
156-
featuresDiscovery.discover(); // safe to run on same thread
157-
} else {
158-
// avoid performing blocking I/O operation on application thread
159-
AgentTaskScheduler.INSTANCE.execute(featuresDiscovery::discover);
142+
DDAgentFeaturesDiscovery ret = featuresDiscovery;
143+
if (ret == null) {
144+
synchronized (this) {
145+
if (featuresDiscovery == null) {
146+
createRemaining(config);
147+
ret =
148+
new DDAgentFeaturesDiscovery(
149+
okHttpClient,
150+
monitoring,
151+
agentUrl,
152+
config.isTraceAgentV05Enabled(),
153+
config.isTracerMetricsEnabled());
154+
155+
if (paused) {
156+
// defer remote discovery until remote I/O is allowed
157+
} else {
158+
if (AGENT_THREAD_GROUP.equals(Thread.currentThread().getThreadGroup())) {
159+
ret.discover(); // safe to run on same thread
160+
} else {
161+
// avoid performing blocking I/O operation on application thread
162+
AgentTaskScheduler.INSTANCE.execute(ret::discover);
163+
}
164+
}
165+
featuresDiscovery = ret;
160166
}
161167
}
162168
}
163-
return featuresDiscovery;
169+
return ret;
164170
}
165171

166172
private static final class FixedConfigUrlSupplier implements Supplier<String> {

components/environment/src/test/java/datadog/environment/CommandLineTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import static java.util.Collections.emptyList;
88
import static java.util.Objects.requireNonNull;
99
import static org.junit.jupiter.api.Assertions.assertEquals;
10-
import static org.junit.jupiter.api.Assumptions.assumeFalse;
10+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
1111
import static org.junit.jupiter.params.provider.Arguments.arguments;
1212

1313
import datadog.environment.CommandLineHelper.Result;
@@ -99,7 +99,7 @@ private static void skipArgFileTestOnJava8(RunArguments arguments) {
9999
}
100100
}
101101
if (useArgFile) {
102-
assumeFalse(System.getProperty("java.home").matches(".*[-/]8[./].*"));
102+
assumeTrue(JavaVirtualMachine.isJavaVersionAtLeast(9));
103103
}
104104
}
105105

components/environment/src/test/java/datadog/environment/JavaVirtualMachineTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,14 @@ void onlyOnGraalVm() {
114114
void onlyOnIbm8() {
115115
assertFalse(JavaVirtualMachine.isGraalVM());
116116
assertTrue(JavaVirtualMachine.isIbm8());
117-
assertFalse(JavaVirtualMachine.isJ9());
117+
assertTrue(JavaVirtualMachine.isJ9());
118118
assertFalse(JavaVirtualMachine.isOracleJDK8());
119119
}
120120

121121
@Test
122122
@EnabledIfSystemProperty(named = "java.vm.name", matches = ".*J9.*")
123123
void onlyOnJ9() {
124124
assertFalse(JavaVirtualMachine.isGraalVM());
125-
assertFalse(JavaVirtualMachine.isIbm8());
126125
assertTrue(JavaVirtualMachine.isJ9());
127126
assertFalse(JavaVirtualMachine.isOracleJDK8());
128127
}

0 commit comments

Comments
 (0)