Skip to content

Commit 45e0d70

Browse files
authored
Cleanup non-standard ENV var setup (#518)
Drop ENV vars from flags as this is non-standard in the Prometheus ecosystem. * Remove es.apiKey flag to avoid credential leaks. Signed-off-by: SuperQ <[email protected]>
1 parent 4699efb commit 45e0d70

File tree

2 files changed

+26
-29
lines changed

2 files changed

+26
-29
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ elasticsearch_exporter --help
5757
| es.client-cert | 1.0.2 | Path to PEM file that contains the corresponding cert for the private key to connect to Elasticsearch. | |
5858
| es.clusterinfo.interval | 1.1.0rc1 | Cluster info update interval for the cluster label | 5m |
5959
| es.ssl-skip-verify | 1.0.4rc1 | Skip SSL verification when connecting to Elasticsearch. | false |
60-
| es.apiKey | unreleased | API Key to use for authenticating against Elasticsearch. | |
6160
| web.listen-address | 1.0.2 | Address to listen on for web interface and telemetry. | :9114 |
6261
| web.telemetry-path | 1.0.2 | Path under which to expose metrics. | /metrics |
6362
| version | 1.0.2 | Show version info on stdout and exit. | |
6463

6564
Commandline parameters start with a single `-` for versions less than `1.1.0rc1`.
66-
For versions greater than `1.1.0rc1`, commandline parameters are specified with `--`. Also, all commandline parameters can be provided as environment variables. The environment variable name is derived from the parameter name
67-
by replacing `.` and `-` with `_` and upper-casing the parameter name.
65+
For versions greater than `1.1.0rc1`, commandline parameters are specified with `--`.
66+
67+
The API key used to connect can be set with the `ES_API_KEY` environment variable.
6868

6969
#### Elasticsearch 7.x security privileges
7070

main.go

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,67 +48,64 @@ func main() {
4848
var (
4949
listenAddress = kingpin.Flag("web.listen-address",
5050
"Address to listen on for web interface and telemetry.").
51-
Default(":9114").Envar("WEB_LISTEN_ADDRESS").String()
51+
Default(":9114").String()
5252
metricsPath = kingpin.Flag("web.telemetry-path",
5353
"Path under which to expose metrics.").
54-
Default("/metrics").Envar("WEB_TELEMETRY_PATH").String()
54+
Default("/metrics").String()
5555
esURI = kingpin.Flag("es.uri",
5656
"HTTP API address of an Elasticsearch node.").
57-
Default("http://localhost:9200").Envar("ES_URI").String()
57+
Default("http://localhost:9200").String()
5858
esTimeout = kingpin.Flag("es.timeout",
5959
"Timeout for trying to get stats from Elasticsearch.").
60-
Default("5s").Envar("ES_TIMEOUT").Duration()
60+
Default("5s").Duration()
6161
esAllNodes = kingpin.Flag("es.all",
6262
"Export stats for all nodes in the cluster. If used, this flag will override the flag es.node.").
63-
Default("false").Envar("ES_ALL").Bool()
63+
Default("false").Bool()
6464
esNode = kingpin.Flag("es.node",
6565
"Node's name of which metrics should be exposed.").
66-
Default("_local").Envar("ES_NODE").String()
66+
Default("_local").String()
6767
esExportIndices = kingpin.Flag("es.indices",
6868
"Export stats for indices in the cluster.").
69-
Default("false").Envar("ES_INDICES").Bool()
69+
Default("false").Bool()
7070
esExportIndicesSettings = kingpin.Flag("es.indices_settings",
7171
"Export stats for settings of all indices of the cluster.").
72-
Default("false").Envar("ES_INDICES_SETTINGS").Bool()
72+
Default("false").Bool()
7373
esExportIndicesMappings = kingpin.Flag("es.indices_mappings",
7474
"Export stats for mappings of all indices of the cluster.").
75-
Default("false").Envar("ES_INDICES_MAPPINGS").Bool()
75+
Default("false").Bool()
7676
esExportClusterSettings = kingpin.Flag("es.cluster_settings",
7777
"Export stats for cluster settings.").
78-
Default("false").Envar("ES_CLUSTER_SETTINGS").Bool()
78+
Default("false").Bool()
7979
esExportShards = kingpin.Flag("es.shards",
8080
"Export stats for shards in the cluster (implies --es.indices).").
81-
Default("false").Envar("ES_SHARDS").Bool()
81+
Default("false").Bool()
8282
esExportSnapshots = kingpin.Flag("es.snapshots",
8383
"Export stats for the cluster snapshots.").
84-
Default("false").Envar("ES_SNAPSHOTS").Bool()
84+
Default("false").Bool()
8585
esClusterInfoInterval = kingpin.Flag("es.clusterinfo.interval",
8686
"Cluster info update interval for the cluster label").
87-
Default("5m").Envar("ES_CLUSTERINFO_INTERVAL").Duration()
87+
Default("5m").Duration()
8888
esCA = kingpin.Flag("es.ca",
8989
"Path to PEM file that contains trusted Certificate Authorities for the Elasticsearch connection.").
90-
Default("").Envar("ES_CA").String()
90+
Default("").String()
9191
esClientPrivateKey = kingpin.Flag("es.client-private-key",
9292
"Path to PEM file that contains the private key for client auth when connecting to Elasticsearch.").
93-
Default("").Envar("ES_CLIENT_PRIVATE_KEY").String()
93+
Default("").String()
9494
esClientCert = kingpin.Flag("es.client-cert",
9595
"Path to PEM file that contains the corresponding cert for the private key to connect to Elasticsearch.").
96-
Default("").Envar("ES_CLIENT_CERT").String()
96+
Default("").String()
9797
esInsecureSkipVerify = kingpin.Flag("es.ssl-skip-verify",
9898
"Skip SSL verification when connecting to Elasticsearch.").
99-
Default("false").Envar("ES_SSL_SKIP_VERIFY").Bool()
100-
esAPIKey = kingpin.Flag("es.apiKey",
101-
"API Key to use for authenticating against Elasticsearch").
102-
Default("").Envar("ES_API_KEY").String()
99+
Default("false").Bool()
103100
logLevel = kingpin.Flag("log.level",
104101
"Sets the loglevel. Valid levels are debug, info, warn, error").
105-
Default("info").Envar("LOG_LEVEL").String()
102+
Default("info").String()
106103
logFormat = kingpin.Flag("log.format",
107104
"Sets the log format. Valid formats are json and logfmt").
108-
Default("logfmt").Envar("LOG_FMT").String()
105+
Default("logfmt").String()
109106
logOutput = kingpin.Flag("log.output",
110107
"Sets the log output. Valid outputs are stdout and stderr").
111-
Default("stdout").Envar("LOG_OUTPUT").String()
108+
Default("stdout").String()
112109
)
113110

114111
kingpin.Version(version.Print(name))
@@ -143,12 +140,12 @@ func main() {
143140
Proxy: http.ProxyFromEnvironment,
144141
}
145142

146-
if *esAPIKey != "" {
147-
apiKey := *esAPIKey
143+
esAPIKey := os.Getenv("ES_API_KEY")
148144

145+
if esAPIKey != "" {
149146
httpTransport = &transportWithAPIKey{
150147
underlyingTransport: httpTransport,
151-
apiKey: apiKey,
148+
apiKey: esAPIKey,
152149
}
153150
}
154151

0 commit comments

Comments
 (0)