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

fix(codecs): native JSON serialization/deserialization for special f64 values #18650

Merged
merged 9 commits into from
Oct 4, 2023
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions lib/codecs/src/decoding/format/native_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ impl Deserializer for NativeJsonDeserializer {
}
.map_err(|error| format!("Error parsing JSON: {:?}", error))?;

//println!("{json}");

let events = match json {
serde_json::Value::Array(values) => values
.into_iter()
Expand Down
24 changes: 23 additions & 1 deletion lib/codecs/src/encoding/format/native_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ impl Encoder<Event> for NativeJsonSerializer {
#[cfg(test)]
mod tests {
use bytes::BytesMut;
use vector_core::event::{LogEvent, Value};
use vector_core::buckets;
use vector_core::event::{LogEvent, Metric, MetricKind, MetricValue, Value};
use vrl::btreemap;

use super::*;
Expand Down Expand Up @@ -84,4 +85,25 @@ mod tests {

assert_eq!(bytes.freeze(), serde_json::to_string(&json).unwrap());
}

#[test]
fn serialize_aggregated_histogram() {
let histogram_event = Event::from(Metric::new(
"histogram",
MetricKind::Absolute,
MetricValue::AggregatedHistogram {
count: 1,
sum: 1.0,
buckets: buckets!(f64::NEG_INFINITY => 0 ,2.0 => 1, f64::INFINITY => 0),
},
));

let mut serializer = NativeJsonSerializer::new();
let mut bytes = BytesMut::new();
serializer
.encode(histogram_event.clone(), &mut bytes)
.unwrap();
let json = serializer.to_json_value(histogram_event).unwrap();
assert_eq!(bytes.freeze(), serde_json::to_string(&json).unwrap());
}
}
2 changes: 1 addition & 1 deletion lib/codecs/tests/data/native_encoding/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/codecs/tests/data/native_encoding/json/0000.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/codecs/tests/data/native_encoding/json/0001.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/codecs/tests/data/native_encoding/json/0002.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/codecs/tests/data/native_encoding/json/0003.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/codecs/tests/data/native_encoding/json/0004.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/codecs/tests/data/native_encoding/json/0005.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/codecs/tests/data/native_encoding/json/0006.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading