-
Notifications
You must be signed in to change notification settings - Fork 2k
fix(codecs): native JSON serialization/deserialization for special f64 values #18650
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5541544
fix: native JSON serialization/deserialization for histogram buckets
pront 6a1108a
regenerated fixtures
pront f7093ba
ignore prev24 tests - will revisit
pront 8b9da21
remove debugging stuff
pront f8845c2
update tests
pront de5b38b
first attempt at a backwards compatible solution
pront f2a79ee
cleanup, remove unused functions, clippy shenanigans
pront 41392f6
Update lib/vector-core/src/event/metric/value.rs
pront 3421949
implemented visitor pattern deserializer optimization
pront File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| use bytes::BytesMut; | ||
| use codecs::decoding::format::Deserializer; | ||
| use codecs::encoding::format::Serializer; | ||
| use codecs::{NativeJsonDeserializerConfig, NativeJsonSerializerConfig}; | ||
| use vector_core::buckets; | ||
| use vector_core::config::LogNamespace; | ||
| use vector_core::event::{Event, Metric}; | ||
| use vector_core::event::{MetricKind, MetricValue}; | ||
|
|
||
| fn assert_roundtrip( | ||
| input_event: Event, | ||
| serializer: &mut dyn Serializer<Error = vector_common::Error>, | ||
| deserializer: &dyn Deserializer, | ||
| expected_json_value: serde_json::Value, | ||
| ) { | ||
| let mut bytes_mut = BytesMut::new(); | ||
| serializer | ||
| .encode(input_event.clone(), &mut bytes_mut) | ||
| .unwrap(); | ||
| let bytes = bytes_mut.freeze(); | ||
| let events = deserializer.parse(bytes, LogNamespace::Vector).unwrap(); | ||
| assert_eq!(events.len(), 1); | ||
| assert_eq!(events[0], input_event); | ||
|
|
||
| let json_value = serde_json::to_value(input_event.as_metric()).unwrap(); | ||
| assert_eq!(json_value, expected_json_value); | ||
| } | ||
|
|
||
| #[test] | ||
| fn histogram_metric_roundtrip() { | ||
| let histogram_event = Event::from(Metric::new( | ||
| "histogram", | ||
| MetricKind::Absolute, | ||
| MetricValue::AggregatedHistogram { | ||
| count: 1, | ||
| sum: 1.0, | ||
| buckets: buckets!( | ||
| f64::NEG_INFINITY => 10 , | ||
| f64::MIN => 10, 1.5 => 10, | ||
| f64::MAX => 10, | ||
| f64::INFINITY => 10), | ||
| }, | ||
| )); | ||
|
|
||
| let expected_json_value = serde_json::from_str( | ||
| r#" | ||
| { | ||
| "aggregated_histogram": { | ||
| "buckets": [ | ||
| { | ||
| "count": 10, | ||
| "upper_limit": "-inf" | ||
| }, | ||
| { | ||
| "count": 10, | ||
| "upper_limit": -1.7976931348623157e308 | ||
| }, | ||
| { | ||
| "count": 10, | ||
| "upper_limit": 1.5 | ||
| }, | ||
| { | ||
| "count": 10, | ||
| "upper_limit": 1.7976931348623157e308 | ||
| }, | ||
| { | ||
| "count": 10, | ||
| "upper_limit": "inf" | ||
| } | ||
| ], | ||
| "count": 1, | ||
| "sum": 1.0 | ||
| }, | ||
| "kind": "absolute", | ||
| "name": "histogram" | ||
| }"#, | ||
| ) | ||
| .unwrap(); | ||
|
|
||
| assert_roundtrip( | ||
| histogram_event, | ||
| &mut NativeJsonSerializerConfig.build(), | ||
| &NativeJsonDeserializerConfig::default().build(), | ||
| expected_json_value, | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.