Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support IPv6 values for DD_AGENT_HOST and DD_TRACE_AGENT_URL #7984

Merged
merged 5 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import datadog.trace.test.util.DDSpecification
import okhttp3.HttpUrl
import okhttp3.OkHttpClient

import static datadog.trace.api.config.TracerConfig.AGENT_HOST

class SharedCommunicationsObjectsSpecification extends DDSpecification {
SharedCommunicationObjects sco = new SharedCommunicationObjects()

Expand Down Expand Up @@ -90,4 +92,36 @@ class SharedCommunicationsObjectsSpecification extends DDSpecification {
sco.monitoring.is(monitoring)
sco.featuresDiscovery.is(agentFeaturesDiscovery)
}

void 'supports ipv6 agent host w/o brackets'() {
given:
injectSysConfig(AGENT_HOST, "2600:1f18:19c0:bd07:d55b::17")
Config config = Mock()

when:
sco.createRemaining(config)

then:
1 * config.getAgentUrl() >> 'http://[2600:1f18:19c0:bd07:d55b::17]:8126'
1 * config.agentNamedPipe >> null
1 * config.agentTimeout >> 1
1 * config.agentUnixDomainSocket >> null
sco.agentUrl as String == 'http://[2600:1f18:19c0:bd07:d55b::17]:8126/'
}

void 'supports ipv6 agent host w/ brackets'() {
given:
injectSysConfig(AGENT_HOST, "[2600:1f18:19c0:bd07:d55b::17]")
Config config = Mock()

when:
sco.createRemaining(config)

then:
1 * config.getAgentUrl() >> 'http://[2600:1f18:19c0:bd07:d55b::17]:8126'
1 * config.agentNamedPipe >> null
1 * config.agentTimeout >> 1
1 * config.agentUnixDomainSocket >> null
sco.agentUrl as String == 'http://[2600:1f18:19c0:bd07:d55b::17]:8126/'
}
}
60 changes: 28 additions & 32 deletions internal-api/src/main/java/datadog/trace/api/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,8 @@ private Config(final ConfigProvider configProvider, final InstrumenterConfig ins

if (agentHostFromEnvironment == null) {
agentHost = DEFAULT_AGENT_HOST;
} else if (agentHostFromEnvironment.charAt(0) == '[') {
agentHost = agentHostFromEnvironment.substring(1, agentHostFromEnvironment.length() - 1);
} else {
agentHost = agentHostFromEnvironment;
}
Expand All @@ -704,8 +706,12 @@ private Config(final ConfigProvider configProvider, final InstrumenterConfig ins
agentPort = agentPortFromEnvironment;
}

if (rebuildAgentUrl) {
agentUrl = "http://" + agentHost + ":" + agentPort;
if (rebuildAgentUrl) { // check if agenthost contains ':'
if (agentHost.indexOf(':') != -1) { // Checking to see whether host address is IPv6 vs IPv4
agentUrl = "http://[" + agentHost + "]:" + agentPort;
} else {
agentUrl = "http://" + agentHost + ":" + agentPort;
}
} else {
agentUrl = agentUrlFromEnvironment;
}
Expand Down Expand Up @@ -1229,8 +1235,7 @@ PROFILING_DATADOG_PROFILER_ENABLED, isDatadogProfilerSafeInCurrentEnvironment())
}
telemetryMetricsInterval = telemetryInterval;

telemetryMetricsEnabled =
configProvider.getBoolean(GeneralConfig.TELEMETRY_METRICS_ENABLED, true);
telemetryMetricsEnabled = configProvider.getBoolean(TELEMETRY_METRICS_ENABLED, true);

isTelemetryLogCollectionEnabled =
instrumenterConfig.isTelemetryEnabled()
Expand Down Expand Up @@ -1724,17 +1729,14 @@ PROFILING_DATADOG_PROFILER_ENABLED, isDatadogProfilerSafeInCurrentEnvironment())
apiKey = tmpApiKey;

boolean longRunningEnabled =
configProvider.getBoolean(
TracerConfig.TRACE_LONG_RUNNING_ENABLED,
ConfigDefaults.DEFAULT_TRACE_LONG_RUNNING_ENABLED);
configProvider.getBoolean(TRACE_LONG_RUNNING_ENABLED, DEFAULT_TRACE_LONG_RUNNING_ENABLED);
long longRunningTraceInitialFlushInterval =
configProvider.getLong(
TracerConfig.TRACE_LONG_RUNNING_INITIAL_FLUSH_INTERVAL,
TRACE_LONG_RUNNING_INITIAL_FLUSH_INTERVAL,
DEFAULT_TRACE_LONG_RUNNING_INITIAL_FLUSH_INTERVAL);
long longRunningTraceFlushInterval =
configProvider.getLong(
TracerConfig.TRACE_LONG_RUNNING_FLUSH_INTERVAL,
ConfigDefaults.DEFAULT_TRACE_LONG_RUNNING_FLUSH_INTERVAL);
TRACE_LONG_RUNNING_FLUSH_INTERVAL, DEFAULT_TRACE_LONG_RUNNING_FLUSH_INTERVAL);

if (longRunningEnabled
&& (longRunningTraceInitialFlushInterval < 10
Expand All @@ -1761,16 +1763,14 @@ PROFILING_DATADOG_PROFILER_ENABLED, isDatadogProfilerSafeInCurrentEnvironment())

this.sparkTaskHistogramEnabled =
configProvider.getBoolean(
SPARK_TASK_HISTOGRAM_ENABLED, ConfigDefaults.DEFAULT_SPARK_TASK_HISTOGRAM_ENABLED);
SPARK_TASK_HISTOGRAM_ENABLED, DEFAULT_SPARK_TASK_HISTOGRAM_ENABLED);

this.sparkAppNameAsService =
configProvider.getBoolean(
SPARK_APP_NAME_AS_SERVICE, ConfigDefaults.DEFAULT_SPARK_APP_NAME_AS_SERVICE);
configProvider.getBoolean(SPARK_APP_NAME_AS_SERVICE, DEFAULT_SPARK_APP_NAME_AS_SERVICE);

this.jaxRsExceptionAsErrorsEnabled =
configProvider.getBoolean(
JAX_RS_EXCEPTION_AS_ERROR_ENABLED,
ConfigDefaults.DEFAULT_JAX_RS_EXCEPTION_AS_ERROR_ENABLED);
JAX_RS_EXCEPTION_AS_ERROR_ENABLED, DEFAULT_JAX_RS_EXCEPTION_AS_ERROR_ENABLED);

axisPromoteResourceName = configProvider.getBoolean(AXIS_PROMOTE_RESOURCE_NAME, false);

Expand All @@ -1780,7 +1780,7 @@ PROFILING_DATADOG_PROFILER_ENABLED, isDatadogProfilerSafeInCurrentEnvironment())

this.tracePostProcessingTimeout =
configProvider.getLong(
TRACE_POST_PROCESSING_TIMEOUT, ConfigDefaults.DEFAULT_TRACE_POST_PROCESSING_TIMEOUT);
TRACE_POST_PROCESSING_TIMEOUT, DEFAULT_TRACE_POST_PROCESSING_TIMEOUT);

if (isLlmObsEnabled()) {
log.debug("Attempting to enable LLM Observability");
Expand Down Expand Up @@ -1821,31 +1821,28 @@ PROFILING_DATADOG_PROFILER_ENABLED, isDatadogProfilerSafeInCurrentEnvironment())

this.telemetryDebugRequestsEnabled =
configProvider.getBoolean(
GeneralConfig.TELEMETRY_DEBUG_REQUESTS_ENABLED,
ConfigDefaults.DEFAULT_TELEMETRY_DEBUG_REQUESTS_ENABLED);
TELEMETRY_DEBUG_REQUESTS_ENABLED, DEFAULT_TELEMETRY_DEBUG_REQUESTS_ENABLED);

this.agentlessLogSubmissionEnabled =
configProvider.getBoolean(GeneralConfig.AGENTLESS_LOG_SUBMISSION_ENABLED, false);
configProvider.getBoolean(AGENTLESS_LOG_SUBMISSION_ENABLED, false);
this.agentlessLogSubmissionQueueSize =
configProvider.getInteger(GeneralConfig.AGENTLESS_LOG_SUBMISSION_QUEUE_SIZE, 1024);
configProvider.getInteger(AGENTLESS_LOG_SUBMISSION_QUEUE_SIZE, 1024);
this.agentlessLogSubmissionLevel =
configProvider.getString(GeneralConfig.AGENTLESS_LOG_SUBMISSION_LEVEL, "INFO");
this.agentlessLogSubmissionUrl =
configProvider.getString(GeneralConfig.AGENTLESS_LOG_SUBMISSION_URL);
configProvider.getString(AGENTLESS_LOG_SUBMISSION_LEVEL, "INFO");
this.agentlessLogSubmissionUrl = configProvider.getString(AGENTLESS_LOG_SUBMISSION_URL);
this.agentlessLogSubmissionProduct = isCiVisibilityEnabled() ? "citest" : "apm";

this.cloudPayloadTaggingServices =
configProvider.getSet(
TracerConfig.TRACE_CLOUD_PAYLOAD_TAGGING_SERVICES,
ConfigDefaults.DEFAULT_TRACE_CLOUD_PAYLOAD_TAGGING_SERVICES);
TRACE_CLOUD_PAYLOAD_TAGGING_SERVICES, DEFAULT_TRACE_CLOUD_PAYLOAD_TAGGING_SERVICES);
this.cloudRequestPayloadTagging =
configProvider.getList(TracerConfig.TRACE_CLOUD_REQUEST_PAYLOAD_TAGGING, null);
configProvider.getList(TRACE_CLOUD_REQUEST_PAYLOAD_TAGGING, null);
this.cloudResponsePayloadTagging =
configProvider.getList(TracerConfig.TRACE_CLOUD_RESPONSE_PAYLOAD_TAGGING, null);
configProvider.getList(TRACE_CLOUD_RESPONSE_PAYLOAD_TAGGING, null);
this.cloudPayloadTaggingMaxDepth =
configProvider.getInteger(TracerConfig.TRACE_CLOUD_PAYLOAD_TAGGING_MAX_DEPTH, 10);
configProvider.getInteger(TRACE_CLOUD_PAYLOAD_TAGGING_MAX_DEPTH, 10);
this.cloudPayloadTaggingMaxTags =
configProvider.getInteger(TracerConfig.TRACE_CLOUD_PAYLOAD_TAGGING_MAX_TAGS, 758);
configProvider.getInteger(TRACE_CLOUD_PAYLOAD_TAGGING_MAX_TAGS, 758);

this.dependecyResolutionPeriodMillis =
configProvider.getLong(
Expand All @@ -1854,8 +1851,7 @@ PROFILING_DATADOG_PROFILER_ENABLED, isDatadogProfilerSafeInCurrentEnvironment())

timelineEventsEnabled =
configProvider.getBoolean(
ProfilingConfig.PROFILING_TIMELINE_EVENTS_ENABLED,
ProfilingConfig.PROFILING_TIMELINE_EVENTS_ENABLED_DEFAULT);
PROFILING_TIMELINE_EVENTS_ENABLED, PROFILING_TIMELINE_EVENTS_ENABLED_DEFAULT);

if (appSecScaEnabled != null
&& appSecScaEnabled
Expand Down Expand Up @@ -3834,7 +3830,7 @@ public boolean isTraceAnalyticsIntegrationEnabled(
}

public boolean isSamplingMechanismValidationDisabled() {
return configProvider.getBoolean(TracerConfig.SAMPLING_MECHANISM_VALIDATION_DISABLED, false);
return configProvider.getBoolean(SAMPLING_MECHANISM_VALIDATION_DISABLED, false);
}

public <T extends Enum<T>> T getEnumValue(
Expand Down
Loading