Skip to content

fix(monitor): classify telemetry endpoints by hostname - #5240

Open
singh4jitendra wants to merge 1 commit into
GoogleCloudPlatform:masterfrom
singh4jitendra:fix/otel-endpoint-hostnames
Open

singh4jitendra wants to merge 1 commit into
GoogleCloudPlatform:masterfrom
singh4jitendra:fix/otel-endpoint-hostnames

Conversation

@singh4jitendra

Copy link
Copy Markdown
Contributor

Description

The telemetry exporters were using substring checks to decide whether an endpoint is Google-hosted or local. That can misclassify names such as googleapis.com.collector.example and localhost.collector.example.

This checks the actual hostname instead. Metrics and logging share the same rules, with tests for look-alike domains, regular collectors, and IPv4/IPv6 loopback addresses.

Link to the issue in case of a bug fix.

Fixes #5237

Testing details

Go 1.27.2, Ubuntu 24.04 under WSL.

  1. Manual -
    • make build - passed, including vet, lint (0 issues), formatting and compilation.
  2. Unit tests -
    • go test -p 1 ./internal/monitor -run '^TestOtelEndpoint(HostnameRules|Authentication)$' -count=1 -json - 21 subcases failed as expected before the fix.
    • go test -mod=readonly -p 1 -count=1 -race -timeout=3m ./internal/monitor - passed after formatting.
    • go test -mod=readonly -p 1 -count=1 -timeout=90s -run '^TestValidateMetrics$' ./cfg - passed.
    • Final endpoint tests use local servers or captured transports and dummy tokens, without real credentials.
  3. Integration tests - Not run against a cloud collector or GCS.

Any backward incompatible change? If so, please explain.

Look-alike remote hostnames no longer receive Google authentication or get treated as local plaintext collectors. Normal Google endpoints, local collectors, the existing IPv4 wildcard behavior, and explicit OTEL transport overrides remain supported. Malformed endpoints return setup errors through the existing exporter error-reporting paths; they do not make mounting fatal.

Use shared hostname rules for Google authentication and local collector transport instead of substring checks. Cover deceptive names, loopback addresses, invalid inputs and exporter authentication using local or captured transports.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces robust validation and classification for experimental OpenTelemetry metrics and logging endpoints, replacing basic string matching with structured parsing using net/netip and net/url. It also adds comprehensive unit tests and documentation detailing endpoint authentication and plaintext rules. A review comment correctly identifies that ip.IsLoopback() does not catch IPv4-mapped IPv6 loopback addresses and suggests using ip.Unmap().IsLoopback() to resolve this.

Comment thread internal/monitor/otelexporters.go Resolved
@singh4jitendra
singh4jitendra marked this pull request as ready for review November 12, 2026 17:28
@singh4jitendra
singh4jitendra requested a review from a team as a code owner November 12, 2026 17:28
@singh4jitendra

Copy link
Copy Markdown
Contributor Author

Hi @geertj, could you take a look at the telemetry hostname change when you have a moment? Happy to walk through the approach if helpful. Thanks!

@singh4jitendra

Copy link
Copy Markdown
Contributor Author

Hi @geertj, could you take a look when you have a moment and merge if everything checks out? Thanks!

@singh4jitendra

Copy link
Copy Markdown
Contributor Author

Hi @geertj, just checking in on the telemetry hostname fix. Could you review it when you have some time and merge if all looks good? Thanks!

@singh4jitendra

Copy link
Copy Markdown
Contributor Author

Hi @geertj, could you take a look at the telemetry hostname fix when you have a chance? If everything checks out, I'd appreciate your help getting it merged. Thanks!

@singh4jitendra

Copy link
Copy Markdown
Contributor Author

Hi @geertj, could you take a look at the telemetry hostname fix when you have a moment? Thanks!

@vipnydav

Copy link
Copy Markdown
Member

Hi @alleaditya, PR #5240 replaces strings.Contains on OTel endpoints with proper hostname matching for GCP auth and local HTTP. Looks good to me (just needs a quick rebase for the /v4/ import). PTAL!

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

Labels

None yet

2 participants