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

⚗️ ✨ [RUMF-1530] send replay metadata as json #2125

Merged
merged 11 commits into from
Apr 17, 2023

Conversation

BenoitZugmeyer
Copy link
Member

@BenoitZugmeyer BenoitZugmeyer commented Mar 30, 2023

Motivation

Send Replay metadata as JSON instead of individual multipart entries to make it easier to extend.

Changes

Reading metadata from Replay payloads will need to be asynchronous, because we are using a Blob to set the entry content type to application/json. Thus, a large part of the PR focuses on preparing the tests for this change.

Then, we actually send the metadata as JSON

Finally, we add the compressed_segment_size to avoid needing custom backend code.

Testing

  • Local
  • Staging
  • Unit
  • End to end

I have gone over the contributing documentation.

@codecov-commenter
Copy link

codecov-commenter commented Mar 30, 2023

Codecov Report

Merging #2125 (6d439e5) into main (4ad4ba4) will increase coverage by 0.07%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #2125      +/-   ##
==========================================
+ Coverage   93.56%   93.64%   +0.07%     
==========================================
  Files         179      180       +1     
  Lines        5985     6011      +26     
  Branches     1342     1347       +5     
==========================================
+ Hits         5600     5629      +29     
+ Misses        385      382       -3     
Impacted Files Coverage Δ
...e/src/domain/configuration/experimentalFeatures.ts 100.00% <100.00%> (ø)
...src/domain/segmentCollection/buildReplayPayload.ts 100.00% <100.00%> (ø)
packages/rum/test/readReplayPayload.ts 100.00% <100.00%> (ø)

... and 2 files with indirect coverage changes

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

@BenoitZugmeyer BenoitZugmeyer force-pushed the benoit/send-replay-metadata-as-json branch from 8146e37 to f065346 Compare March 30, 2023 18:07
@BenoitZugmeyer BenoitZugmeyer force-pushed the benoit/send-replay-metadata-as-json branch from 5ffb0ea to 04c4b04 Compare March 31, 2023 09:02
@BenoitZugmeyer BenoitZugmeyer marked this pull request as ready for review March 31, 2023 09:44
@BenoitZugmeyer BenoitZugmeyer requested review from a team as code owners March 31, 2023 09:44
packages/rum/test/readReplayPayload.ts Outdated Show resolved Hide resolved
Copy link
Member Author

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

This commit introduces an experimental feature flag for sending replay
payloads as JSON. It restores a few unit and e2e tests, and adjusts the
way we read metadata in tests to work in both ways.
})
done()
const requests = await readSentRequests(1)
expect(requests[0].segment).toEqual(jasmine.any(Object))
Copy link
Contributor

Choose a reason for hiding this comment

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

question: this is supposed to be binary data no?
thought: I am surprise it matches the Object predicate?

Copy link
Member Author

Choose a reason for hiding this comment

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

readSentRequests is using readReplayPayload, which is a helper to read the FormData that is sent and decode/deserialize it.

Copy link
Contributor

Choose a reason for hiding this comment

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

praise: much nicer with async/await than done

})
})

describe('without replay_json_payload experimental flag', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion(not-blocking): if possible maybe add disableExperimentalFeatures([ExperimentalFeature.REPLAY_JSON_PAYLOAD]) or a reset to make the label of the describe explicit and no relying on default value on the reset of the previous tests

Copy link
Member Author

Choose a reason for hiding this comment

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

All tests rely on a default state. This default state needs to be reset at the end of each test, else everything would be impredictable, especially because we are using a randomized test execution order.

}
}

return readJsonBlob((payload.data as FormData).get('event') as Blob) as Promise<BrowserSegmentMetadataAndSegmentSizes>
Copy link
Contributor

Choose a reason for hiding this comment

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

question: why not cast in the resolve function in readJsonBlob?

Copy link
Member Author

Choose a reason for hiding this comment

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

You mean, something like this?

function readJsonBlob<T>() {
  return new Promise<T>(...)
}

The end result is indeed the same, but the cast would be implicit. I'd rather have readJsonBlob(): Promise<unknown>, which provide no guarantee about the returned type, and then let the caller take the responsibility to ducktype it or cast it. But I agree the syntax is a bit more verbose.

Copy link
Contributor

Choose a reason for hiding this comment

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

this would not work?

resolve(deserialized as BrowserSegmentMetadataAndSegmentSizes)

Copy link
Member Author

Choose a reason for hiding this comment

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

readJsonBlob() is used two times with different return types

@BenoitZugmeyer BenoitZugmeyer merged commit d1a4ae3 into main Apr 17, 2023
2 checks passed
@BenoitZugmeyer BenoitZugmeyer deleted the benoit/send-replay-metadata-as-json branch April 17, 2023 13:03
@BenoitZugmeyer BenoitZugmeyer changed the title ✨ [RUMF-1530] send replay metadata as json ⚗️ ✨ [RUMF-1530] send replay metadata as json Apr 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants