Skip to content

[prometheus-consul-exporter] Allow options to use environment variables #6896

Description

@javajawa

Is your feature request related to a problem ?

In our consul environment, we have a local consul endpoint available on every VM, not running in a container.
This is the desired target for the consul-exporter, but the Go binary does not reinterpret environment variables in options (which is a reasonable choice).

Ideally, we want to have this values.yaml config, and it Just Work:tm:

consulServer: "$CONSUL_HOST:8500"
extraEnv:
  - name: CONSUL_HOST
    valueFrom:
      fieldRef:
        fieldPath: status.hostIP

Describe the solution you'd like.

Some values setting which allows the following change

diff --git a/k8s/sre/consul-exporter/main/consul-exporter/consul-exporter.yaml b/k8s/sre/consul-exporter/main/consul-exporter/consul-exporter.yaml
index 6cc818f..c1fd68f 100644
--- a/k8s/sre/consul-exporter/main/consul-exporter/consul-exporter.yaml
+++ b/k8s/sre/consul-exporter/main/consul-exporter/consul-exporter.yaml
@@ -94,10 +94,9 @@ spec:
         - name: prometheus-consul-exporter
           image: "prom/consul-exporter:v0.13.0"
           imagePullPolicy: IfNotPresent
-          command: ["consul_exporter"]
+          command: ["/bin/sh"]
           args:
-            - "--consul.server=$CONSUL_HOST:8500"
+            - "-c"
+            - "consul_exporter --consul.server=$CONSUL_HOST:8500"
           ports:
             - name: http
               containerPort: 9107

This would be an opt-in; either

  • the traditional Helm option of overriding the command (although this may be fiddly with the static first option and the need for [/bin/sh, -c] for the shell option)
  • Having a flag that explicitly changes it to be launched via a shell

I have confirmed the image has a functional /bin/sh for both of these options.

Describe alternatives you've considered.

NONE

Additional context.

I have a local branch ready to go with the second option laid out, adding a single new value which acts as an explicit toggle for this feature

# By default, consul_exporter is run directly.
# If you want to use environment variables in `options` or `consulServer`,
# enable this option to have a shell interpret the command string before
# `consul_exporter` is executed.
invokeViaShell: false

And I'm raising the issue so I can grab the ID ;)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions