refactor(profiling): avoid panic on out-of-bounds label set id#2002
refactor(profiling): avoid panic on out-of-bounds label set id#2002morrisonlevi wants to merge 2 commits into
Conversation
📚 Documentation Check Results📦
|
Clippy Allow Annotation ReportComparing clippy allow annotations between branches:
Summary by Rule
Annotation Counts by File
Annotation Stats by Crate
About This ReportThis report tracks Clippy allow annotations for specific rules, showing how they've changed in this PR. Decreasing the number of these annotations generally improves code quality. |
🔒 Cargo Deny Results📦
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2002 +/- ##
==========================================
- Coverage 72.71% 72.70% -0.02%
==========================================
Files 452 452
Lines 74893 74937 +44
==========================================
+ Hits 54460 54481 +21
- Misses 20433 20456 +23
🚀 New features to boost your workflow:
|
🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: 14cb2ec | Docs | Datadog PR Page | Give us feedback! |
Artifact Size Benchmark Reportaarch64-alpine-linux-musl
aarch64-unknown-linux-gnu
libdatadog-x64-windows
libdatadog-x86-windows
x86_64-alpine-linux-musl
x86_64-unknown-linux-gnu
|
| #[cold] | ||
| fn oob_label_set() -> io::Error { | ||
| io::Error::new( | ||
| io::ErrorKind::InvalidData, | ||
| "out-of-bounds label set id found during serialization", | ||
| ) | ||
| } |
There was a problem hiding this comment.
whats the advantage of naming this function rather than using a closure
There was a problem hiding this comment.
In this specific case, to give it a #[cold] attribute so that the engine realizes it should be cold. It should never be called (only if there are bugs), so it's as cold as you can get!
Also, stylistically, it looked bad inline (because the formatter insists on formatting it across 4 lines).
| let iter = std::mem::take(&mut self.observations).try_into_iter()?; | ||
| for (sample, timestamp, mut values) in iter { | ||
| let labels = &mut extended_label_sets[sample.labels.to_raw_id()]; | ||
| let off = sample.labels.to_offset(); |
There was a problem hiding this comment.
what is the difference between offset and raw id?
There was a problem hiding this comment.
In these specific cases, nothing, because LabelSetId uses usize as the RawId type and there's no shifting. I think to_offset is more obvious about what we're doing, which is why I changed it.
For other types, like string ids, the to_raw_id() might return an i64, but to_offset() is always usize.
What does this PR do?
Avoids a panic on bounds access when the label set id is out-of-bounds. This shouldn't happen, and is a bug. If it does happen though we shouldn't panic: we should fail gracefully instead.
Motivation
I'm working to remove panics. For now I'm hunting places which already return a
Resultso they can be made without breaking compatibility.Additional Notes
Nope
How to test the change?
Tests as normal, regression test was added.