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

ratelimits: Implement batched Spends and Refunds #7143

Merged
merged 16 commits into from
Dec 7, 2023

Conversation

beautifulentropy
Copy link
Member

@beautifulentropy beautifulentropy commented Nov 7, 2023

  • Move default and override limits, and associated methods, out of the Limiter to new limitRegistry struct, embedded in a new public TransactionBuilder.
  • Export Transaction and add corresponding Transaction constructor methods for each limit Name, making Limiter and TransactionBuilder the API for interacting with the ratelimits package.
  • Implement batched Spends and Refunds on the Limiter, the new methods accept a slice of Transactions.
  • Add new boolean fields check and spend to Transaction to support more complicated cases that can arise in batches:
    1. the InvalidAuthorizations limit is checked at New Order time in a batch with many other limits, but should only be spent when an Authorization is first considered invalid.
    2. the CertificatesPerDomain limit is overridden by CertficatesPerDomainPerAccount, when this is the case, spends of the CertificatesPerDomain limit should be "best-effort" but NOT deny the request if capacity is lacking.
  • Modify the existing Spend/Refund methods to support Transaction.check/spend and 0 cost Transactions.
  • Make bucketId private and add a constructor for each bucket key format supported by ratelimits.
  • Move domainsForRateLimiting() from the ra.go to ratelimits. This avoids a circular import issue in ra.go.

Part of #5545


Ideally ratelimits/bucket.go should be renamed ratelimits/transaction.go but that will make the diff harder to review. We can do the rename in a follow-up.

Base automatically changed from ratelimits-qol-and-cleanup to main November 8, 2023 18:29
@beautifulentropy beautifulentropy force-pushed the ratelimits-batch-transactions branch 9 times, most recently from 04a05bd to 6b70047 Compare November 9, 2023 21:50
@beautifulentropy beautifulentropy force-pushed the ratelimits-batch-transactions branch from 6b70047 to c96c473 Compare November 9, 2023 21:52
@beautifulentropy beautifulentropy force-pushed the ratelimits-batch-transactions branch from 996f652 to e1fe8a4 Compare November 9, 2023 22:36
@beautifulentropy beautifulentropy force-pushed the ratelimits-batch-transactions branch from e1fe8a4 to 6f4bd2a Compare November 9, 2023 22:47
@beautifulentropy beautifulentropy force-pushed the ratelimits-batch-transactions branch from 731b8a1 to f8c6528 Compare November 20, 2023 20:20
@beautifulentropy beautifulentropy force-pushed the ratelimits-batch-transactions branch 2 times, most recently from f41cd06 to 14920cd Compare November 20, 2023 20:42
@beautifulentropy beautifulentropy force-pushed the ratelimits-batch-transactions branch from 14920cd to 4e42b79 Compare November 20, 2023 20:43
@beautifulentropy beautifulentropy force-pushed the ratelimits-batch-transactions branch from 0e5b7d5 to 7d2d757 Compare November 21, 2023 21:26
@beautifulentropy beautifulentropy force-pushed the ratelimits-batch-transactions branch 2 times, most recently from fddb710 to 32e393a Compare November 27, 2023 20:16
@beautifulentropy beautifulentropy force-pushed the ratelimits-batch-transactions branch 5 times, most recently from 03136d6 to 798a61f Compare November 27, 2023 21:22
@beautifulentropy beautifulentropy force-pushed the ratelimits-batch-transactions branch from 798a61f to 0adf3fa Compare November 27, 2023 21:27
@beautifulentropy beautifulentropy changed the title ratelimits: Add support for batched Spends and Refunds ratelimits: Implement batched Spends and Refunds Nov 27, 2023
@beautifulentropy beautifulentropy marked this pull request as ready for review November 27, 2023 21:56
@beautifulentropy beautifulentropy requested a review from a team as a code owner November 27, 2023 21:56
ratelimits/bucket.go Outdated Show resolved Hide resolved
ratelimits/bucket.go Outdated Show resolved Hide resolved
ratelimits/bucket.go Outdated Show resolved Hide resolved
ratelimits/bucket.go Outdated Show resolved Hide resolved
Copy link
Contributor

@jsha jsha left a comment

Choose a reason for hiding this comment

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

Partial review but I wanted to get something across the table before the end of the (east coast) day. Will keep reviewing.

ratelimits/limiter.go Outdated Show resolved Hide resolved
ratelimits/limiter.go Outdated Show resolved Hide resolved
ratelimits/limiter.go Outdated Show resolved Hide resolved
ratelimits/limiter.go Outdated Show resolved Hide resolved
ratelimits/limiter.go Outdated Show resolved Hide resolved
ratelimits/limiter.go Show resolved Hide resolved
ratelimits/bucket.go Outdated Show resolved Hide resolved
ratelimits/bucket.go Outdated Show resolved Hide resolved
ratelimits/bucket.go Outdated Show resolved Hide resolved
ratelimits/bucket.go Outdated Show resolved Hide resolved
ratelimits/bucket.go Outdated Show resolved Hide resolved
ratelimits/limit.go Outdated Show resolved Hide resolved
@beautifulentropy beautifulentropy force-pushed the ratelimits-batch-transactions branch from 62ae5a4 to 6f6ec22 Compare December 1, 2023 21:27
@beautifulentropy beautifulentropy requested a review from jsha December 1, 2023 22:20
@beautifulentropy beautifulentropy force-pushed the ratelimits-batch-transactions branch from 941293e to 7fd825b Compare December 1, 2023 22:22
Copy link
Contributor

@jsha jsha left a comment

Choose a reason for hiding this comment

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

Looks great!


tats := make(map[string]time.Time, len(bucketKeys))
for i, result := range results {
tatNano, err := result.(*redis.StringCmd).Int64()
Copy link
Contributor

Choose a reason for hiding this comment

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

Is each result documented to definitely be of type *redis.StringCmd? If not, this should use the , ok type assertion and return error if it's the wrong type.

Copy link
Member Author

@beautifulentropy beautifulentropy Dec 6, 2023

Choose a reason for hiding this comment

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

Correct. Specifically, each executed Pipeline command is documented to return a specific result type:

A few lines above we queue multiple Get() commands:

	pipeline := r.client.Pipeline()
	for _, bucketKey := range bucketKeys {
		pipeline.Get(ctx, bucketKey)
	}

The function signature of the Get() command:

func (redis.StringCmdable).Get(ctx context.Context, key string) *redis.StringCmd


domains = DomainsForRateLimiting([]string{"www.example.com", "example.com", "www.example.co.uk"})
test.AssertDeepEquals(t, domains, []string{"example.co.uk", "example.com"})

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
domains = DomainsForRateLimiting([]string{"example.com", "example.com"})
test.AssertDeepEquals(t, domains, []string{"example.com"})

The function description states that it also de-duplicates the output domains.

@beautifulentropy beautifulentropy merged commit eb49d44 into main Dec 7, 2023
12 checks passed
@beautifulentropy beautifulentropy deleted the ratelimits-batch-transactions branch December 7, 2023 16:56
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.

4 participants