MindFlavor / prometheus_wireguard_exporter

A Prometheus exporter for WireGuard, written in Rust.
https://mindflavor.github.io/prometheus_wireguard_exporter
MIT License
485 stars 51 forks source link

Unescaped double quotes in `friendly_name` break prometheus scrape #82

Closed stvnw closed 2 years ago

stvnw commented 2 years ago

Double quotation marks (") in friendly_name are not automatically escaped in the metrics output, and will cause scraping by prometheus to fail. For example:

# friendly_name = Ada's 13" Laptop

will result in a prometheus error like:

<datetime> <host> prometheus: level=debug ts=<ts> caller=scrape.go:<pid>
component="scrape manager" scrape_pool=<job> target=http://<ip>:9586/metrics
msg="Append failed" err="expected label name, got \"INVALID\""

Prometheus will also mark the host as not up.

Scraping succeeds if double quotes are manually escaped in the config file. The following is okay:

# friendly_name = Ada's 13\" Laptop

Technically this also applies to friendly_json, but unescaped double qoutes would be malformed JSON, and it is the user's responsibility to supply well-formed JSON. In the case of friendly_name, I would propose either the exporter automatically escape double quotes, or a note be added to the README to let the user know of this requirement.

MindFlavor commented 2 years ago

Good catch. The fix should be easy enough.