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

Invalid escape sequence in prometheus output #204

Closed
dmazhar-cogniance opened this issue Aug 1, 2022 · 10 comments
Closed

Invalid escape sequence in prometheus output #204

dmazhar-cogniance opened this issue Aug 1, 2022 · 10 comments
Labels
bug Something isn't working

Comments

@dmazhar-cogniance
Copy link

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 dmazhar-cogniance added the bug Something isn't working label Aug 1, 2022
@dmazhar-cogniance
Copy link
Author

dmazhar-cogniance commented Aug 23, 2022

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 😞

@TheOneValen
Copy link

TheOneValen commented Jan 6, 2023

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

@demeringo
Copy link
Contributor

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.

result.push_str(&format!("{}=\"{}\",", k, v.replace('\"', "_")));

demeringo added a commit to demeringo/scaphandre that referenced this issue Jan 9, 2023
@demeringo
Copy link
Contributor

@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 added a commit to demeringo/scaphandre that referenced this issue Jan 31, 2023
@meepmeep
Copy link

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'

@bpetit
Copy link
Contributor

bpetit commented Mar 24, 2023

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

@meepmeep
Copy link

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

@bpetit
Copy link
Contributor

bpetit commented May 18, 2023

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
Copy link
Contributor

bpetit commented Jul 24, 2023

Hi !

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

@bpetit
Copy link
Contributor

bpetit commented Aug 11, 2023

Closing until someone speaks up :)

@bpetit bpetit closed this as completed Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Previous releases
Development

No branches or pull requests

5 participants