Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tilde character in file path in a shell must expand to the absolute path of the home directory #4244

Closed
amej opened this Issue Jun 8, 2018 · 8 comments

Comments

Projects
None yet
3 participants
@amej
Copy link

amej commented Jun 8, 2018

Proposal

** Tilde symbol in a file path needs to expand to absolute path of home directory of the user as per the *nix **

Bug Report

What did you do?
As per instructions given in https://prometheus.io/docs/introduction/first_steps/; start prometheus by executing
./prometheus --config.file=~asathe/prometheus-2.3.0.linux-amd64/prometheus.yml

What did you expect to see?
In the ~asathe/prometheus-2.3.0.linux-amd64/prometheus.yml ; I expected the ~asathe to expand to home directory of asathe ( in my case; it is /home/pnq/asathe )
What did you see instead? Under which circumstances?
prometheus reported
level=error ts=2018-06-08T13:41:36.291212386Z caller=main.go:597 err="Error loading config couldn't load configuration (--config.file=~asathe/prometheus-2.3.0.linux-amd64/prometheus.yml): open ~asathe/prometheus-2.3.0.linux-amd64/prometheus.yml: no such file or directory"

Environment

  • System information:

Linux 4.14.16-300.fc27.x86_64 x86_64 ```

  • Prometheus version:
./prometheus --version
prometheus, version 2.3.0 (branch: HEAD, revision: 290d71791a507a5057b9a099c9d48703d86dc941)
  build user:       root@d539e167976a
  build date:       20180607-08:46:54
  go version:       go1.10.2
  • Prometheus configuration file:
[asathe@localhost prometheus-2.3.0.linux-amd64]$ cat prometheus.yml 
# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
    - targets: ['localhost:9090']
[asathe@localhost prometheus-2.3.0.linux-amd64]$ 
  • Logs:
[root@localhost prometheus-2.3.0.linux-amd64]# ./prometheus --config.file=~asathe/prometheus-2.3.0.linux-amd64/prometheus.yml 
level=info ts=2018-06-08T13:41:36.242555868Z caller=main.go:222 msg="Starting Prometheus" version="(version=2.3.0, branch=HEAD, revision=290d71791a507a5057b9a099c9d48703d86dc941)"
level=info ts=2018-06-08T13:41:36.242694699Z caller=main.go:223 build_context="(go=go1.10.2, user=root@d539e167976a, date=20180607-08:46:54)"
level=info ts=2018-06-08T13:41:36.2427562Z caller=main.go:224 host_details="(Linux 4.14.16-300.fc27.x86_64 #1 SMP Wed Jan 31 19:24:27 UTC 2018 x86_64 localhost.localdomain (none))"
level=info ts=2018-06-08T13:41:36.242800958Z caller=main.go:225 fd_limits="(soft=1024, hard=4096)"
level=info ts=2018-06-08T13:41:36.24340709Z caller=main.go:514 msg="Starting TSDB ..."
level=info ts=2018-06-08T13:41:36.249070562Z caller=web.go:426 component=web msg="Start listening for connections" address=0.0.0.0:9090
level=info ts=2018-06-08T13:41:36.272393842Z caller=main.go:524 msg="TSDB started"
level=info ts=2018-06-08T13:41:36.275782327Z caller=main.go:603 msg="Loading configuration file" filename=~asathe/prometheus-2.3.0.linux-amd64/prometheus.yml
level=info ts=2018-06-08T13:41:36.27587218Z caller=main.go:402 msg="Stopping scrape discovery manager..."
level=info ts=2018-06-08T13:41:36.275922809Z caller=main.go:416 msg="Stopping notify discovery manager..."
level=info ts=2018-06-08T13:41:36.275960298Z caller=main.go:438 msg="Stopping scrape manager..."
level=info ts=2018-06-08T13:41:36.276101975Z caller=main.go:412 msg="Notify discovery manager stopped"
level=info ts=2018-06-08T13:41:36.287078035Z caller=manager.go:464 component="rule manager" msg="Stopping rule manager..."
level=info ts=2018-06-08T13:41:36.287120767Z caller=manager.go:470 component="rule manager" msg="Rule manager stopped"
level=info ts=2018-06-08T13:41:36.287138091Z caller=notifier.go:512 component=notifier msg="Stopping notification manager..."
level=info ts=2018-06-08T13:41:36.290181893Z caller=main.go:398 msg="Scrape discovery manager stopped"
level=info ts=2018-06-08T13:41:36.29078386Z caller=main.go:432 msg="Scrape manager stopped"
level=info ts=2018-06-08T13:41:36.290835358Z caller=main.go:588 msg="Notifier manager stopped"
level=error ts=2018-06-08T13:41:36.291212386Z caller=main.go:597 err="Error loading config couldn't load configuration (--config.file=~asathe/prometheus-2.3.0.linux-amd64/prometheus.yml): open ~asathe/prometheus-2.3.0.linux-amd64/prometheus.yml: no such file or directory"
level=info ts=2018-06-08T13:41:36.291274804Z caller=main.go:599 msg="See you next time!"


@brian-brazil

This comment has been minimized.

Copy link
Member

brian-brazil commented Jun 8, 2018

Tilde expansion is the responsibility of your shell on Unix. Which shell are you using?

If your shell doesn't support it, $HOME always works.

@amej

This comment has been minimized.

Copy link
Author

amej commented Jun 8, 2018

Tilde expansion is the responsibility of your shell on Unix. Which shell are you using?

root@localhost ~]# file ~
/root: directory
[root@localhost ~]# file ~asathe/
/home/asathe/: directory
[root@localhost ~]# echo $HOME
/root
[root@localhost ~]# echo $SHELL
/bin/bash
[root@localhost ~]# rpm -q bash
bash-4.4.12-13.fc27.x86_64
[root@localhost ~]# 


[asathe@localhost node_exporter-0.16.0.linux-amd64]$ j=~asathe
[asathe@localhost node_exporter-0.16.0.linux-amd64]$ echo $j
/home/asathe



It is not mentioned in the documents, but the './prometheus --configfile= ..' needs to be executed as root user. In my scenario; I extracted prometheus into normal user's directory '~asathe/prometheus'.
I switched non-login/login-shell to root to execute prometheus binary. But; after switching the variable $HOME would store the home directory of root user. Hence; the only option is to use the tilde symbol.
Thus; this is still an issue.

In the scenario; 'prometheus' directory is present inside the home directory root user; $HOME gets expanded to its value ( /root ) in the following command:
./prometheus --config.file=$HOME/prometheus-2.3.0.linux-amd64/prometheus.yml

@brian-brazil

This comment has been minimized.

Copy link
Member

brian-brazil commented Jun 8, 2018

I switched non-login/login-shell to root to execute prometheus binary.

It sounds like you've been using sudo or similar and your environment has gotten a bit messed up. I'd suggest logging in normally as your usual non-root user and starting from scratch from there.

@krasi-georgiev

This comment has been minimized.

Copy link
Member

krasi-georgiev commented Jun 8, 2018

I just tried and ~ doesn't expand for me either.

ls ~/src/github.com/prometheus/prometheus/debug/simple.yml
-rw-r--r--. 1 krasi 437 Jun  7 14:09 /home/krasi/src/github.com/prometheus/prometheus/debug/simple.yml

go run main.go  uname_default.go fdlimits_default.go  --config.file=~/src/github.com/prometheus/prometheus/debug/simple.yml
....
...
open ~/src/github.com/prometheus/prometheus/debug/simple.yml: no such file or directory
@krasi-georgiev

This comment has been minimized.

Copy link
Member

krasi-georgiev commented Jun 8, 2018

@amej do you think you can try to find the cause and open a PR?

@krasi-georgiev

This comment has been minimized.

Copy link
Member

krasi-georgiev commented Jun 8, 2018

on a second thought @amej do you have any immediate use for that? unless it is trivial change and someone really needs this maybe not worth adding any extra code for this.

I usually use relative paths like ./prometheus --config.file=../../debug/simple.yml

@krasi-georgiev

This comment has been minimized.

Copy link
Member

krasi-georgiev commented Jun 11, 2018

don't think we have an immediate need for this so will revisit if needed.

feel free to reopen if you have a good use case that requires this.

@lock

This comment has been minimized.

Copy link

lock bot commented Mar 22, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Mar 22, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.