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(ratelimits): Add metric buckets rate limit #11506

Merged
merged 4 commits into from Apr 10, 2024

Conversation

s1gr1d
Copy link
Member

@s1gr1d s1gr1d commented Apr 9, 2024

closes #11336

@s1gr1d s1gr1d requested a review from AbhiPrasad April 9, 2024 12:14
@s1gr1d s1gr1d marked this pull request as draft April 9, 2024 12:15
Copy link
Contributor

github-actions bot commented Apr 9, 2024

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay, Feedback) - Webpack (gzipped) 80.56 KB (+0.1% 🔺)
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 71.55 KB (+0.11% 🔺)
@sentry/browser (incl. Tracing, Replay with Canvas) - Webpack (gzipped) 75.57 KB (+0.11% 🔺)
@sentry/browser (incl. Tracing, Replay) - Webpack with treeshaking flags (gzipped) 65.18 KB (+0.12% 🔺)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 35.49 KB (+0.24% 🔺)
@sentry/browser (incl. browserTracingIntegration) - Webpack (gzipped) 35.37 KB (+0.24% 🔺)
@sentry/browser (incl. Feedback) - Webpack (gzipped) 31.55 KB (+0.11% 🔺)
@sentry/browser (incl. sendFeedback) - Webpack (gzipped) 31.56 KB (+0.11% 🔺)
@sentry/browser - Webpack (gzipped) 22.78 KB (+0.18% 🔺)
@sentry/browser (incl. Tracing, Replay, Feedback) - ES6 CDN Bundle (gzipped) 78.67 KB (+0.11% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 70.04 KB (+0.11% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 35.82 KB (+0.16% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped) 25.2 KB (+0.13% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 220.48 KB (+0.08% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 108.29 KB (+0.16% 🔺)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 75.55 KB (+0.1% 🔺)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 39.06 KB (+0.18% 🔺)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 72.03 KB (+0.1% 🔺)
@sentry/react - Webpack (gzipped) 22.81 KB (+0.18% 🔺)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 89.87 KB (+0.07% 🔺)
@sentry/nextjs Client - Webpack (gzipped) 54.01 KB (+0.12% 🔺)
@sentry-internal/feedback - Webpack (gzipped) 17.3 KB (0%)

@s1gr1d s1gr1d requested a review from cleptric April 9, 2024 13:44
Base automatically changed from sig-remove-statsd to v7 April 9, 2024 15:02
@s1gr1d s1gr1d force-pushed the sig-metric-buckets-rate-limit branch from b44c390 to 945c6e5 Compare April 9, 2024 15:10
@s1gr1d s1gr1d marked this pull request as ready for review April 9, 2024 15:10
@@ -85,7 +85,16 @@ export function updateRateLimits(
updatedRateLimits.all = now + delay;
} else {
for (const category of categories.split(';')) {
updatedRateLimits[category] = now + delay;
if (category === 'metric_bucket') {
const namespaces = limit.split(':', 5)[4] ? limit.split(':', 5)[4].split(';') : null;
Copy link
Member

Choose a reason for hiding this comment

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

can we combine this limit.split call with the one above in const [retryAfter, categories]?

also generally we prefer against using null, undefined is returned by default when array access returns nothing, and it helps reduce bundle size generally.


if (!namespaces || namespaces.includes('custom')) {
// back off transmitting metrics from the SDK
updatedRateLimits[category] = now + delay;
Copy link
Member

Choose a reason for hiding this comment

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

this is the same as line 96, can we merge the logic somehow?

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 added all in one if statement. But as it is not so clear anymore that 'metric_bucket' actually is the category when namespaces is defined, I added a comment that explains it :)

Comment on lines 88 to 91
// namespaces will be present when category === 'metric_bucket'
if (category !== 'metric_bucket' || !namespaces || namespaces.split(';').includes('custom')) {
updatedRateLimits[category] = now + delay;
}
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
// namespaces will be present when category === 'metric_bucket'
if (category !== 'metric_bucket' || !namespaces || namespaces.split(';').includes('custom')) {
updatedRateLimits[category] = now + delay;
}
if (category === 'metric_bucket') {
// namespaces will be present when category === 'metric_bucket'
if (!namespaces || namespaces.split(';').includes('custom')) {
updatedRateLimits[category] = now + delay;
}
} else {
updatedRateLimits[category] = now + delay;
}

This is giga nitting but I would do it like this. Regardless of bundlesize (hoping terser is smart enough). Makes it easier to understand this admittedly convoluted logic.

@@ -197,3 +197,35 @@ describe('updateRateLimits()', () => {
expect(updatedRateLimits.all).toEqual(60_000);
});
});

describe('data category "metric_bucket"', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Let's add another test case for 2700:metric_bucket:organization:quota_exceeded:

@s1gr1d s1gr1d enabled auto-merge (squash) April 10, 2024 12:16
@s1gr1d s1gr1d merged commit ab40116 into v7 Apr 10, 2024
103 checks passed
@s1gr1d s1gr1d deleted the sig-metric-buckets-rate-limit branch April 10, 2024 12:44
@AbhiPrasad AbhiPrasad mentioned this pull request Apr 10, 2024
s1gr1d added a commit that referenced this pull request Apr 11, 2024
cadesalaberry pushed a commit to cadesalaberry/sentry-javascript that referenced this pull request Apr 19, 2024
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

3 participants