prometheus/promql
Tobias Klausmann b998636893
Improve error logging for missing config and QL dir (#10260)
* Improve error logging for missing config and QL dir

Currently, when Prometheus can't open its config file or the query
logging dir under the data dir, it only logs what it has been given
default or commandline/config. Depending on the environment this can be
less than helpful, since the working directory may be unclear to the
user. I have specifically kept the existing error messages as intact as
possible to a) still log the parameter as given and b) cause as little
disruption for log-parsers/-analyzers as possible.

So in case of the config file or the data dir being non-absolute paths,
I use os.GetWd to find the working dir and assemble an absolute path for
error logging purposes. If GetWd fails, we just log "unknown", as
recovering from an error there would be very complex measure, likely not
worth the code/effort.

Example errors:

```
$ ./prometheus
ts=2022-02-06T16:00:53.034Z caller=main.go:445 level=error msg="Error loading config (--config.file=prometheus.yml)" fullpath=/home/klausman/src/prometheus/prometheus.yml err="open prometheus.yml: no such file or directory"
$ touch prometheus.yml
$ ./prometheus
[...]
ts=2022-02-06T16:01:00.992Z caller=query_logger.go:99 level=error component=activeQueryTracker msg="Error opening query log file" file=data/queries.active fullpath=/home/klausman/src/prometheus/data/queries.active err="open data/queries.active: permission denied"
panic: Unable to create mmap-ed active query log
[...]
$
```

Signed-off-by: Tobias Klausmann <klausman@schwarzvogel.de>

* Replace our own logic with just using filepath.Abs()

Signed-off-by: Tobias Klausmann <klausman@schwarzvogel.de>

* Further simplification

Signed-off-by: Tobias Klausmann <klausman@schwarzvogel.de>

* Review edits

Signed-off-by: Tobias Klausmann <klausman@schwarzvogel.de>

* Review edits

Signed-off-by: Tobias Klausmann <klausman@schwarzvogel.de>

* Review edits

Signed-off-by: Tobias Klausmann <klausman@schwarzvogel.de>
2022-02-16 17:43:15 +01:00
..
fuzz-data textparse: Add fuzzing and fix bug caught 2017-07-07 11:12:17 +02:00
parser Move packages out of deprecated pkg directory 2021-11-09 08:03:10 +01:00
testdata address comment 2022-02-15 22:09:17 +08:00
bench_test.go Move packages out of deprecated pkg directory 2021-11-09 08:03:10 +01:00
engine.go Switch to grafana/regexp everywhere (#10268) 2022-02-13 00:58:27 +01:00
engine_test.go fix potential deadlock in test (#9010) 2021-11-27 12:45:06 +00:00
functions.go Switch to grafana/regexp everywhere (#10268) 2022-02-13 00:58:27 +01:00
functions_test.go feat: linreg => slope 0 for const values (#9728) 2021-11-16 00:03:22 +01:00
fuzz.go error for invalid media type should not be completely swallowed (#10186) 2022-02-08 10:57:56 +01:00
fuzz_test.go error for invalid media type should not be completely swallowed (#10186) 2022-02-08 10:57:56 +01:00
promql_test.go add doc 2022-02-13 21:59:03 +08:00
quantile.go address comment 2022-02-15 22:09:17 +08:00
query_logger.go Improve error logging for missing config and QL dir (#10260) 2022-02-16 17:43:15 +01:00
query_logger_test.go Switch to grafana/regexp everywhere (#10268) 2022-02-13 00:58:27 +01:00
test.go Switch to grafana/regexp everywhere (#10268) 2022-02-13 00:58:27 +01:00
test_test.go Move packages out of deprecated pkg directory 2021-11-09 08:03:10 +01:00
value.go Promql: Add clarifying note to Point.MarshalJSON 2021-11-25 13:32:37 +01:00