Skip to content

Accept RFC 1123 hostnames in EndpointUtil.validateEndpoint - #8746

Open
kalayciburak wants to merge 1 commit into
open-telemetry:mainfrom
kalayciburak:fix/endpoint-rfc1123-host
Open

Accept RFC 1123 hostnames in EndpointUtil.validateEndpoint#8746
kalayciburak wants to merge 1 commit into
open-telemetry:mainfrom
kalayciburak:fix/endpoint-rfc1123-host

Conversation

@kalayciburak

@kalayciburak kalayciburak commented Aug 25, 2026

Copy link
Copy Markdown

Description

EndpointUtil.validateEndpoint rejects hostnames that java.net.URI#getHost() cannot parse even when they are valid DNS names. That is JDK-8188305: RFC 2396 host parsing returns null for labels that start with a digit, which is common for Kubernetes namespaces such as otlp.1234-k8s-namespace.

The existing uri.getHost() == null check was added in #8489 to reject truly host-less URIs (http:localhost:4317, https:/foo). That check is still needed, but it is too strict when getHost() is null and a host is present.

This falls back to URL.getHost(), the same parser used by OtlpConfigUtil.validateEndpoint. Host-less URIs still fail; RFC 1123 names that URI.getHost() misses are accepted.

This unblocks the default OkHttp sender (OkHttpHttpSender re-parses via HttpUrl.get). It does not make JdkHttpSender or UpstreamGrpcSenderProvider work: those still call URI.getHost() / URI.getPort(), which stay null / -1 for these names. There is no standard way to build a java.net.URI whose getHost() returns an RFC 1123 hostname the JDK parser rejects.

Related to #8745. Leaving that issue open to track the JDK HTTP and managed-channel gRPC senders.

Testing done

  • ./gradlew :exporters:common:test --tests io.opentelemetry.exporter.internal.EndpointUtilTest - 12 tests, 0 failed
    • RED: the three new RFC 1123 cases failed on URI.getHost() == null before the change
    • GREEN: all 12 pass after the fallback
  • ./gradlew :exporters:common:check - passed (tests, checkstyle, spotless, japicmp, animalsniffer)

URI.getHost() returns null for some valid DNS names (JDK-8188305),
such as a label that starts with a digit. Fall back to URL.getHost()
so those endpoints are accepted, matching OtlpConfigUtil.

Fixes open-telemetry#8745

Signed-off-by: Burak KALAYCI <kalayciburak1996@gmail.com>
@kalayciburak
kalayciburak requested a review from a team as a code owner August 25, 2026 11:49
@linux-foundation-easycla

linux-foundation-easycla Bot commented Aug 25, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: kalayciburak / name: Burak KALAYCI (69f1520)

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Aug 25, 2026

Copy link
Copy Markdown

Pull request dashboard status

Waiting on the author · refreshed 2026-09-08 22:52 UTC

Respond to 1 review item (e.g. link a commit, explain why not, ask a follow-up):

  • Inline threads: 1
Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Should this be with reviewers? Comment /dashboard route:reviewers to route it to them.
  • Anything wrong — including the routing? Report it with what you expected; it helps us improve the dashboard.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 69f1520108

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

"Invalid endpoint, must start with http:// or https://: " + uri);
}
if (uri.getHost() == null) {
if (!hasHost(uri, endpoint)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve a usable host for accepted endpoints

When this fallback is taken, including for the three new test cases, the method still returns the original URI, whose getHost() is null and whose getPort() is -1. Supported consumers cannot use that representation: JdkHttpSender.java:198 passes it to HttpRequest.Builder.uri, which throws IllegalArgumentException: unsupported URI, while UpstreamGrpcSenderProvider.java:71 passes the null host and invalid port to ManagedChannelBuilder.forAddress. Consequently, these newly accepted endpoints still fail whenever the JDK HTTP or managed-channel gRPC sender is selected; the parsed host and port must be preserved or those consumers must use a parser that supports these names.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified, with nuance.

For "http://otlp.1234-k8s-namespace:4318", URI.getHost() returns null and URI.getPort() returns -1 (the authority is unparsed, so port information is also lost).

The default OkHttp sender is fine. OkHttpHttpSender constructs its request URL via HttpUrl.get(endpoint), which re-parses from uri.toString() using OkHttp's own URL parser. That parser handles RFC 1123 hostnames correctly and never calls uri.getHost(). Fixing validateEndpoint to accept these URIs is sufficient for the common case.

The JDK sender fails at runtime. JdkHttpSender passes the URI directly to HttpRequest.newBuilder().uri(endpoint), which internally calls uri.getHost() and throws:

java.lang.IllegalArgumentException: unsupported URI http://otlp.1234-k8s-namespace:4318

Similarly, UpstreamGrpcSenderProvider calls endpoint.getHost() and endpoint.getPort() directly, passing null and -1 to ManagedChannelBuilder.forAddress.

Fixing JdkHttpSender and UpstreamGrpcSenderProvider for these hostnames is non-trivial: there is no standard way to construct a java.net.URI whose getHost() returns an RFC 1123 hostname that the JDK parser rejects (URI is final and all its constructors run the same RFC 2396 validation). That is a separate problem from what this PR addresses. This PR is sufficient to unblock users of the default OkHttp sender.

@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 57.14286% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.28%. Comparing base (e2efec5) to head (69f1520).
⚠️ Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
.../opentelemetry/exporter/internal/EndpointUtil.java 57.14% 2 Missing and 1 partial ⚠️

❌ Your patch check has failed because the patch coverage (57.14%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8746      +/-   ##
============================================
- Coverage     91.29%   91.28%   -0.01%     
- Complexity    10498    10501       +3     
============================================
  Files          1006     1006              
  Lines         28338    28344       +6     
  Branches       3581     3582       +1     
============================================
+ Hits          25870    25873       +3     
- Misses         1675     1677       +2     
- Partials        793      794       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@opentelemetry-pr-dashboard

Copy link
Copy Markdown

Hi @kalayciburak — just a friendly reminder that this pull request is waiting on you. The dashboard status comment has the open items and is kept current.

  • Replying is enough to hand it off — answer, explain why no change is needed, or ask a follow-up. The dashboard routes it onward once nothing on the list is waiting on you.
  • To hand it back for any other reason, including the dashboard getting this wrong, comment /dashboard route:reviewers.

/**
* {@link URI#getHost()} follows RFC 2396 and returns {@code null} for some valid DNS names
* (JDK-8188305), for example a label that starts with a digit. {@link URL#getHost()} accepts
* those names, matching {@code OtlpConfigUtil.validateEndpoint}.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should amend this works for OkHttp sender but not for the others. For this reason, this does fix #8745. We'll want to amend the PR description accordingly, and keep that issue open for tracking.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated the PR body. OkHttp only, #8745 stays open for the JDK/gRPC cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants