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

[API Proposal]: RateLimitPartition rename Create methods #71352

Closed
BrennanConroy opened this issue Jun 27, 2022 · 2 comments · Fixed by #72054
Closed

[API Proposal]: RateLimitPartition rename Create methods #71352

BrennanConroy opened this issue Jun 27, 2022 · 2 comments · Fixed by #72054
Labels
api-approved API was approved in API review, it can be implemented area-System.Threading
Milestone

Comments

@BrennanConroy
Copy link
Member

Background and motivation

As part of #65400 we made a RateLimitPartition API which holds information about a partitions key and a factory to create a RateLimiter if the partition isn't currently instantiated.

The current API is RateLimitPartition.Create<TKey>(TKey partitionKey, Func<TKey, RateLimiter> factory) and .CreateConcurrencyLimiter<TKey>(...) .CreateNoLimiter<TKey>(...) etc. for specific limiters we provide. The concern is that the "Create" names imply the limiters are being created every time the RateLimitPartition.Create(...) method is called which isn't true.

We would like to propose renaming these methods to try to be clearer that it's a partition identifier+creator that is being created.

API Proposal

namespace System.Threading.RateLimiting;

public static class RateLimitPartition
{
-    public static RateLimitPartition<TKey> Create<TKey>(
+    public static RateLimitPartition<TKey> Define<TKey>(
        TKey partitionKey,
        Func<TKey, RateLimiter> factory)
    {
    }

-    public static RateLimitPartition<TKey> CreateConcurrencyLimiter<TKey>(
+    public static RateLimitPartition<TKey> DefineConcurrencyLimiter<TKey>(
        TKey partitionKey,
        Func<TKey, ConcurrencyLimiterOptions> factory)
    {
    }

-    public static RateLimitPartition<TKey> CreateNoLimiter<TKey>(TKey partitionKey)
+    public static RateLimitPartition<TKey> DefineNoLimiter<TKey>(TKey partitionKey)
    {
    }

-    public static RateLimitPartition<TKey> CreateTokenBucketLimiter<TKey>(
+    public static RateLimitPartition<TKey> DefineTokenBucketLimiter<TKey>(
        TKey partitionKey,
        Func<TKey, TokenBucketRateLimiterOptions> factory)
    {
    }

-    public static RateLimitPartition<TKey> CreateSlidingWindowLimiter<TKey>(
+    public static RateLimitPartition<TKey> DefineSlidingWindowLimiter<TKey>(
        TKey partitionKey,
        Func<TKey, SlidingWindowRateLimiterOptions> factory)
    {
    }

-    public static RateLimitPartition<TKey> CreateFixedWindowLimiter<TKey>(
+    public static RateLimitPartition<TKey> DefineFixedWindowLimiter<TKey>(
        TKey partitionKey,
        Func<TKey, FixedWindowRateLimiterOptions> factory)
    {
    }

API Usage

PartitionedRateLimiter<string> limiter = PartitionedRateLimiter.Create<string, string>(resource =>
{
    switch (resource)
    {
        case "Policy1":
            return RateLimitPartition.DefineConcurrencyLimiter(resource, _ => new ConcurrencyLimiterOptions(...));
        case "Policy2":
            return RateLimitPartition.DefineTokenBucketLimiter(resource, _ => new TokenBucketRateLimiterOptions(...));
        default:
            return RateLimitPartition.Define(resource, _ => new CustomLimiter(...));
    }
});

RateLimitLease lease = limiter.Acquire("Policy1");
// etc.

Alternative Designs

+    public static RateLimitPartition<TKey> Choose<TKey>(...);
+    public static RateLimitPartition<TKey> ChooseConcurrencyLimiter<TKey>(...);
+    public static RateLimitPartition<TKey> ChooseNoLimiter<TKey>(...);

+    public static RateLimitPartition<TKey> With<TKey>(...);
+    public static RateLimitPartition<TKey> WithConcurrencyLimiter<TKey>(...);
+    public static RateLimitPartition<TKey> WithNoLimiter<TKey>(...);

+    public static RateLimitPartition<TKey> DefinePartition<TKey>(...);
+    public static RateLimitPartition<TKey> DefineConcurrencyLimiterPartition<TKey>(...);
+    public static RateLimitPartition<TKey> DefineNoLimiterPartition<TKey>(...);

+    public static RateLimitPartition<TKey> GetOrCreate<TKey>(...);
+    public static RateLimitPartition<TKey> GetOrCreateConcurrencyLimiter<TKey>(...);
+    public static RateLimitPartition<TKey> GetOrCreateNoLimiter<TKey>(...);

Risks

No response

@BrennanConroy BrennanConroy added api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Threading labels Jun 27, 2022
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jun 27, 2022
@ghost
Copy link

ghost commented Jun 27, 2022

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

Issue Details

Background and motivation

As part of #65400 we made a RateLimitPartition API which holds information about a partitions key and a factory to create a RateLimiter if the partition isn't currently instantiated.

The current API is RateLimitPartition.Create<TKey>(TKey partitionKey, Func<TKey, RateLimiter> factory) and .CreateConcurrencyLimiter<TKey>(...) .CreateNoLimiter<TKey>(...) etc. for specific limiters we provide. The concern is that the "Create" names imply the limiters are being created every time the RateLimitPartition.Create(...) method is called which isn't true.

We would like to propose renaming these methods to try to be clearer that it's a partition identifier+creator that is being created.

API Proposal

namespace System.Threading.RateLimiting;

public static class RateLimitPartition
{
-    public static RateLimitPartition<TKey> Create<TKey>(
+    public static RateLimitPartition<TKey> Define<TKey>(
        TKey partitionKey,
        Func<TKey, RateLimiter> factory)
    {
    }

-    public static RateLimitPartition<TKey> CreateConcurrencyLimiter<TKey>(
+    public static RateLimitPartition<TKey> DefineConcurrencyLimiter<TKey>(
        TKey partitionKey,
        Func<TKey, ConcurrencyLimiterOptions> factory)
    {
    }

-    public static RateLimitPartition<TKey> CreateNoLimiter<TKey>(TKey partitionKey)
+    public static RateLimitPartition<TKey> DefineNoLimiter<TKey>(TKey partitionKey)
    {
    }

-    public static RateLimitPartition<TKey> CreateTokenBucketLimiter<TKey>(
+    public static RateLimitPartition<TKey> DefineTokenBucketLimiter<TKey>(
        TKey partitionKey,
        Func<TKey, TokenBucketRateLimiterOptions> factory)
    {
    }

-    public static RateLimitPartition<TKey> CreateSlidingWindowLimiter<TKey>(
+    public static RateLimitPartition<TKey> DefineSlidingWindowLimiter<TKey>(
        TKey partitionKey,
        Func<TKey, SlidingWindowRateLimiterOptions> factory)
    {
    }

-    public static RateLimitPartition<TKey> CreateFixedWindowLimiter<TKey>(
+    public static RateLimitPartition<TKey> DefineFixedWindowLimiter<TKey>(
        TKey partitionKey,
        Func<TKey, FixedWindowRateLimiterOptions> factory)
    {
    }

API Usage

PartitionedRateLimiter<string> limiter = PartitionedRateLimiter.Create<string, string>(resource =>
{
    switch (resource)
    {
        case "Policy1":
            return RateLimitPartition.DefineConcurrencyLimiter(resource, _ => new ConcurrencyLimiterOptions(...));
        case "Policy2":
            return RateLimitPartition.DefineTokenBucketLimiter(resource, _ => new TokenBucketRateLimiterOptions(...));
        default:
            return RateLimitPartition.Define(resource, _ => new CustomLimiter(...));
    }
});

RateLimitLease lease = limiter.Acquire("Policy1");
// etc.

Alternative Designs

+    public static RateLimitPartition<TKey> Choose<TKey>(...);
+    public static RateLimitPartition<TKey> ChooseConcurrencyLimiter<TKey>(...);
+    public static RateLimitPartition<TKey> ChooseNoLimiter<TKey>(...);

+    public static RateLimitPartition<TKey> With<TKey>(...);
+    public static RateLimitPartition<TKey> WithConcurrencyLimiter<TKey>(...);
+    public static RateLimitPartition<TKey> WithNoLimiter<TKey>(...);

+    public static RateLimitPartition<TKey> DefinePartition<TKey>(...);
+    public static RateLimitPartition<TKey> DefineConcurrencyLimiterPartition<TKey>(...);
+    public static RateLimitPartition<TKey> DefineNoLimiterPartition<TKey>(...);

+    public static RateLimitPartition<TKey> GetOrCreate<TKey>(...);
+    public static RateLimitPartition<TKey> GetOrCreateConcurrencyLimiter<TKey>(...);
+    public static RateLimitPartition<TKey> GetOrCreateNoLimiter<TKey>(...);

Risks

No response

Author: BrennanConroy
Assignees: -
Labels:

api-suggestion, area-System.Threading

Milestone: -

@BrennanConroy BrennanConroy added api-ready-for-review API is ready for review, it is NOT ready for implementation blocking Marks issues that we want to fast track in order to unblock other important work and removed api-suggestion Early API idea and discussion, it is NOT ready for implementation labels Jun 27, 2022
@mangod9 mangod9 removed the untriaged New issue has not been triaged by the area owner label Jul 7, 2022
@mangod9 mangod9 added this to the 7.0.0 milestone Jul 7, 2022
@terrajobst
Copy link
Member

terrajobst commented Jul 12, 2022

Video

  • Let' use Get
namespace System.Threading.RateLimiting;

public static class RateLimitPartition
{
-    public static RateLimitPartition<TKey> Create<TKey>(
+    public static RateLimitPartition<TKey> Get<TKey>(
        TKey partitionKey,
        Func<TKey, RateLimiter> factory)
    {
    }

-    public static RateLimitPartition<TKey> CreateConcurrencyLimiter<TKey>(
+    public static RateLimitPartition<TKey> GetConcurrencyLimiter<TKey>(
        TKey partitionKey,
        Func<TKey, ConcurrencyLimiterOptions> factory)
    {
    }

-    public static RateLimitPartition<TKey> CreateNoLimiter<TKey>(TKey partitionKey)
+    public static RateLimitPartition<TKey> GetNoLimiter<TKey>(TKey partitionKey)
    {
    }

-    public static RateLimitPartition<TKey> CreateTokenBucketLimiter<TKey>(
+    public static RateLimitPartition<TKey> GetTokenBucketLimiter<TKey>(
        TKey partitionKey,
        Func<TKey, TokenBucketRateLimiterOptions> factory)
    {
    }

-    public static RateLimitPartition<TKey> CreateSlidingWindowLimiter<TKey>(
+    public static RateLimitPartition<TKey> GetSlidingWindowLimiter<TKey>(
        TKey partitionKey,
        Func<TKey, SlidingWindowRateLimiterOptions> factory)
    {
    }

-    public static RateLimitPartition<TKey> CreateFixedWindowLimiter<TKey>(
+    public static RateLimitPartition<TKey> GetFixedWindowLimiter<TKey>(
        TKey partitionKey,
        Func<TKey, FixedWindowRateLimiterOptions> factory)
    {
    }

@terrajobst terrajobst added api-approved API was approved in API review, it can be implemented and removed api-ready-for-review API is ready for review, it is NOT ready for implementation labels Jul 12, 2022
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jul 12, 2022
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jul 13, 2022
@BrennanConroy BrennanConroy removed the blocking Marks issues that we want to fast track in order to unblock other important work label Jul 13, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Aug 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-approved API was approved in API review, it can be implemented area-System.Threading
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants