Skip to content

Fix autodiscovery over UNIX domain sockets - #1317

Open
Arusekk wants to merge 1 commit into
prometheus-community:masterfrom
Arusekk:unix-autodiscovery
Open

Fix autodiscovery over UNIX domain sockets#1317
Arusekk wants to merge 1 commit into
prometheus-community:masterfrom
Arusekk:unix-autodiscovery

Conversation

@Arusekk

@Arusekk Arusekk commented May 22, 2026

Copy link
Copy Markdown

Fixes #1316

Compiles fine, but not tested any further. I hope this is trivial enough to be safe.

@Arusekk
Arusekk force-pushed the unix-autodiscovery branch from 8a17104 to d6b2a58 Compare May 22, 2026 08:07
@sysadmind

Copy link
Copy Markdown
Contributor

Can you help me understand what this fixes and how? Based on my understanding, the existing .String call on the URI should properly serialize and URI information.

@Arusekk

Arusekk commented Jun 10, 2026

Copy link
Copy Markdown
Author

Sure. As I explained in the issue, is that URI is updated from postgres:///dbname?host=/run/postgresql (scheme postgres, empty host, path /dbname, query host=/run/postgresql) to have path otherdbname. Then, .String unparses the URL to postgresql://otherdbname?host=/run/postgresql&sslmode=disable (scheme postgres, host otherdbname, empty path, query host=/run/postgresql). The third slash is gone.

As a result, for each discovered otherdbname, postgres_exporter tries to resolve otherdbname via DNS and connect to it. Thankfully most database names do not resolve to any malicious servers.

The problem is not visible when using remote connections - only local ones are affected. For remote ones, this happens to work - by chance - because the URLs have a non-empty host.

Why the difference? I wonder, too. I tried reporting it to golang, as I believed this is a golang problem (after all, why should URL objects be so inconsistent), but they said that since no actual URL parses to this exact structure, the resulting .String return value is left undefined. They resort to correct guesses for a non-empty host, but prefer to guess wrong when the host is empty. See golang/go#5927 (comment) (maybe they can be convinced when presented with evidence of downstream impact, but my arguments alone proved insufficient).

Fixes prometheus-community#1316

Signed-off-by: Arusekk <floss@arusekk.pl>
@Arusekk
Arusekk force-pushed the unix-autodiscovery branch from d6b2a58 to 35788c7 Compare July 24, 2026 11:38
@n3ph

n3ph commented Jul 24, 2026

Copy link
Copy Markdown

Still looking forward for this. ATM auto-discovery through UNIX domain sockets with alloy is an architectural blocker.

@Arusekk Thank you for being on it 🙇🏼

@n3ph

n3ph commented Jul 24, 2026

Copy link
Copy Markdown

@ArthurSens

Copy link
Copy Markdown
Contributor

Hey, sorry for the delay, @Arusekk!

Although the fix looks correct, it would be awesome if we could add a test to make sure we don't accidentally reintroduce this bug. Maybe we could have a table-driven test covering:

  • postgres:///postgres?host=/run/postgresql
  • postgresql://user@/postgres?host=/run/postgresql
  • A normal TCP URL to prevent regressions
  • Preservation of credentials and query parameters

@ArthurSens

Copy link
Copy Markdown
Contributor

/workflow-approve

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.

Autodiscovery broken with Unix domain sockets

4 participants