Skip to content

Commit 364cab5

Browse files
authored
Merge branch 'master' into bbujon/context
2 parents c23bbe5 + f15598a commit 364cab5

File tree

32 files changed

+597
-154
lines changed

32 files changed

+597
-154
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
issuer: https://token.actions.githubusercontent.com
2+
3+
subject: repo:DataDog/dd-trace-java:ref:refs/heads/master
4+
5+
claim_pattern:
6+
event_name: release
7+
ref: refs/heads/master
8+
ref_protected: "true"
9+
job_workflow_ref: DataDog/dd-trace-java/\.github/workflows/add-release-to-cloudfoundry\.yaml@refs/heads/master
10+
11+
permissions:
12+
contents: write

.gitlab-ci.yml

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ include:
77

88
stages:
99
- build
10-
- shared-pipeline
1110
- publish
11+
- shared-pipeline
1212
- benchmarks
1313
- macrobenchmarks
1414
- tests
@@ -580,7 +580,7 @@ muzzle-dep-report:
580580
CI_USE_TEST_AGENT: "true"
581581
CI_AGENT_HOST: local-agent
582582
services:
583-
- name: ghcr.io/datadog/dd-apm-test-agent/ddapm-test-agent:v1.27.1
583+
- name: ghcr.io/datadog/dd-apm-test-agent/ddapm-test-agent:v1.31.1
584584
alias: local-agent
585585
variables:
586586
LOG_LEVEL: "DEBUG"
@@ -880,6 +880,88 @@ requirements_json_test:
880880
package-oci:
881881
needs: [ build ]
882882

883+
override_verify_maven_central:
884+
image: registry.ddbuild.io/images/base/gbi-ubuntu_2204:release
885+
stage: publish
886+
needs: [ ]
887+
rules:
888+
- if: '$POPULATE_CACHE'
889+
when: never
890+
- when: manual
891+
allow_failure: true
892+
script:
893+
- touch OVERRIDE_MAVEN_VERIFY
894+
cache: # Cache is used to signal between the override_verify_maven_central and verify_maven_central_deployment jobs
895+
- key: $CI_PIPELINE_ID-OVERRIDE_SIGNAL
896+
paths:
897+
- OVERRIDE_MAVEN_VERIFY
898+
policy: push
899+
unprotect: true
900+
901+
# Verify Maven Central deployment is publicly available before publishing OCI images
902+
verify_maven_central_deployment:
903+
image: registry.ddbuild.io/images/base/gbi-ubuntu_2204:release
904+
stage: publish
905+
needs: [ deploy_to_maven_central ]
906+
rules:
907+
- if: '$POPULATE_CACHE'
908+
when: never
909+
- if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/'
910+
when: on_success
911+
- when: manual
912+
allow_failure: true
913+
cache: # Cache is used to signal between the override_verify_maven_central and verify_maven_central_deployment jobs
914+
- key: $CI_PIPELINE_ID-OVERRIDE_SIGNAL
915+
paths:
916+
- OVERRIDE_MAVEN_VERIFY
917+
policy: pull
918+
unprotect: true
919+
script:
920+
- if [ -f OVERRIDE_MAVEN_VERIFY ]; then echo "SKIPPING MAVEN VERIFICATION"; exit 0; fi
921+
- |
922+
export VERSION=${CI_COMMIT_TAG##v}
923+
ARTIFACT_URLS=(
924+
"https://repo1.maven.org/maven2/com/datadoghq/dd-java-agent/${VERSION}/dd-java-agent-${VERSION}.jar"
925+
"https://repo1.maven.org/maven2/com/datadoghq/dd-trace-api/${VERSION}/dd-trace-api-${VERSION}.jar"
926+
"https://repo1.maven.org/maven2/com/datadoghq/dd-trace-ot/${VERSION}/dd-trace-ot-${VERSION}.jar"
927+
)
928+
# Wait 5 mins initially, then try 5 times with a minute delay between each retry to see if the release artifacts are available
929+
sleep 300
930+
TRY=0
931+
MAX_TRIES=5
932+
DELAY=60
933+
while [ $TRY -lt $MAX_TRIES ]; do
934+
ARTIFACTS_AVAILABLE=true
935+
for URL in "${ARTIFACT_URLS[@]}"; do
936+
if ! curl --location --fail --silent --show-error -I "$URL"; then
937+
ARTIFACTS_AVAILABLE=false
938+
break
939+
fi
940+
done
941+
if [ "$ARTIFACTS_AVAILABLE" = true ]; then
942+
break
943+
fi
944+
TRY=$((TRY + 1))
945+
if [ $TRY -eq $MAX_TRIES ]; then
946+
echo "The release was not available after 10 mins. Manually re-run the job to try again."
947+
exit 1
948+
fi
949+
sleep $DELAY
950+
done
951+
952+
publishing-gate:
953+
stage: publish
954+
needs:
955+
- job: verify_maven_central_deployment
956+
optional: true # Required for releases only
957+
rules:
958+
- if: '$POPULATE_CACHE'
959+
when: on_success
960+
- if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/'
961+
when: on_success
962+
- when: manual
963+
allow_failure: true
964+
883965
configure_system_tests:
884966
variables:
885967
SYSTEM_TESTS_SCENARIOS_GROUPS: "simple_onboarding,simple_onboarding_profiling,simple_onboarding_appsec,docker-ssi,lib-injection"

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package datadog.environment;
22

3+
import static java.util.Collections.emptyMap;
4+
import static java.util.Collections.unmodifiableMap;
5+
6+
import java.util.HashMap;
7+
import java.util.Map;
38
import javax.annotation.Nullable;
49

510
/**
@@ -42,4 +47,18 @@ public static String getOrDefault(String name, String defaultValue) {
4247
return defaultValue;
4348
}
4449
}
50+
51+
/**
52+
* Gets all environment variables.
53+
*
54+
* @return All environment variables captured in an unmodifiable {@link Map}, or an empty {@link
55+
* Map} if they can't be retrieved.
56+
*/
57+
public static Map<String, String> getAll() {
58+
try {
59+
return unmodifiableMap(new HashMap<>(System.getenv()));
60+
} catch (SecurityException e) {
61+
return emptyMap();
62+
}
63+
}
4564
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package datadog.environment;
22

3+
import static java.util.Collections.emptyMap;
4+
import static java.util.Collections.unmodifiableMap;
5+
6+
import java.util.HashMap;
7+
import java.util.Map;
38
import javax.annotation.Nullable;
49

510
/**
@@ -42,6 +47,24 @@ public static String getOrDefault(String property, String defaultValue) {
4247
}
4348
}
4449

50+
/**
51+
* Convert system properties to an unmodifiable {@link Map}.
52+
*
53+
* @return All system properties captured in an unmodifiable {@link Map}, or an empty {@link Map}
54+
* if they can't be retrieved.
55+
*/
56+
public static Map<String, String> asStringMap() {
57+
try {
58+
Map<String, String> map = new HashMap<>();
59+
for (String propertyName : System.getProperties().stringPropertyNames()) {
60+
map.put(propertyName, System.getProperty(propertyName));
61+
}
62+
return unmodifiableMap(map);
63+
} catch (SecurityException ignored) {
64+
return emptyMap();
65+
}
66+
}
67+
4568
/**
4669
* Sets a system property value.
4770
*

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
44
import static org.junit.jupiter.api.Assertions.assertEquals;
5+
import static org.junit.jupiter.api.Assertions.assertFalse;
56
import static org.junit.jupiter.api.Assertions.assertNotNull;
67
import static org.junit.jupiter.api.Assertions.assertNull;
8+
import static org.junit.jupiter.api.Assertions.assertThrows;
79

10+
import java.util.Map;
811
import org.junit.jupiter.api.Test;
912

1013
class EnvironmentVariablesTest {
@@ -36,4 +39,13 @@ void testGetOrDefault() {
3639
assertDoesNotThrow(() -> EnvironmentVariables.getOrDefault(MISSING_ENV_VAR, null));
3740
assertNull(EnvironmentVariables.getOrDefault(MISSING_ENV_VAR, null));
3841
}
42+
43+
@Test
44+
void testGetAll() {
45+
Map<String, String> all = EnvironmentVariables.getAll();
46+
assertNotNull(all);
47+
assertFalse(all.isEmpty());
48+
// Unmodifiable collection
49+
assertThrows(UnsupportedOperationException.class, all::clear);
50+
}
3951
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static org.junit.jupiter.api.Assertions.*;
44
import static org.junit.jupiter.api.Assumptions.assumeTrue;
55

6+
import java.util.Map;
67
import org.junit.jupiter.api.Test;
78

89
class SystemPropertiesTest {
@@ -63,4 +64,15 @@ void testClear() {
6364
assertDoesNotThrow(() -> SystemProperties.clear(null));
6465
assertNull(SystemProperties.clear(null));
6566
}
67+
68+
@Test
69+
void testAsStringMap() {
70+
Map<String, String> stringMap = SystemProperties.asStringMap();
71+
assertNotNull(stringMap);
72+
assertFalse(stringMap.isEmpty());
73+
// Unmodifiable collection
74+
assertThrows(
75+
UnsupportedOperationException.class,
76+
() -> stringMap.put(MISSING_SYSTEM_PROPERTY, DEFAULT_VALUE));
77+
}
6678
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@
99
import datadog.trace.bootstrap.instrumentation.api.AgentPropagation;
1010
import datadog.trace.bootstrap.instrumentation.api.AgentSpanContext;
1111
import java.net.InetSocketAddress;
12-
import java.util.Properties;
12+
import java.util.Map;
1313
import javax.annotation.Nullable;
1414

1515
public class ProcessHierarchy {
1616

1717
private static final class SystemPropertiesPropagationGetter
18-
implements AgentPropagation.ContextVisitor<Properties> {
19-
static final AgentPropagation.ContextVisitor<Properties> INSTANCE =
18+
implements AgentPropagation.ContextVisitor<Map<String, String>> {
19+
static final AgentPropagation.ContextVisitor<Map<String, String>> INSTANCE =
2020
new SystemPropertiesPropagationGetter();
2121

2222
private SystemPropertiesPropagationGetter() {}
2323

2424
@Override
25-
public void forEachKey(Properties carrier, AgentPropagation.KeyClassifier classifier) {
26-
for (String propertyName : carrier.stringPropertyNames()) {
27-
if (!classifier.accept(propertyName, carrier.getProperty(propertyName))) {
25+
public void forEachKey(Map<String, String> carrier, AgentPropagation.KeyClassifier classifier) {
26+
for (Map.Entry<String, String> property : carrier.entrySet()) {
27+
if (!classifier.accept(property.getKey(), property.getValue())) {
2828
return;
2929
}
3030
}
@@ -36,7 +36,7 @@ public void forEachKey(Properties carrier, AgentPropagation.KeyClassifier classi
3636
ProcessHierarchy() {
3737
parentProcessModuleContext =
3838
extractContextAndGetSpanContext(
39-
System.getProperties(), SystemPropertiesPropagationGetter.INSTANCE);
39+
SystemProperties.asStringMap(), SystemPropertiesPropagationGetter.INSTANCE);
4040
}
4141

4242
/**

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package datadog.trace.civisibility.ci.env;
22

3-
import java.util.Collections;
3+
import datadog.environment.EnvironmentVariables;
44
import java.util.Map;
55

66
public class CiEnvironmentImpl implements CiEnvironment {
@@ -12,13 +12,7 @@ public CiEnvironmentImpl(Map<String, String> env) {
1212
}
1313

1414
public static CiEnvironment local() {
15-
Map<String, String> env;
16-
try {
17-
env = System.getenv();
18-
} catch (SecurityException e) {
19-
env = Collections.emptyMap();
20-
}
21-
return new CiEnvironmentImpl(env);
15+
return new CiEnvironmentImpl(EnvironmentVariables.getAll());
2216
}
2317

2418
@Override

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/buildsystem/BuildSystemModuleImpl.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import datadog.communication.ddagent.TracerVersion;
66
import datadog.context.propagation.CarrierSetter;
7+
import datadog.environment.SystemProperties;
78
import datadog.trace.api.Config;
89
import datadog.trace.api.DDTags;
910
import datadog.trace.api.civisibility.domain.BuildModuleLayout;
@@ -37,7 +38,6 @@
3738
import java.util.HashMap;
3839
import java.util.List;
3940
import java.util.Map;
40-
import java.util.Properties;
4141
import java.util.concurrent.atomic.LongAdder;
4242
import java.util.function.Consumer;
4343
import javax.annotation.Nullable;
@@ -137,18 +137,14 @@ private Map<String, String> getPropertiesPropagatedToChildProcess(
137137
ExecutionSettings executionSettings,
138138
BuildSessionSettings sessionSettings) {
139139
Map<String, String> propagatedSystemProperties = new HashMap<>();
140-
try {
141-
Properties systemProperties = System.getProperties();
142-
for (Map.Entry<Object, Object> e : systemProperties.entrySet()) {
143-
String propertyName = (String) e.getKey();
144-
Object propertyValue = e.getValue();
145-
if ((propertyName.startsWith(Config.PREFIX)
146-
|| propertyName.startsWith("datadog.slf4j.simpleLogger.defaultLogLevel"))
147-
&& propertyValue != null) {
148-
propagatedSystemProperties.put(propertyName, propertyValue.toString());
149-
}
140+
for (Map.Entry<String, String> p : SystemProperties.asStringMap().entrySet()) {
141+
String propertyName = p.getKey();
142+
String propertyValue = p.getValue();
143+
if ((propertyName.startsWith(Config.PREFIX)
144+
|| propertyName.startsWith("datadog.slf4j.simpleLogger.defaultLogLevel"))
145+
&& propertyValue != null) {
146+
propagatedSystemProperties.put(propertyName, propertyValue);
150147
}
151-
} catch (SecurityException ignored) {
152148
}
153149

154150
propagatedSystemProperties.put(

dd-java-agent/instrumentation/gradle-8.3/src/main/groovy/datadog/trace/instrumentation/gradle/GradleDaemonInjectionUtils.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.nio.file.Path;
1010
import java.util.HashMap;
1111
import java.util.Map;
12-
import java.util.Properties;
1312

1413
public class GradleDaemonInjectionUtils {
1514

@@ -28,20 +27,16 @@ public static Map<String, String> addJavaagentToGradleDaemonProperties(
2827
Path agentJarPath = agentJar.toPath();
2928
StringBuilder agentArg = new StringBuilder("-javaagent:").append(agentJarPath).append('=');
3029

31-
try {
32-
Properties systemProperties = System.getProperties();
33-
for (Map.Entry<Object, Object> e : systemProperties.entrySet()) {
34-
String propertyName = (String) e.getKey();
35-
Object propertyValue = e.getValue();
36-
if (propertyName.startsWith(Config.PREFIX)) {
37-
agentArg
38-
.append(propertyName)
39-
.append("='")
40-
.append(String.valueOf(propertyValue).replace("'", "'\\''"))
41-
.append("',");
42-
}
30+
for (Map.Entry<String, String> p : SystemProperties.asStringMap().entrySet()) {
31+
String propertyName = p.getKey();
32+
String propertyValue = p.getValue();
33+
if (propertyName.startsWith(Config.PREFIX)) {
34+
agentArg
35+
.append(propertyName)
36+
.append("='")
37+
.append(propertyValue.replace("'", "'\\''"))
38+
.append("',");
4339
}
44-
} catch (SecurityException ignored) {
4540
}
4641

4742
// creating a new map in case jvmOptions is immutable

0 commit comments

Comments
 (0)