better escape prometheus label values (#63)

This commit is contained in:
Jerome Gravel-Niquet 2019-12-14 00:04:31 +00:00 committed by Toby Lawrence
parent be7c5151cc
commit 58ffb74b3e
1 changed files with 9 additions and 1 deletions

View File

@ -181,7 +181,15 @@ fn key_to_parts(key: Key) -> (String, Vec<String>) {
let labels = labels
.into_iter()
.map(Label::into_parts)
.map(|(k, v)| format!("{}=\"{}\"", k, v.escape_default().collect::<String>()))
.map(|(k, v)| {
format!(
"{}=\"{}\"",
k,
v.replace("\\", "\\\\")
.replace("\"", "\\\"")
.replace("\n", "\\n")
)
})
.collect();
(name, labels)