Skip to content

fix(metrics/otel): bracket IPv6 host literals in exporter endpoint URL#66813

Merged
potiuk merged 1 commit into
apache:mainfrom
1fanwang:metrics-ipv6-otel-endpoint
May 12, 2026
Merged

fix(metrics/otel): bracket IPv6 host literals in exporter endpoint URL#66813
potiuk merged 1 commit into
apache:mainfrom
1fanwang:metrics-ipv6-otel-endpoint

Conversation

@1fanwang
Copy link
Copy Markdown
Contributor

Problem

get_otel_data_exporter() builds the OTLP exporter endpoint URL with a raw f-string:

endpoint_str = f"{protocol}://{host}:{port}/v1/{endpoint_suffix}"

When host is 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 the host:port delimiter:

http://::1:4318/v1/metrics              # invalid
http://2001:db8::1:4318/v1/metrics      # invalid

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 in shared/observability/.../common.py that brackets bare IPv6 literals and leaves hostnames, IPv4 literals, and already-bracketed v6 strings unchanged. The helper accepts str | None so the existing error-logging path (where the deprecated airflow host/port config can resolve to None) keeps its shape.

Tests

Extended test_config_priorities with four new parametrised cases:

  • ::1http://[::1]:4318/v1/metrics
  • 2001:db8::1http://[2001:db8::1]:4318/v1/metrics
  • [::1] (already bracketed) → preserved
  • 10.0.0.1 (v4) → passes through unchanged

Closes #66811

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 potiuk merged commit f8baa0a into apache:main May 12, 2026
78 checks passed
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.

OTel exporter endpoint URL doesn't bracket IPv6 host literals

2 participants