loki icon indicating copy to clipboard operation
loki copied to clipboard

[promtail] -config.expand-env not working

Open alexanderruch opened this issue 2 years ago • 4 comments

Description -config.expand-env=true does not have the desired effect, system variables are not translated and are displayed blank.

To Reproduce Steps to reproduce the behavior:

  1. $ export TESTVAR=myTest
  2. setup promtail with local-config.yaml
  3. $ /usr/local/bin/promtail -config.expand-env=true -config.file /opt/promtail/local-config.yaml
  4. 0.0.0.:9080/targets

Expected behavior Labels showing test="" expected is test="myTest"

Environment:

  • Promtail version 2.5.0 (branch: HEAD, revision: 2d9d0ee23) / binary (promtail-linux-amd64.zip)
  • Ubuntu 20.04.4 LTS

Promtail config section

scrape_configs:
  - job_name: system
    pipeline_stages:
    static_configs:
      - targets:
          - localhost
        labels:
          job: varlogs  # Works as expected
          test: ${TESTVAR} # does not work
          __path__: /var/log/*.log

Varabiel output on terminal

test@ubuntu01:~$ echo $TESTVAR
myTest

alexanderruch avatar May 22 '22 02:05 alexanderruch

We saw the same thing with:

/path/to/promtail -config.expand-env=true -config.file /etc/promtail.yml

scrape_configs:
  - job_name: journal
    journal:
      labels:
        hostname: ${HOSTNAME}

The hostname label ends up blank

heapdavid avatar May 23 '22 12:05 heapdavid

I tried to reproduce this but I could not. Are you sure you start the promtail with the same user, or in the same terminal session where you export the environment variable?

Can you try:

HOSTNAME=foo /path/to/promtail -config.expand-env=true -config.file /etc/promtail.yml

chaudum avatar May 25 '22 15:05 chaudum

Hi! This issue has been automatically marked as stale because it has not had any activity in the past 30 days.

We use a stalebot among other tools to help manage the state of issues in this project. A stalebot can be very useful in closing issues in a number of cases; the most common is closing issues or PRs where the original reporter has not responded.

Stalebots are also emotionless and cruel and can close issues which are still very relevant.

If this issue is important to you, please add a comment to keep it open. More importantly, please add a thumbs-up to the original issue entry.

We regularly sort for closed issues which have a stale label sorted by thumbs up.

We may also:

  • Mark issues as revivable if we think it's a valid issue but isn't something we are likely to prioritize in the future (the issue will still remain closed).
  • Add a keepalive label to silence the stalebot if the issue is very common/popular/important.

We are doing our best to respond, organize, and prioritize all issues but it can be a challenging task, our sincere apologies if you find yourself at the mercy of the stalebot.

stale[bot] avatar Jul 10 '22 22:07 stale[bot]

In case someone else runs into this issue, the systemd unit file had to be changed to the following to pass in a variable.

ExecStart=/bin/bash -c 'hostname=$HOSTNAME exec /usr/local/bin/promtail -config.expand-env=true -positions.file /var/lib/promtail/positions.yml -config.file /etc/loki/promtail.yaml'

mwolter805 avatar Aug 06 '22 22:08 mwolter805

Any news on this?

TheWiresharkGuy avatar Jul 04 '23 16:07 TheWiresharkGuy

+1 In my case I'm using Docker Compose, and even when overwriting the entrypoint, the -config.expand-env=true flag does nothing.

promtail:
  image: grafana/promtail:2.9.2
  volumes:
    - ./config/promtail.yml:/etc/promtail/promtail.yml
  environment:
    - MY_ENV_VAR=${MY_ENV_VAR}
  entrypoint: >
    /bin/bash -c "
    MY_ENV_VAR=localhost /usr/bin/promtail -config.expand-env=true -config.file /etc/promtail/promtail.yml
    "

/etc/promtail/promtail.yml

scrape_configs:
  - job_name: logger
    static_configs:
      - targets:
        - ${MY_ENV_VAR}

Pexers avatar Oct 25 '23 14:10 Pexers