Skip to content

Environment variable substitution for DSN's #427

@Marcel-Jansen

Description

@Marcel-Jansen

Is your feature request related to a problem? Please describe.
When using a DSN that contains environment variable placeholders (e.g., ${DB_USER}), the placeholders are not automatically substituted, which prevents us from reusing existing database secrets.

Describe the solution you'd like
I suggest enhancing the safeParse function to automatically substitute environment variable placeholders within the DSN, utilizing the newly introduced functionality for setting environment variables in PR #399.

func safeParse(rawURL string) (*dburl.URL, error) {
	parsed, err := dburl.Parse(os.ExpandEnv(rawURL))
	if err != nil {
		if uerr := new(url.Error); errors.As(err, &uerr) {
			return nil, uerr.Err
		}
		return nil, errors.New("invalid URL")
	}
	return parsed, nil
}

Describe alternatives you've considered
We are currently implementing the SQL exporter jobs functionality, allowing us to use a single exporter instance against multiple database connections. However, we don't see suitable and safe solutions for setting the database credentials except running two SQL exporter instances with the SQLEXPORTER_TARGET_DSN set. This approach would require creating a new secret with the DSN value, while a secret with the username and password for the databases already exists.

Feature request #186 will partially resolve this issue, but would still require two instances.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions