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

♻️ [RUM-249] update worker protocol #2346

Merged
merged 15 commits into from Jul 25, 2023

Conversation

BenoitZugmeyer
Copy link
Member

@BenoitZugmeyer BenoitZugmeyer commented Jul 20, 2023

Motivation

Adjust the Worker protocol to prepare for RUM/Logs data compression

Changes

Lots of changes discussed in the RFC. Commits are self-contained, please review commit by commit.

Note: changes in segment.ts will be extracted to a DeflateWorker in a next PR

Testing

  • Local
  • Staging
  • Unit
  • End to end

I have gone over the contributing documentation.

@codecov-commenter
Copy link

codecov-commenter commented Jul 20, 2023

Codecov Report

Merging #2346 (dd5c779) into main (e344f34) will increase coverage by 0.00%.
The diff coverage is 96.20%.

@@           Coverage Diff           @@
##             main    #2346   +/-   ##
=======================================
  Coverage   94.17%   94.18%           
=======================================
  Files         206      207    +1     
  Lines        6134     6176   +42     
  Branches     1358     1367    +9     
=======================================
+ Hits         5777     5817   +40     
- Misses        357      359    +2     
Impacted Files Coverage Δ
packages/worker/src/boot/startWorker.ts 90.90% <90.62%> (ø)
packages/core/src/domain/telemetry/telemetry.ts 96.22% <100.00%> (ø)
packages/core/src/tools/utils/byteUtils.ts 94.11% <100.00%> (+5.22%) ⬆️
...ckages/rum/src/domain/segmentCollection/segment.ts 98.03% <100.00%> (+0.74%) ⬆️
...src/domain/segmentCollection/startDeflateWorker.ts 100.00% <100.00%> (ø)
packages/rum/test/mockWorker.ts 98.21% <100.00%> (-0.36%) ⬇️

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@BenoitZugmeyer BenoitZugmeyer marked this pull request as ready for review July 20, 2023 15:19
@BenoitZugmeyer BenoitZugmeyer requested review from a team as code owners July 20, 2023 15:19
}
}

function concatBuffers(buffers: Uint8Array[]) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 thought: ‏this function is needed in both the worker and RUM. I duplicated it, it's not great, but it avoids adding a dependency between the worker code and main packages. Maybe the worker can expose some utility function like that, but we'd need to ensure that it is tree-shakable to a pulling too much of the worker code in main packages.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be simpler if the utility code was exposed from core?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try it. I put it in core, so now the worker depends on core. I was hesitating about it, because in the future core might very well depend on the worker. We'll see how it goes!

This makes tests impler as they are now synchronous, and will allow to
test more scenarios
@BenoitZugmeyer
Copy link
Member Author

/to-staging

@dd-devflow
Copy link

dd-devflow bot commented Jul 24, 2023

🚂 Branch Integration: starting soon, merge in < 0s

commit 093e058d0d will soon be integrated into staging-30.

This build is going to start soon! (estimated merge in less than 0s)

you can cancel this operation by commenting your pull request with /to-staging -c!

@dd-devflow
Copy link

dd-devflow bot commented Jul 24, 2023

🚂 Branch Integration: this commit was successfully integrated

Commit 093e058d0d has been merged into staging-30 in merge commit b8fa9dfdec.

Check out the triggered pipeline on Gitlab 🦊

Comment on lines +89 to +106
/**
* Creates a buffer of bytes to append to the end of the Zlib stream to finish it. It is composed of
* two parts:
* * an empty deflate block as specified in https://www.rfc-editor.org/rfc/rfc1951.html#page-13 ,
* which happens to be always 3, 0
* * an adler32 checksum as specified in https://www.rfc-editor.org/rfc/rfc1950.html#page-4
*
* This is essentially what pako writes to the stream when invoking `deflate.push('',
* constants.Z_FINISH)` operation after some data has been pushed with "Z_SYNC_FLUSH", but doing so
* ends the stream and no more data can be pushed into it.
*
* Since we want to let the main thread end the stream synchronously at any point without needing to
* send a message to the worker to flush it, we send back a trailer in each "wrote" response so the
* main thread can just append it to the compressed data to end the stream.
*
* Beside creating a valid zlib stream, those 6 bits are expected to be here so the Datadog backend
* can merge streams together (see internal doc).
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏 praise: ‏🤩

@BenoitZugmeyer BenoitZugmeyer merged commit 6bec25a into main Jul 25, 2023
17 checks passed
@BenoitZugmeyer BenoitZugmeyer deleted the benoit/update-worker-protocol branch July 25, 2023 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants