Skip to content

Comments

feat: provide configuration subset via env variables#430

Merged
burningalchemist merged 1 commit intomasterfrom
config/env
Jan 15, 2024
Merged

feat: provide configuration subset via env variables#430
burningalchemist merged 1 commit intomasterfrom
config/env

Conversation

@burningalchemist
Copy link
Owner

@burningalchemist burningalchemist commented Jan 12, 2024

resolves #186

This PR adds a feature to pass values via environment variables with SQLEXPORTER_ prefix to a subset of configuration parameters such as:

SQLEXPORTER_GLOBAL_MIN_INTERVAL
SQLEXPORTER_GLOBAL_SCRAPE_TIMEOUT_OFFSET
SQLEXPORTER_GLOBAL_SCRAPE_TIMEOUT
SQLEXPORTER_GLOBAL_MAX_CONNECTION_LIFETIME
SQLEXPORTER_GLOBAL_MAX_CONNECTIONS
SQLEXPORTER_GLOBAL_MAX_IDLE_CONNECTIONS

SQLEXPORTER_TARGET_NAME
SQLEXPORTER_TARGET_DSN
SQLEXPORTER_TARGET_AWS_SECRET_NAME
SQLEXPORTER_TARGET_COLLECTORS
SQLEXPORTER_TARGET_ENABLE_PING

The precedence (where applicable) is:

Command line parameters > Environment variables > Config file

SQLEXPORTER_TARGET_COLLECTORS list can be passed as semicolon-separated values (e.g. a;b;c;d).


Given the complexity to represent jobs via dedicated environment variables, there's an option to pass the configuration as a json/yaml object to SQLEXPORTER_JOBS. It's unclear whether it's a good idea at all, so it's not a part of this particular PR and might be added later.

In the meantime, the recent change has brought environment variable expansion, providing a way to define DSN strings as user-defined environment variables, and expand them on the app init. This should help with separating sensitive data from the rest of the config file. In the past this urged users to treat the whole sql_exporter.yml file as a secret (to conform with the good security practices) or keep sensitive data visible as plaintext (ignoring security practices). This problem might be finally considered as solved.


Besides, the minimal go version in go.mod to build the project is updated to v1.21.

fix: set default delimiter to semicolon
@burningalchemist burningalchemist changed the title wip: provide configuration subset via env variables feat: provide configuration subset via env variables Jan 15, 2024
@burningalchemist burningalchemist marked this pull request as ready for review January 15, 2024 22:57
@burningalchemist burningalchemist merged commit 4c15797 into master Jan 15, 2024
@burningalchemist burningalchemist deleted the config/env branch January 15, 2024 23:09
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.

Add full support for config based on environment variables

1 participant