Escape metric label values
This commit is contained in:
parent
011fbdd2b7
commit
a1bcaf93d1
15
src/main.rs
15
src/main.rs
@ -62,6 +62,13 @@ async fn get_baeder_names() -> Result<HashMap<String, String>, String> {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn escape_metric_label_value(value: &String) -> String {
|
||||||
|
let value = value.replace(r#"\"#, r#"\\"#);
|
||||||
|
let value = value.replace("\n", r"\n");
|
||||||
|
let value = value.replace(r#"""#, r#"\""#);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct AppState {
|
struct AppState {
|
||||||
baedernames: HashMap<String, String>,
|
baedernames: HashMap<String, String>,
|
||||||
@ -143,9 +150,13 @@ async fn route_metrics(
|
|||||||
let mut out = String::new();
|
let mut out = String::new();
|
||||||
|
|
||||||
for bad in trafficdata {
|
for bad in trafficdata {
|
||||||
|
let badid = escape_metric_label_value(&bad.id);
|
||||||
match state.baedernames.get(&bad.id) {
|
match state.baedernames.get(&bad.id) {
|
||||||
Some(name) => out.push_str(&format!("berlinerbaeder_occupation{{bad=\"{}\", badname=\"{}\"}} {}\n", bad.id, name, bad.counter.unwrap_or(-1))),
|
Some(name) => {
|
||||||
None => out.push_str(&format!("berlinerbaeder_occupation{{bad=\"{}\"}} {}\n", bad.id, bad.counter.unwrap_or(-1))),
|
let badname = escape_metric_label_value(name);
|
||||||
|
out.push_str(&format!("berlinerbaeder_occupation{{bad=\"{}\", badname=\"{}\"}} {}\n", badid, badname, bad.counter.unwrap_or(-1)))}
|
||||||
|
,
|
||||||
|
None => out.push_str(&format!("berlinerbaeder_occupation{{bad=\"{}\"}} {}\n", badid, bad.counter.unwrap_or(-1))),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user