timescale / prometheus-postgresql-adapter

Use PostgreSQL as a remote storage database for Prometheus
Apache License 2.0
335 stars 66 forks source link

CLI flags as environment variables #71

Closed sc250024 closed 5 years ago

sc250024 commented 5 years ago

Description

Solves issue https://github.com/timescale/prometheus-postgresql-adapter/issues/43. In general, to make the app more compliant with the 12Factor standard (https://12factor.net/config), and for security reasons mentioned in the issue, all CLI flags have an equivalent environment variable.

Motivation and Context

This is a feature enhancement. Initially I was working on a Helm chart for this app (https://github.com/helm/charts/pull/7927), and I thought it would be better to have environment variable support. I will probably resume work on the Helm chart, but the maintainers of that repo are slow as hell; probably better if Timescale had its own repository for Helm charts to be honest.

I'm not sure if this qualifies as a breaking change, but the CLI flags should be renamed to not use dots (.) in them. See my comment here (https://github.com/timescale/prometheus-postgresql-adapter/issues/43#issuecomment-481879131), but in short, the BASH shell doesn't allow for dots in environment variables names when you run export.

How Has This Been Tested?

Locally ran the build command:

GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -installsuffix cgo --ldflags '-w' -o prometheus-postgresql-adapter

And then ran docker-compose up --detach --build with some environment variables mapped to the container. I can confirm that the prometheus-postgresql-adapter successfully reads the environment variables injected.

Types of changes

Checklist:

CLAassistant commented 5 years ago

CLA assistant check
All committers have signed the CLA.