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

refactor: Use fetch instead of XHR for forwarding stats uploads #904

Merged
merged 4 commits into from
Sep 3, 2024

Conversation

rmi22186
Copy link
Member

Instructions

  1. PR target branch should be against development
  2. PR title name should follow this format: https://github.com/mParticle/mparticle-workflows/blob/main/.github/workflows/pr-title-check.yml
  3. PR branch prefix should follow this format: https://github.com/mParticle/mparticle-workflows/blob/main/.github/workflows/pr-branch-check-name.yml

Summary

This PR prioritizes using fetch in when sending forwarding stats to mParticle servers. XHR is used as a fallback.

Testing Plan

  • Was this tested locally? If not, explain why. Updated unit test. Tested on local app using fetch, and then deleting window.fetch in order to test XHR fallback.
  • {explain how this has been tested, and what, if any, additional testing should be done}

Reference Issue (For mParticle employees only. Ignore if you are an outside contributor)

src/apiClient.ts Show resolved Hide resolved
src/apiClient.ts Outdated
mid: number;
esid: number;
n: string;
attrs: Dictionary<any>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's avoid using any. Either we should make a type for this attribute, or use Record<string, string> if it's a simple key/value pair. I would prefer the former if there are a specific attributes that must be passed.

src/apiClient.ts Outdated
Comment on lines 183 to 185
this.sendSingleForwardingStatsToServer = async (
forwardingStatsData: IForwardingStatsData
) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
this.sendSingleForwardingStatsToServer = async (
forwardingStatsData: IForwardingStatsData
) => {
this.sendSingleForwardingStatsToServer = async (
forwardingStatsData: IForwardingStatsData
): void => {

Copy link
Member Author

Choose a reason for hiding this comment

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

i ended up moving this to the forwarder.js file, so we lost the typing here. it seemed to fit better there logically, but i can revert if you think keeping the types is more important than organization

src/apiClient.ts Outdated Show resolved Hide resolved
src/apiClient.ts Outdated Show resolved Hide resolved
test/src/tests-forwarders.js Outdated Show resolved Hide resolved
src/apiClient.ts Outdated Show resolved Hide resolved
src/apiClient.ts Outdated Show resolved Hide resolved
src/apiClient.ts Outdated Show resolved Hide resolved
src/apiClient.ts Outdated Show resolved Hide resolved
src/forwarders.js Show resolved Hide resolved
Co-authored-by: Alex S <49695018+alexs-mparticle@users.noreply.github.com>
Copy link

sonarcloud bot commented Aug 23, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
5.2% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

@alexs-mparticle alexs-mparticle added wait to merge refactor Changes to the structure of the code labels Aug 29, 2024
@rmi22186 rmi22186 merged commit 29b835f into development Sep 3, 2024
25 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Changes to the structure of the code wait to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants