Browse Source

check if floats are finite, replacing NaNs with 0.0 to avoid influx server errors

master
Jonathan Strong 6 years ago
parent
commit
f59c627187
1 changed files with 15 additions and 5 deletions
  1. +15
    -5
      src/influx.rs

+ 15
- 5
src/influx.rs View File

@@ -539,14 +539,24 @@ pub fn serialize_owned(measurement: &OwnedMeasurement, line: &mut String) {
match *value { match *value {
OwnedValue::String(ref s) => line.push_str(&as_string(s)), OwnedValue::String(ref s) => line.push_str(&as_string(s)),
OwnedValue::Integer(ref i) => line.push_str(&format!("{}i", i)), OwnedValue::Integer(ref i) => line.push_str(&format!("{}i", i)),
OwnedValue::Float(ref f) => line.push_str(&format!("{}", f)),
OwnedValue::Boolean(ref b) => line.push_str(as_boolean(b)), OwnedValue::Boolean(ref b) => line.push_str(as_boolean(b)),
OwnedValue::D128(ref d) => line.push_str(&format!("{}", d)),


#[cfg(not(feature = "disable-short-uuid"))]
OwnedValue::Uuid(ref u) => line.push_str(&format!("\"{}\"", &u.to_string()[..8])),
OwnedValue::D128(ref d) => {
if d.is_finite() {
line.push_str(&format!("{}", d));
} else {
line.push_str("0.0");
}
}

OwnedValue::Float(ref f) => {
if f.is_finite() {
line.push_str(&format!("{}", f));
} else {
line.push_str("0.0");
}
}


#[cfg(feature = "disable-short-uuid")]
OwnedValue::Uuid(ref u) => line.push_str(&format!("\"{}\"", u)), OwnedValue::Uuid(ref u) => line.push_str(&format!("\"{}\"", u)),
}; };
}; };


Loading…
Cancel
Save