fix(metrics/otel): bracket IPv6 host literals in exporter endpoint URL#66813
Merged
Conversation
get_otel_data_exporter() builds the OTLP exporter endpoint as a raw f-string. When host is an IPv6 literal (e.g. ::1, 2001:db8::1) the resulting URL is invalid per RFC 3986 section 3.2.2 — the v6 host needs to be enclosed in [...] so the colon separators don't conflict with the host:port delimiter. Add _format_url_host() that brackets bare v6 literals and leaves hostnames, IPv4 literals, and already-bracketed v6 strings unchanged. Closes apache#66811 Signed-off-by: 1fanwang <1fannnw@gmail.com>
potiuk
approved these changes
May 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
get_otel_data_exporter()builds the OTLP exporter endpoint URL with a raw f-string:When
hostis an IPv6 literal (e.g.::1,2001:db8::1), the resulting URL is invalid per RFC 3986 §3.2.2 — the v6 host has to be enclosed in[...]so the:separators don't conflict with thehost:portdelimiter:The OTLP exporter then either fails to parse the URL or interprets the trailing port digits as part of the v6 address.
Fix
Add a small
_format_url_host()helper inshared/observability/.../common.pythat brackets bare IPv6 literals and leaves hostnames, IPv4 literals, and already-bracketed v6 strings unchanged. The helper acceptsstr | Noneso the existing error-logging path (where the deprecated airflow host/port config can resolve toNone) keeps its shape.Tests
Extended
test_config_prioritieswith four new parametrised cases:::1→http://[::1]:4318/v1/metrics2001:db8::1→http://[2001:db8::1]:4318/v1/metrics[::1](already bracketed) → preserved10.0.0.1(v4) → passes through unchangedCloses #66811