Skip to content

Commit 903085e

Browse files
authored
Merge branch 'master' into mhlidd/config_inversion_telemetry
2 parents 8d2c687 + cfc9870 commit 903085e

File tree

29 files changed

+453
-161
lines changed

29 files changed

+453
-161
lines changed

.gitlab-ci.yml

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,10 @@ default:
193193
after_script:
194194
- *cgroup_info
195195

196-
# TODO: Add a pre-release check to see if the dd-octo-sts token is working.
197-
# Checks and fail early if central credentials are incorrect, indeed, when a new token is generated
198-
# on the central publisher protal, it invalidates the old one. This checks prevents going further.
196+
# Check and fail early if maven central credentials are incorrect. When a new token is generated
197+
# on the central publisher portal, it invalidates the old one. This check prevents going further.
199198
# See https://datadoghq.atlassian.net/wiki/x/Oog5OgE
200-
pre-release-checks:
199+
maven-central-pre-release-check:
201200
image: ghcr.io/datadog/dd-trace-java-docker-build:${BUILDER_IMAGE_VERSION_PREFIX}base
202201
stage: .pre
203202
rules:
@@ -216,9 +215,37 @@ pre-release-checks:
216215
exit 1
217216
fi
218217
218+
dd-octo-sts-pre-release-check:
219+
image: registry.ddbuild.io/images/dd-octo-sts-ci-base:2025.06-1
220+
stage: .pre
221+
tags: [ "arch:amd64" ]
222+
id_tokens:
223+
DDOCTOSTS_ID_TOKEN:
224+
aud: dd-octo-sts
225+
rules:
226+
- if: '$POPULATE_CACHE'
227+
when: never
228+
- if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/'
229+
when: on_success
230+
allow_failure: false
231+
before_script:
232+
- dd-octo-sts version
233+
- dd-octo-sts debug --scope DataDog/dd-trace-java --policy self.gitlab.release
234+
- dd-octo-sts token --scope DataDog/dd-trace-java --policy self.gitlab.release > test-github-token.txt
235+
script:
236+
- gh auth login --with-token < test-github-token.txt
237+
- gh auth status
238+
after_script:
239+
- dd-octo-sts revoke -t $(cat test-github-token.txt)
240+
retry:
241+
max: 2
242+
when: always
243+
219244
build:
220245
needs:
221-
- job: pre-release-checks
246+
- job: maven-central-pre-release-check
247+
optional: true
248+
- job: dd-octo-sts-pre-release-check
222249
optional: true
223250
extends: .gradle_build
224251
variables:
@@ -822,15 +849,14 @@ deploy_artifacts_to_github:
822849
# The deploy_to_maven_central job is not run for release candidate versions
823850
optional: true
824851
before_script:
825-
# Get token
826852
- dd-octo-sts version
827853
- dd-octo-sts debug --scope DataDog/dd-trace-java --policy self.gitlab.release
828854
- dd-octo-sts token --scope DataDog/dd-trace-java --policy self.gitlab.release > github-token.txt
829855
script:
830856
- gh auth login --with-token < github-token.txt
831-
- gh auth status # Maybe helpful to have this output in logs?
857+
- gh auth status
832858
- export VERSION=${CI_COMMIT_TAG##v} # remove "v" from front of tag to get version
833-
- cp workspace/dd-java-agent/build/libs/dd-java-agent-${VERSION}.jar workspace/dd-java-agent/build/libs/dd-java-agent.jar # we upload two filenames
859+
- cp workspace/dd-java-agent/build/libs/dd-java-agent-${VERSION}.jar workspace/dd-java-agent/build/libs/dd-java-agent.jar # upload two filenames
834860
- gh release upload --clobber --repo DataDog/dd-trace-java $CI_COMMIT_TAG workspace/dd-java-agent/build/libs/dd-java-agent.jar
835861
- gh release upload --clobber --repo DataDog/dd-trace-java $CI_COMMIT_TAG workspace/dd-java-agent/build/libs/dd-java-agent-${VERSION}.jar
836862
- gh release upload --clobber --repo DataDog/dd-trace-java $CI_COMMIT_TAG workspace/dd-trace-api/build/libs/dd-trace-api-${VERSION}.jar
@@ -841,36 +867,6 @@ deploy_artifacts_to_github:
841867
max: 2
842868
when: always
843869

844-
# This is the original job that uses the AWS SSM token retrieval method. Allow manual triggering in case the dd-octo-sts token is not working.
845-
# TODO: Remove this job once the dd-octo-sts token is provably working.
846-
deploy_artifacts_to_github_old:
847-
stage: publish
848-
image: registry.ddbuild.io/github-cli:v27480869-eafb11d-2.43.0
849-
rules:
850-
- if: '$POPULATE_CACHE'
851-
when: never
852-
- if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/'
853-
when: manual
854-
# Requires the deploy_to_maven_central job to have run first (the UP-TO-DATE gradle check across jobs is broken)
855-
# This will deploy the artifacts built from the publishToSonatype task to the GitHub release
856-
needs:
857-
- job: deploy_to_maven_central
858-
# The deploy_to_maven_central job is not run for release candidate versions
859-
optional: true
860-
script:
861-
- 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
862-
- gh auth login --with-token < github-token.txt
863-
- gh auth status # Maybe helpful to have this output in logs?
864-
- export VERSION=${CI_COMMIT_TAG##v} # remove "v" from front of tag to get version
865-
- cp workspace/dd-java-agent/build/libs/dd-java-agent-${VERSION}.jar workspace/dd-java-agent/build/libs/dd-java-agent.jar # we upload two filenames
866-
- gh release upload --clobber --repo DataDog/dd-trace-java $CI_COMMIT_TAG workspace/dd-java-agent/build/libs/dd-java-agent.jar
867-
- gh release upload --clobber --repo DataDog/dd-trace-java $CI_COMMIT_TAG workspace/dd-java-agent/build/libs/dd-java-agent-${VERSION}.jar
868-
- gh release upload --clobber --repo DataDog/dd-trace-java $CI_COMMIT_TAG workspace/dd-trace-api/build/libs/dd-trace-api-${VERSION}.jar
869-
- gh release upload --clobber --repo DataDog/dd-trace-java $CI_COMMIT_TAG workspace/dd-trace-ot/build/libs/dd-trace-ot-${VERSION}.jar
870-
retry:
871-
max: 2
872-
when: always
873-
874870
requirements_json_test:
875871
rules:
876872
- when: on_success

.gitlab/macrobenchmarks.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ check-slo-breaches:
8080
interruptible: true
8181
tags: ["arch:amd64"]
8282
image: registry.ddbuild.io/images/benchmarking-platform-tools-ubuntu:latest
83-
when: on_success
83+
rules:
84+
- if: $POPULATE_CACHE
85+
when: never
86+
- when: on_success
8487
needs:
8588
- job: baseline
8689
artifacts: true

components/environment/src/main/java/datadog/environment/JvmOptions.java

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import java.nio.file.Paths;
1616
import java.util.ArrayList;
1717
import java.util.List;
18-
import java.util.ListIterator;
1918
import java.util.StringTokenizer;
2019

2120
/** Fetches and captures the JVM options. */
@@ -41,28 +40,44 @@ private String[] readProcFsCmdLine() {
4140
return null;
4241
}
4342

44-
@SuppressForbidden // Class.forName() as backup
4543
private List<String> findVmOptions() {
44+
return findVmOptions(PROCFS_CMDLINE);
45+
}
46+
47+
@SuppressForbidden // Class.forName() as backup
48+
// Visible for testing
49+
List<String> findVmOptions(String[] procfsCmdline) {
4650
// Try ProcFS on Linux
47-
if (PROCFS_CMDLINE != null) {
51+
// Be aware that when running a native image, the command line in /proc/self/cmdline is just the
52+
// executable
53+
if (procfsCmdline != null) {
54+
// Create list of VM options
55+
List<String> vmOptions = new ArrayList<>();
4856
// Start at 1 to skip "java" command itself
4957
int index = 1;
50-
// Look for main class or "-jar", end of VM options
51-
for (; index < PROCFS_CMDLINE.length; index++) {
52-
if (!PROCFS_CMDLINE[index].startsWith("-") || "-jar".equals(PROCFS_CMDLINE[index])) {
53-
break;
54-
}
55-
}
56-
// Create list of VM options
57-
List<String> vmOptions = new ArrayList<>(asList(PROCFS_CMDLINE).subList(1, index + 1));
58-
ListIterator<String> iterator = vmOptions.listIterator();
59-
while (iterator.hasNext()) {
60-
String vmOption = iterator.next();
61-
if (vmOption.startsWith("@")) {
62-
iterator.remove();
63-
for (String argument : getArgumentsFromFile(vmOption)) {
64-
iterator.add(argument);
58+
// Look for first self-standing argument that is not prefixed with "-" or end of VM options
59+
// Skip "-jar" and the jar file
60+
// Simultaneously, collect all arguments in the VM options
61+
for (; index < procfsCmdline.length; index++) {
62+
String argument = procfsCmdline[index];
63+
if (argument.startsWith("@")) {
64+
vmOptions.addAll(getArgumentsFromFile(argument));
65+
} else {
66+
if ("-jar".equals(argument)) {
67+
// skip "-jar" and the jar file
68+
index++;
69+
continue;
70+
} else if ("-cp".equals(argument)) {
71+
// slurp '-cp' and the classpath
72+
vmOptions.add(argument);
73+
if (index + 1 < procfsCmdline.length) {
74+
argument = procfsCmdline[++index];
75+
}
76+
} else if (!argument.startsWith("-")) {
77+
// end of VM options
78+
break;
6579
}
80+
vmOptions.add(argument);
6681
}
6782
}
6883
// Insert JDK_JAVA_OPTIONS at the start if present and supported

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

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,23 @@
88
import static java.util.Collections.emptyList;
99
import static java.util.Collections.emptyMap;
1010
import static java.util.Collections.singletonList;
11+
import static java.util.Objects.requireNonNull;
1112
import static org.junit.jupiter.api.Assertions.assertEquals;
1213
import static org.junit.jupiter.api.Assumptions.assumeTrue;
1314
import static org.junit.jupiter.params.provider.Arguments.arguments;
1415

1516
import datadog.environment.CommandLineHelper.Result;
17+
import java.io.BufferedReader;
18+
import java.io.IOException;
19+
import java.io.InputStream;
20+
import java.io.InputStreamReader;
21+
import java.util.ArrayList;
22+
import java.util.Collection;
1623
import java.util.HashMap;
1724
import java.util.List;
1825
import java.util.Map;
1926
import java.util.stream.Stream;
27+
import org.junit.jupiter.api.Assertions;
2028
import org.junit.jupiter.params.ParameterizedTest;
2129
import org.junit.jupiter.params.provider.Arguments;
2230
import org.junit.jupiter.params.provider.MethodSource;
@@ -105,6 +113,67 @@ void testFindVmOptions(
105113
assertEquals(expectedArguments.jvmOptions, result.jvmOptions, "Failed to get JVM options");
106114
}
107115

116+
@MethodSource
117+
private static Stream<Arguments> procFsCmdLine() {
118+
// spotless:off
119+
return Stream.of(
120+
arguments(
121+
"No arguments",
122+
new String[0],
123+
emptyList()
124+
),
125+
arguments(
126+
"Native image launcher",
127+
new String[]{"native-image-launcher", "-Xmx512m"},
128+
singletonList("-Xmx512m")
129+
),
130+
arguments(
131+
"Java with JAR and options",
132+
new String[]{"java", "-Xmx512m", "-Xms256m", "-jar", "app.jar"},
133+
asList("-Xmx512m", "-Xms256m")
134+
),
135+
arguments(
136+
"Java from class and options",
137+
new String[]{"java", "-Xmx512m", "-Xms256m", "-cp", "app.jar", "Main"},
138+
asList("-Xmx512m", "-Xms256m", "-cp", "app.jar")
139+
),
140+
arguments(
141+
"Java from class and options, mixed",
142+
new String[]{"java", "-Xms256m", "-cp", "app.jar", "-Xmx512m", "Main"},
143+
asList("-Xms256m", "-cp", "app.jar", "-Xmx512m")
144+
),
145+
arguments(
146+
"Args from file",
147+
new String[]{"java", "-Dargfile.prop=test", "-verbose:class", argFile("carriage-return-separated"), "-jar", "app.jar"},
148+
flatten("-Dargfile.prop=test", "-verbose:class", expectedArsFromArgFile("carriage-return-separated"))
149+
),
150+
arguments(
151+
"Args from file",
152+
new String[]{"java", "-Dargfile.prop=test", "-verbose:class", argFile("new-line-separated"), "-jar", "app.jar"},
153+
flatten("-Dargfile.prop=test", "-verbose:class", expectedArsFromArgFile("new-line-separated"))
154+
),
155+
arguments(
156+
"Args from file",
157+
new String[]{"java", "-Dargfile.prop=test", "-verbose:class", argFile("space-separated"), "-jar", "app.jar"},
158+
flatten("-Dargfile.prop=test", "-verbose:class", expectedArsFromArgFile("space-separated"))
159+
),
160+
arguments(
161+
"Args from file",
162+
new String[]{"java", "-Dargfile.prop=test", "-verbose:class", argFile("tab-separated"), "-jar", "app.jar"},
163+
flatten("-Dargfile.prop=test", "-verbose:class", expectedArsFromArgFile("tab-separated"))
164+
));
165+
// spotless:on
166+
}
167+
168+
@ParameterizedTest(name = "[{index}] {0}")
169+
@MethodSource("procFsCmdLine")
170+
void testFindVmOptionsWithProcFsCmdLine(
171+
String useCase, String[] procfsCmdline, List<String> expected) throws Exception {
172+
JvmOptions vmOptions = new JvmOptions();
173+
List<String> found = vmOptions.findVmOptions(procfsCmdline);
174+
assertEquals(expected, found);
175+
}
176+
108177
private void skipJdkJavaOptionsOnJava8(Map<String, String> environmentVariables) {
109178
assumeTrue(
110179
JavaVirtualMachine.isJavaVersionAtLeast(9)
@@ -121,4 +190,36 @@ private static Map<String, String> env(String... keysAndValues) {
121190
}
122191
return env;
123192
}
193+
194+
private static String argFile(String name) {
195+
return "@src/test/resources/argfiles/" + name + ".txt";
196+
}
197+
198+
private static List<String> expectedArsFromArgFile(String name) {
199+
List<String> arguments = new ArrayList<>();
200+
try (InputStream stream =
201+
requireNonNull(
202+
CommandLineTest.class.getResourceAsStream("/argfiles/" + name + "-expected.txt"));
203+
BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) {
204+
String line;
205+
while ((line = reader.readLine()) != null) {
206+
arguments.add(line);
207+
}
208+
} catch (IOException e) {
209+
Assertions.fail("Failed to read expected args from " + name + "argfile", e);
210+
}
211+
return arguments;
212+
}
213+
214+
private static List<String> flatten(Object... values) {
215+
List<String> result = new ArrayList<>();
216+
for (Object value : values) {
217+
if (value instanceof Collection) {
218+
result.addAll((Collection<? extends String>) value);
219+
} else {
220+
result.add(value.toString());
221+
}
222+
}
223+
return result;
224+
}
124225
}

0 commit comments

Comments
 (0)