Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment variables to override connection string and collectors list #161

Closed
lukos opened this issue Nov 4, 2022 · 2 comments
Closed
Labels
enhancement New feature or request response pending

Comments

@lukos
Copy link

lukos commented Nov 4, 2022

As a containerised app, the current implementation doesn't seem to support using either a secret and/or an environment variable to set the secret parts of the connection string and/or to adjust the list of collectors. These are both in the root config file, which although it can be treated as an entire secret, means that whoever needs to configure the e.g. scrape timeout offset, also would need access to the secrets.

A solution I have implemented locally allows an optional environment variable that can set the DSN or the collectors list (the second I am not sure if it is as useful). This code is very simple:

func (t *TargetConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
	type plain TargetConfig
	if err := unmarshal((*plain)(t)); err != nil {
		return err
	}

        // My new block below
	// Look for env variable to overwrite
	if val, ok := os.LookupEnv("SQLEXPORTER_DSN"); ok {
		t.DSN = Secret(val)
	}

	// Check required fields
	if t.DSN == "" {
		return fmt.Errorf("missing data_source_name for target %+v", t)
	}
        // etc.

I am not sure if there are other ways to achieve the same thing but this allows my deployment tool to inject an environment variable with the correct DSN passwords in it per-environment.

If you are happy with this, I am happy to create a PR but as a Go noob, I don't know if I have missed any edge cases (like Nil errors)

@lukos lukos added the enhancement New feature or request label Nov 4, 2022
@burningalchemist
Copy link
Owner

burningalchemist commented Nov 10, 2022

Hi @lukos, there's already the environment variable which allows you to override the DSN in the config file, it's SQLEXPORTER_TARGET_DSN.

As for collectors list, I'm not sure we want to have it as an environment variable for the time being.

Besides, all the environment variables coming with the respective driver can also be applied (e.g. postgresql). For that you'd need to check the driver's repository.

Please let me know if it the environment variable doesn't work as expected.

@burningalchemist
Copy link
Owner

Closed due to inactivity.

@burningalchemist burningalchemist closed this as not planned Won't fix, can't repro, duplicate, stale Dec 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request response pending
Projects
None yet
Development

No branches or pull requests

2 participants