Skip to content

Commit 3de3d08

Browse files
authored
Merge branch 'master' into kr-igor/dsm-optimization-v2
2 parents 68373af + 887ea39 commit 3de3d08

File tree

30 files changed

+1074
-735
lines changed

30 files changed

+1074
-735
lines changed

.gitlab/one-pipeline.locked.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# DO NOT EDIT THIS FILE MANUALLY
22
# This file is auto-generated by automation.
33
include:
4-
- remote: https://gitlab-templates.ddbuild.io/libdatadog/one-pipeline/ca/d44e89797a5a47c43cf712193abefe2178a004176606f7e01b77d1ec49a3ef5e/one-pipeline.yml
4+
- remote: https://gitlab-templates.ddbuild.io/libdatadog/one-pipeline/ca/a0486057161f85a77e39ad2aa60ac66bb52414696d9b3dd87177df1057b11295/one-pipeline.yml

communication/build.gradle

Lines changed: 0 additions & 70 deletions
This file was deleted.

communication/build.gradle.kts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
plugins {
2+
`java-library`
3+
}
4+
5+
description = "communication"
6+
7+
apply(from = rootDir.resolve("gradle/java.gradle"))
8+
9+
dependencies {
10+
implementation(libs.slf4j)
11+
12+
api(project(":remote-config:remote-config-api"))
13+
implementation(project(":remote-config:remote-config-core"))
14+
implementation(project(":internal-api"))
15+
implementation(project(":utils:container-utils"))
16+
implementation(project(":utils:socket-utils"))
17+
implementation(project(":utils:version-utils"))
18+
19+
api(libs.okio)
20+
api(libs.okhttp)
21+
api(libs.moshi)
22+
implementation(libs.dogstatsd)
23+
24+
testImplementation(project(":utils:test-utils"))
25+
testImplementation(libs.bundles.junit5)
26+
testImplementation(libs.truth)
27+
testImplementation(libs.bytebuddy)
28+
testImplementation("org.msgpack:msgpack-core:0.8.20")
29+
testImplementation("org.msgpack:jackson-dataformat-msgpack:0.8.20")
30+
testImplementation(
31+
group = "com.squareup.okhttp3",
32+
name = "mockwebserver",
33+
version = libs.versions.okhttp.legacy.get() // actually a version range
34+
)
35+
}
36+
37+
val minimumBranchCoverage by extra(0.5)
38+
val minimumInstructionCoverage by extra(0.8)
39+
val excludedClassesCoverage by extra(
40+
listOf(
41+
"datadog.communication.ddagent.ExternalAgentLauncher",
42+
"datadog.communication.ddagent.ExternalAgentLauncher.NamedPipeHealthCheck",
43+
"datadog.communication.ddagent.SharedCommunicationObjects.FixedConfigUrlSupplier",
44+
"datadog.communication.ddagent.SharedCommunicationObjects.RetryConfigUrlSupplier",
45+
"datadog.communication.http.OkHttpUtils",
46+
"datadog.communication.http.OkHttpUtils.1",
47+
"datadog.communication.http.OkHttpUtils.ByteBufferRequestBody",
48+
"datadog.communication.http.OkHttpUtils.CustomListener",
49+
"datadog.communication.http.OkHttpUtils.GZipByteBufferRequestBody",
50+
"datadog.communication.http.OkHttpUtils.GZipRequestBodyDecorator",
51+
"datadog.communication.http.OkHttpUtils.JsonRequestBody",
52+
"datadog.communication.monitor.DDAgentStatsDConnection",
53+
"datadog.communication.monitor.DDAgentStatsDConnection.*",
54+
"datadog.communication.monitor.LoggingStatsDClient",
55+
"datadog.communication.BackendApiFactory",
56+
"datadog.communication.BackendApiFactory.Intake",
57+
"datadog.communication.EvpProxyApi",
58+
"datadog.communication.IntakeApi",
59+
"datadog.communication.util.IOUtils",
60+
"datadog.communication.util.IOUtils.1",
61+
)
62+
)
63+
val excludedClassesBranchCoverage by extra(
64+
listOf(
65+
"datadog.communication.ddagent.TracerVersion",
66+
"datadog.communication.BackendApiFactory",
67+
"datadog.communication.EvpProxyApi",
68+
"datadog.communication.IntakeApi",
69+
)
70+
)
71+
val excludedClassesInstructionCoverage by extra(
72+
listOf(
73+
// can't reach the error condition now
74+
"datadog.communication.fleet.FleetServiceImpl",
75+
"datadog.communication.ddagent.SharedCommunicationObjects",
76+
"datadog.communication.ddagent.TracerVersion",
77+
"datadog.communication.BackendApiFactory",
78+
"datadog.communication.BackendApiFactory.Intake",
79+
"datadog.communication.EvpProxyApi",
80+
"datadog.communication.IntakeApi",
81+
"datadog.communication.util.IOUtils",
82+
"datadog.communication.util.IOUtils.1",
83+
)
84+
)

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ private EnvironmentVariables() {}
1616
* Gets an environment variable value.
1717
*
1818
* @param name The environment variable name.
19-
* @return The environment variable value, {@code null} if missing or can't be retrieved.
19+
* @return The environment variable value, {@code null} if missing, can't be retrieved, or the
20+
* environment variable name is {@code null}.
2021
*/
2122
public static @Nullable String get(String name) {
2223
return getOrDefault(name, null);
@@ -28,9 +29,13 @@ private EnvironmentVariables() {}
2829
* @param name The environment variable name.
2930
* @param defaultValue The default value to return if the environment variable is missing or can't
3031
* be retrieved.
31-
* @return The environment variable value, {@code defaultValue} if missing or can't be retrieved.
32+
* @return The environment variable value, {@code defaultValue} if missing, can't be retrieved or
33+
* the environment variable name is {@code null}.
3234
*/
3335
public static String getOrDefault(@Nonnull String name, String defaultValue) {
36+
if (name == null) {
37+
return defaultValue;
38+
}
3439
try {
3540
String value = System.getenv(name);
3641
return value == null ? defaultValue : value;

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

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

3+
import javax.annotation.Nonnull;
4+
35
/**
46
* Safely queries system properties against security manager.
57
*
@@ -13,7 +15,8 @@ private SystemProperties() {}
1315
* Gets a system property value.
1416
*
1517
* @param property The system property name.
16-
* @return The system property value, {@code null} if missing or can't be retrieved.
18+
* @return The system property value, {@code null} if missing, can't be retrieved, or the system
19+
* property name is {@code null}.
1720
*/
1821
public static String get(String property) {
1922
return getOrDefault(property, null);
@@ -25,9 +28,13 @@ public static String get(String property) {
2528
* @param property The system property name.
2629
* @param defaultValue The default value to return if the system property is missing or can't be
2730
* retrieved.
28-
* @return The system property value, {@code defaultValue} if missing or can't be retrieved.
31+
* @return The system property value, {@code defaultValue} if missing, can't be retrieved, or the
32+
* system property name is {@code null}.
2933
*/
30-
public static String getOrDefault(String property, String defaultValue) {
34+
public static String getOrDefault(@Nonnull String property, String defaultValue) {
35+
if (property == null) {
36+
return defaultValue;
37+
}
3138
try {
3239
return System.getProperty(property, defaultValue);
3340
} catch (SecurityException ignored) {
Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,39 @@
11
package datadog.environment;
22

3-
import static org.junit.jupiter.api.Assertions.*;
3+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
4+
import static org.junit.jupiter.api.Assertions.assertEquals;
5+
import static org.junit.jupiter.api.Assertions.assertNotNull;
6+
import static org.junit.jupiter.api.Assertions.assertNull;
47

58
import org.junit.jupiter.api.Test;
69

710
class EnvironmentVariablesTest {
811
private static final String EXISTING_ENV_VAR = "JAVA_8_HOME";
912
private static final String MISSING_ENV_VAR = "UNDEFINED_ENV_VAR";
13+
private static final String DEFAULT_VALUE = "DEFAULT";
1014

1115
@Test
1216
void testGet() {
17+
// Existing environment variable
1318
assertNotNull(EnvironmentVariables.get(EXISTING_ENV_VAR));
19+
// Missing environment variable
1420
assertNull(EnvironmentVariables.get(MISSING_ENV_VAR));
15-
assertThrows(NullPointerException.class, () -> EnvironmentVariables.get(null));
21+
// Null values
22+
assertDoesNotThrow(() -> EnvironmentVariables.get(null));
23+
assertNull(EnvironmentVariables.get(null));
1624
}
1725

1826
@Test
1927
void testGetOrDefault() {
28+
// Existing environment variable
2029
assertNotNull(EnvironmentVariables.getOrDefault(EXISTING_ENV_VAR, null));
21-
22-
assertEquals("", EnvironmentVariables.getOrDefault(MISSING_ENV_VAR, ""));
30+
// Missing environment variable
31+
assertEquals(DEFAULT_VALUE, EnvironmentVariables.getOrDefault(MISSING_ENV_VAR, DEFAULT_VALUE));
32+
assertNull(EnvironmentVariables.getOrDefault(MISSING_ENV_VAR, null));
33+
// Null values
34+
assertDoesNotThrow(() -> EnvironmentVariables.getOrDefault(null, DEFAULT_VALUE));
35+
assertEquals(DEFAULT_VALUE, EnvironmentVariables.getOrDefault(null, DEFAULT_VALUE));
36+
assertDoesNotThrow(() -> EnvironmentVariables.getOrDefault(MISSING_ENV_VAR, null));
2337
assertNull(EnvironmentVariables.getOrDefault(MISSING_ENV_VAR, null));
24-
25-
assertThrows(NullPointerException.class, () -> EnvironmentVariables.getOrDefault(null, ""));
2638
}
2739
}

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,32 @@
88
class SystemPropertiesTest {
99
private static final String EXISTING_SYSTEM_PROPERTY = "java.home";
1010
private static final String MISSING_SYSTEM_PROPERTY = "undefined.system.property";
11+
private static final String DEFAULT_VALUE = "DEFAULT";
1112

1213
@Test
1314
void testGet() {
15+
// Existing system properties
1416
assertNotNull(SystemProperties.get(EXISTING_SYSTEM_PROPERTY));
17+
// Missing system properties
1518
assertNull(SystemProperties.get(MISSING_SYSTEM_PROPERTY));
16-
assertThrows(NullPointerException.class, () -> SystemProperties.get(null));
19+
// Null values
20+
assertDoesNotThrow(() -> SystemProperties.get(null));
21+
assertNull(SystemProperties.get(null));
1722
}
1823

1924
@Test
2025
void testGetOrDefault() {
26+
// Existing system properties
2127
assertNotNull(SystemProperties.getOrDefault(EXISTING_SYSTEM_PROPERTY, null));
22-
23-
assertEquals("", SystemProperties.getOrDefault(MISSING_SYSTEM_PROPERTY, ""));
28+
// Missing system properties
29+
assertEquals(
30+
DEFAULT_VALUE, SystemProperties.getOrDefault(MISSING_SYSTEM_PROPERTY, DEFAULT_VALUE));
31+
assertNull(SystemProperties.getOrDefault(MISSING_SYSTEM_PROPERTY, null));
32+
// Null values
33+
assertDoesNotThrow(() -> SystemProperties.getOrDefault(null, DEFAULT_VALUE));
34+
assertEquals(DEFAULT_VALUE, SystemProperties.getOrDefault(null, DEFAULT_VALUE));
35+
assertDoesNotThrow(() -> SystemProperties.getOrDefault(MISSING_SYSTEM_PROPERTY, null));
2436
assertNull(SystemProperties.getOrDefault(MISSING_SYSTEM_PROPERTY, null));
25-
26-
assertThrows(NullPointerException.class, () -> SystemProperties.getOrDefault(null, ""));
2737
}
2838

2939
@Test

0 commit comments

Comments
 (0)