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

feat(utils): Introduce rate limit helpers #4685

Merged
merged 12 commits into from
Mar 7, 2022
Merged

Conversation

AbhiPrasad
Copy link
Member

@AbhiPrasad AbhiPrasad commented Mar 4, 2022

Ref: #4660

As we move toward introducing a new transport API, the first step is to validate rate-limiting logic. We do this by creating a new set of functional helpers that mutate a rate limits object.

In 5 seconds I will link a PR that does this conversion in browser.

All credits to @kamilogorek as 95% of this is from v7-dev!

Resolves https://getsentry.atlassian.net/browse/WEB-660

@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2022

size-limit report

Path Base Size (845aada) Current Size Change
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 19.8 KB 19.79 KB -0.02% 🔽
@sentry/browser - ES5 CDN Bundle (minified) 63.37 KB 63.38 KB +0.02% 🔺
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 18.44 KB 18.44 KB -0.03% 🔽
@sentry/browser - ES6 CDN Bundle (minified) 56.41 KB 56.41 KB -0.02% 🔽
@sentry/browser - Webpack (gzipped + minified) 22.27 KB 22.27 KB 0%
@sentry/browser - Webpack (minified) 76.33 KB 76.34 KB +0.02% 🔺
@sentry/react - Webpack (gzipped + minified) 22.3 KB 22.3 KB +0.01% 🔺
@sentry/nextjs Client - Webpack (gzipped + minified) 46.44 KB 46.43 KB -0.03% 🔽
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 26.69 KB 26.68 KB -0.01% 🔽
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 25.02 KB 25.01 KB -0.02% 🔽

Copy link
Member

@lobsterkatie lobsterkatie left a comment

Choose a reason for hiding this comment

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

A few naming nits, but otherwise looks good!

};
const headers = {};
const updatedRateLimits = updateRateLimits(rateLimits, headers);
expect(rateLimits).toStrictEqual(updatedRateLimits);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
expect(rateLimits).toStrictEqual(updatedRateLimits);
expect(updatedRateLimits).toStrictEqual(rateLimits);

Our expectation is, effectively, "the result will be correct," so I think it makes more sense to swap these. Also, I'm curious why you're using strict equal here over equal. Are you testing that they didn't get converted to strings?

Copy link
Member Author

Choose a reason for hiding this comment

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

updatedRateLimits and rateLimits should be rate limits objects. I guess we don't need the undefined checks from toStrictEqual, I'll just update it

packages/utils/test/ratelimit.test.ts Outdated Show resolved Hide resolved
packages/utils/test/ratelimit.test.ts Outdated Show resolved Hide resolved
packages/utils/test/ratelimit.test.ts Outdated Show resolved Hide resolved
Comment on lines 55 to 56
const rlHeader = headers['x-sentry-rate-limits'];
const raHeader = headers['retry-after'];
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const rlHeader = headers['x-sentry-rate-limits'];
const raHeader = headers['retry-after'];
const rateLimitHeader = headers['x-sentry-rate-limits'];
const retryAfterHeader = headers['retry-after'];

You know me and spelling things out... 😛

AbhiPrasad and others added 4 commits March 7, 2022 07:53
Co-authored-by: Katie Byers <lobsterkatie@gmail.com>
Co-authored-by: Katie Byers <lobsterkatie@gmail.com>
Co-authored-by: Katie Byers <lobsterkatie@gmail.com>
@AbhiPrasad AbhiPrasad enabled auto-merge (squash) March 7, 2022 13:02
@AbhiPrasad AbhiPrasad merged commit 61c79ef into master Mar 7, 2022
@AbhiPrasad AbhiPrasad deleted the abhi-rate-limit-helpers branch March 7, 2022 13:09
AbhiPrasad added a commit that referenced this pull request Mar 14, 2022
This patch converts the browser based transport to use the ratelimit helpers introduced in #4685
@AbhiPrasad AbhiPrasad added this to the Pre 7.0.0 Work milestone Mar 23, 2022
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.

2 participants