-
Notifications
You must be signed in to change notification settings - Fork 8
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 the trace payload size hint #664
Merged
+75
−54
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 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 |
---|---|---|
|
@@ -47,49 +47,56 @@ use tinybytes::{Bytes, BytesString}; | |
/// }; | ||
/// let encoded_data = to_vec_named(&vec![vec![span]]).unwrap(); | ||
/// let encoded_data_as_tinybytes = tinybytes::Bytes::from(encoded_data); | ||
/// let decoded_traces = from_slice(encoded_data_as_tinybytes).expect("Decoding failed"); | ||
/// let (decoded_traces, _) = from_slice(encoded_data_as_tinybytes).expect("Decoding failed"); | ||
/// | ||
/// assert_eq!(1, decoded_traces.len()); | ||
/// assert_eq!(1, decoded_traces[0].len()); | ||
/// let decoded_span = &decoded_traces[0][0]; | ||
/// assert_eq!("test-span", decoded_span.name.as_str()); | ||
/// ``` | ||
pub fn from_slice(mut data: tinybytes::Bytes) -> Result<Vec<Vec<Span>>, DecodeError> { | ||
pub fn from_slice(mut data: tinybytes::Bytes) -> Result<(Vec<Vec<Span>>, usize), DecodeError> { | ||
let trace_count = | ||
rmp::decode::read_array_len(unsafe { data.as_mut_slice() }).map_err(|_| { | ||
DecodeError::InvalidFormat("Unable to read array len for trace count".to_owned()) | ||
})?; | ||
|
||
(0..trace_count).try_fold( | ||
Vec::with_capacity( | ||
trace_count | ||
.try_into() | ||
.expect("Unable to cast trace_count to usize"), | ||
), | ||
|mut traces, _| { | ||
let span_count = | ||
rmp::decode::read_array_len(unsafe { data.as_mut_slice() }).map_err(|_| { | ||
DecodeError::InvalidFormat("Unable to read array len for span count".to_owned()) | ||
})?; | ||
|
||
let trace = (0..span_count).try_fold( | ||
Vec::with_capacity( | ||
span_count | ||
.try_into() | ||
.expect("Unable to cast span_count to usize"), | ||
), | ||
|mut trace, _| { | ||
let span = decode_span(&mut data)?; | ||
trace.push(span); | ||
Ok(trace) | ||
}, | ||
)?; | ||
|
||
traces.push(trace); | ||
let start_len = data.len(); | ||
|
||
Ok(traces) | ||
}, | ||
) | ||
Ok(( | ||
(0..trace_count).try_fold( | ||
Vec::with_capacity( | ||
trace_count | ||
.try_into() | ||
.expect("Unable to cast trace_count to usize"), | ||
), | ||
|mut traces, _| { | ||
let span_count = rmp::decode::read_array_len(unsafe { data.as_mut_slice() }) | ||
.map_err(|_| { | ||
DecodeError::InvalidFormat( | ||
"Unable to read array len for span count".to_owned(), | ||
) | ||
})?; | ||
|
||
let trace = (0..span_count).try_fold( | ||
Vec::with_capacity( | ||
span_count | ||
.try_into() | ||
.expect("Unable to cast span_count to usize"), | ||
), | ||
|mut trace, _| { | ||
let span = decode_span(&mut data)?; | ||
trace.push(span); | ||
Ok(trace) | ||
}, | ||
)?; | ||
|
||
traces.push(trace); | ||
|
||
Ok(traces) | ||
}, | ||
)?, | ||
start_len - data.len(), | ||
)) | ||
} | ||
|
||
#[inline] | ||
|
@@ -270,7 +277,7 @@ mod tests { | |
..Default::default() | ||
}; | ||
let encoded_data = rmp_serde::to_vec_named(&vec![vec![span]]).unwrap(); | ||
let decoded_traces = | ||
let (decoded_traces, _) = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably have at least one unit test that checks we're returning the correct size. |
||
from_slice(tinybytes::Bytes::from(encoded_data)).expect("Decoding failed"); | ||
|
||
assert_eq!(1, decoded_traces.len()); | ||
|
@@ -290,7 +297,7 @@ mod tests { | |
span["meta_struct"] = json!(expected_meta_struct.clone()); | ||
|
||
let encoded_data = rmp_serde::to_vec_named(&vec![vec![span]]).unwrap(); | ||
let decoded_traces = | ||
let (decoded_traces, _) = | ||
from_slice(tinybytes::Bytes::from(encoded_data)).expect("Decoding failed"); | ||
|
||
assert_eq!(1, decoded_traces.len()); | ||
|
@@ -314,7 +321,7 @@ mod tests { | |
span["meta_struct"] = json!(expected_meta_struct.clone()); | ||
|
||
let encoded_data = rmp_serde::to_vec_named(&vec![vec![span]]).unwrap(); | ||
let decoded_traces = | ||
let (decoded_traces, _) = | ||
from_slice(tinybytes::Bytes::from(encoded_data)).expect("Decoding failed"); | ||
|
||
assert_eq!(1, decoded_traces.len()); | ||
|
@@ -340,7 +347,7 @@ mod tests { | |
span["meta"] = json!(expected_meta.clone()); | ||
|
||
let encoded_data = rmp_serde::to_vec_named(&vec![vec![span]]).unwrap(); | ||
let decoded_traces = | ||
let (decoded_traces, _) = | ||
from_slice(tinybytes::Bytes::from(encoded_data)).expect("Decoding failed"); | ||
|
||
assert_eq!(1, decoded_traces.len()); | ||
|
@@ -370,7 +377,7 @@ mod tests { | |
span["meta"] = json!(expected_meta.clone()); | ||
|
||
let encoded_data = rmp_serde::to_vec_named(&vec![vec![span]]).unwrap(); | ||
let decoded_traces = | ||
let (decoded_traces, _) = | ||
from_slice(tinybytes::Bytes::from(encoded_data)).expect("Decoding failed"); | ||
|
||
assert_eq!(1, decoded_traces.len()); | ||
|
@@ -392,7 +399,7 @@ mod tests { | |
let mut span = create_test_json_span(1, 2, 0, 0); | ||
span["metrics"] = json!(expected_metrics.clone()); | ||
let encoded_data = rmp_serde::to_vec_named(&vec![vec![span]]).unwrap(); | ||
let decoded_traces = | ||
let (decoded_traces, _) = | ||
from_slice(tinybytes::Bytes::from(encoded_data)).expect("Decoding failed"); | ||
|
||
assert_eq!(1, decoded_traces.len()); | ||
|
@@ -416,7 +423,7 @@ mod tests { | |
let mut span = create_test_json_span(1, 2, 0, 0); | ||
span["metrics"] = json!(expected_metrics.clone()); | ||
let encoded_data = rmp_serde::to_vec_named(&vec![vec![span]]).unwrap(); | ||
let decoded_traces = | ||
let (decoded_traces, _) = | ||
from_slice(tinybytes::Bytes::from(encoded_data)).expect("Decoding failed"); | ||
|
||
assert_eq!(1, decoded_traces.len()); | ||
|
@@ -449,7 +456,7 @@ mod tests { | |
span["span_links"] = json!([expected_span_link]); | ||
|
||
let encoded_data = rmp_serde::to_vec_named(&vec![vec![span]]).unwrap(); | ||
let decoded_traces = | ||
let (decoded_traces, _) = | ||
from_slice(tinybytes::Bytes::from(encoded_data)).expect("Decoding failed"); | ||
|
||
assert_eq!(1, decoded_traces.len()); | ||
|
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's helpful to at least name the variable, even if we don't use it in the example.