Skip to content

Autodiscovery broken with Unix domain sockets #1316

Description

@Arusekk

What did you do?

If the exporter is configured to use Unix domain socket connections over URL postgres:///dbname?host=/run/postgresql, autodiscovery tries to resolve the additional databases as hosts.
A workaround is to use key=value key=value connection strings, but this is incompatible with Grafana alloy, which insists DSNs must be valid URLs.

The culprit is here:

dsnURI.Path = databaseName

Golang URL structure tries to fix this path when hostname is not empty, but it does not try so hard when there is no hostname.
I tried reporting to upstream golang, but they decided that it is on the user to prepend a slash (golang/go#79532).

Context: grafana/alloy#4624 (comment)

What did you expect to see?

Autodiscovery of my databases.

What did you see instead? Under which circumstances?

Exporter trying to connect to hosts named as my databases.

Environment

  • System information:

  • postgres_exporter version:

    <bundled in latest alloy, issue still present on master>

  • postgres_exporter flags:

? I think N/A

  • PostgreSQL version:

  • Logs:

Oct 17 19:34:53 bareostest.hebler.lab alloy[8703]: ts=2025-10-17T17:34:53.07021794Z level=error msg="error encountered scraping DSN" component_path=/ component_id=prometheus.exporter.postgres.default err="Error opening connection to database (postgresql://bareos?host=/run/postgresql&sslmode=disable): dial tcp: lookup bareos on 192.168.122.1:53: no such host"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions