scaphandre icon indicating copy to clipboard operation
scaphandre copied to clipboard

Invalid escape sequence in prometheus output

Open dmazhar-cogniance opened this issue 2 years ago • 1 comments

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, commit f0be7fec728bc1f52c6a36f0ceeebd699b1da8ce

Additional context

N/A

dmazhar-cogniance avatar Aug 01 '22 08:08 dmazhar-cogniance

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:

dmazhar-cogniance avatar Aug 23 '22 08:08 dmazhar-cogniance

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 '\_'

TheOneValen avatar Jan 06 '23 11:01 TheOneValen

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

demeringo avatar Jan 09 '23 15:01 demeringo

@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).

demeringo avatar Jan 09 '23 15:01 demeringo

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'

meepmeep avatar Mar 24 '23 15:03 meepmeep

I should review the PR next week. Thanks for your contribution on this

bpetit avatar Mar 24 '23 18:03 bpetit

Any update on this issue ? I would love to inject data into prometheus :)

meepmeep avatar Apr 12 '23 16:04 meepmeep

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 ?

bpetit avatar May 18 '23 15:05 bpetit

Hi !

@dmazhar-cogniance @meepmeep did you get any chance to try the dev branch ? :)

bpetit avatar Jul 24 '23 12:07 bpetit

Closing until someone speaks up :)

bpetit avatar Aug 11 '23 02:08 bpetit