scaphandre
scaphandre copied to clipboard
Invalid escape sequence in prometheus output
Bug description
Getting an error from prometheus when trying to scrape scaphandre metrics: text format parsing error in line 46: invalid escape sequence '\u'
The line 46:
scaph_process_power_consumption_microwatts{exe="agetty",cmdline="/sbin/agetty-o-p -- \u--nocleartty1linux",pid="683"} 0
To Reproduce
Run scaphandre in prometheus mode and start a process with prometheus invalid escape sequence in the cmdline
Expected behavior
Prometheus consuming metrics
Screenshots
N/A
Environment
- Linux distribution version: Debian GNU/Linux 11.4
- Kernel version (output of
uname -r
): 5.10.0-16-amd64 - Scaphandre build from
dev
, commitf0be7fec728bc1f52c6a36f0ceeebd699b1da8ce
Additional context
N/A
May be related to the old prometheus version. I'm using prometheus version 1.8.1
in this setup. Can't test on a newer version unfortunately :disappointed:
I use telegraf to scrape, i get the same error with \_
. Complex commandline arguments for quemu contain whole json arguments.
reading text format failed: text format parsing error in line 22: invalid escape sequence '\_'
It seems that OpenMetrics format recommends (SHOULD in the spec) that we escape backslashes https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#escaping.
It means replacing '' by '\' when formatting the metric. We only do it for the quote char but not backslashes.
https://github.com/hubblo-org/scaphandre/blob/50fea42ebd1f8bda9d98e8d27b348c626ed3055d/src/exporters/prometheus.rs#L197
@bpetit I opened a PR, but would like to have your view on this, feel free to close the PR if you disagree. I may have overlooked possible side effects (in particular, changing the labels may pose problem with existing data).
Any update on this issue ? I have the same error when trying to read the data with telegraf :
2023-03-24T13:50:19Z E! [inputs.prometheus] Error in plugin: error reading metrics for "http://127.0.0.1:8887/metrics": reading text format failed: text format parsing error in line 150: invalid escape sequence '\u'
I should review the PR next week. Thanks for your contribution on this
Any update on this issue ? I would love to inject data into prometheus :)
Hi,
I got the exact same error developing the prometheus pushgateway exporter.
A fix is now in dev for this, could you give it a try ?
Hi !
@dmazhar-cogniance @meepmeep did you get any chance to try the dev branch ? :)
Closing until someone speaks up :)