-
Notifications
You must be signed in to change notification settings - Fork 16
feat(profiling)!: make MIME type optional #1492
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
base: main
Are you sure you want to change the base?
Conversation
📚 Documentation Check Results📦
|
🔒 Cargo Deny Results📦
|
45141ac to
3671a27
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1492 +/- ##
==========================================
- Coverage 71.04% 71.03% -0.01%
==========================================
Files 422 422
Lines 68697 68713 +16
==========================================
+ Hits 48804 48810 +6
- Misses 19893 19903 +10
🚀 New features to boost your workflow:
|
BenchmarksComparisonBenchmark execution time: 2026-01-29 22:02:08 Comparing candidate commit 3671a27 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 57 metrics, 2 unstable metrics. CandidateCandidate benchmark detailsGroup 1
Group 2
Group 3
Group 4
Group 5
Group 6
Group 7
Group 8
Group 9
Group 10
Group 11
Group 12
Group 13
Group 14
Group 15
Group 16
Group 17
Group 18
Group 19
BaselineOmitted due to size. |
| for file in additional_files { | ||
| let mut encoder = Compressor::<DefaultProfileCodec>::try_new( | ||
| (file.bytes.len() >> 3).next_power_of_two(), | ||
| 10 * 1024 * 1024, | ||
| Profile::COMPRESSION_LEVEL, | ||
| ) | ||
| .context("failed to create compressor")?; | ||
| encoder.write_all(file.bytes)?; | ||
|
|
||
| form = form.part( | ||
| file.name.to_string(), | ||
| reqwest::multipart::Part::bytes(encoder.finish()?).file_name(file.name.to_string()), | ||
| ); | ||
| let mut part = | ||
| reqwest::multipart::Part::bytes(encoder.finish()?).file_name(file.name.to_string()); | ||
| if !matches!(file.mime, MimeType::None) { | ||
| part = part.mime_str(file.mime.as_str())?; | ||
| } | ||
| form = form.part(file.name.to_string(), part); | ||
| } |
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'm still not convinced we're going the right direction here.
As per https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Type :
The HTTP Content-Type representation header is used to indicate the original media type of a resource before any content encoding is applied.
The Content-Type header differs from Content-Encoding in that Content-Encoding helps the recipient understand how to decode data to its original form.
and https://httpwg.org/http-core/draft-ietf-httpbis-semantics-latest.html?#field.content-encoding ...:
Content coding values indicate an encoding transformation that has been or can be applied to a representation. Content codings are primarily used to allow a representation to be compressed or otherwise usefully transformed without losing the identity of its underlying media type and without loss of information. Frequently, the representation is stored in coded form, transmitted directly, and only decoded by the final recipient.
but again I'm not sure this is the correct thing here.
In particular, I don't think "zstandard compression" is something we only do for transport here, since we store these files with this exact compression.
Another reason is -- if json should be content-type json even when compressed, why is the profile not application/protobuf too?
TL;DR: My suggestion is, let's not complicate until we figure out a clear reason to do so -- let's set everything to application/octet-stream and simplify the API and our code. Bonus point, this is one less API breaking change between libdatadog v26 and v27.
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 did some reading and asked GPT about it too. I think these would be the correct headers to send for zstd compressed json:
Content-Type: application/json
Content-Encoding: zstd
The original PR @danielsn opened was to add a mime type because integration tests were failing: #1478. @danielsn, do you remember what test was failing specifically? In the vein of trying to solve problems, I think we should re-examine the original problem, but I believe @ivoanjo is right that application/octet-stream is a generic binary type for when you don't know or don't want to set one.
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.
The key distinction here in the headers (and I was discussing this with @danielsn ) as well, is that Content-Encoding is not an allowed header in a multipart http file upload, as per https://datatracker.ietf.org/doc/html/rfc7578 :
4.8. Other "Content-" Header Fields
The multipart/form-data media type does not support any MIME header
fields in parts other than Content-Type, Content-Disposition, and (in
limited circumstances) Content-Transfer-Encoding. Other header
fields MUST NOT be included and MUST be ignored.
Perhaps Content-Transfer-Encoding could be used, but again, if the previous approach with application/octet-stream has been working fine + simplifies the API, and we're not even sure what a "more correct" solution would be, I'd suggest we go with the simplified take on this.
What does this PR do?
Makes mime type optional for files
Motivation
Allows clients to use it or not as they see fit.
Additional Notes
I made it 0 for the None case so that if you default init the enum in C it works as expected.
How to test the change?
Describe here in detail how the change can be validated.