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

Implement rateLimit configuration #84

Merged
merged 2 commits into from
Sep 13, 2024

Conversation

albertchae
Copy link
Collaborator

Summary

Add rateLimit configuration per https://github.com/inngest/inngest/blob/0ac11f2c312c066e517e53749052dd89fd2926ba/docs/SDK_SPEC.md?plain=1#L586-L606
Very similar to throttle implementation in #66

Checklist

  • Update documentation
  • Added unit/integration tests

Related

Copy link

linear bot commented Sep 11, 2024

@albertchae albertchae marked this pull request as ready for review September 11, 2024 12:10
@albertchae albertchae force-pushed the albert/inn-3332-implement-rate-limit branch from 8d88a7f to c925bd6 Compare September 11, 2024 22:40
Copy link
Collaborator

@KiKoS0 KiKoS0 left a comment

Choose a reason for hiding this comment

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

Looks good 🚀

Thread.sleep(500);
String event3 = InngestFunctionTestHelpers.sendEvent(client, "test/rateLimit").getIds()[0];

Thread.sleep(2000);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we increase the duration similar to idempotency #85?

RateLimitedFunctionIntegrationTest > testFunctionIsRateLimited() FAILED
    java.lang.ArrayIndexOutOfBoundsException: 0
        at com.inngest.springbootdemo.EventRunsResponse.first(EventRunsResponse.java:14)
        at com.inngest.springbootdemo.RateLimitedFunctionIntegrationTest.testFunctionIsRateLimited(RateLimitedFunctionIntegrationTest.java:32)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good idea, increased the two 2000ms waits to 4000ms

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Very similar to throttle implementation in #66
@albertchae albertchae force-pushed the albert/inn-3332-implement-rate-limit branch from c925bd6 to ba3587a Compare September 12, 2024 23:44
Comment on lines +23 to +25
// Rate limit test function is limited to 2 over 6 seconds. Based on the simplistic description of GCRA in
// https://www.inngest.com/docs/guides/rate-limiting#how-rate-limiting-works
// we need to sleep at least 3 seconds here for the second event not to get rate limited
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This test was buggy before instead of just being flaky. After reading the documentation at https://www.inngest.com/docs/guides/rate-limiting#how-rate-limiting-works, I adjusted the sleep times for the test to hopefully run more robustly.

// Sleep at least 6 seconds for the rate limit bucket to be completely cleared
Thread.sleep(6000);

// Rate limit should only allow the first 2 events to run
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the function config was mismatched with this comment until now 😭

@albertchae albertchae merged commit 2e01336 into main Sep 13, 2024
9 checks passed
@albertchae albertchae deleted the albert/inn-3332-implement-rate-limit branch September 13, 2024 00:48
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