-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Rate limit #37
Rate limit #37
Conversation
merge current code
merge servicediscovery
Merge CircuitBreakerPattern
@geffzhang I will check this soon, thanks for the pull request. |
@geffzhang Looks really good 👍, maybe we could add an acceptance test that shows the rate limiting is working end to end. I find acceptance tests very useful when refactoring. |
@TomPallister yes,acceptance test very useful when refactoring. I have added two test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@geffzhang pull request is very good! Thank you. I have left some comments please check them.
} | ||
|
||
public class RateLimitRule | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this class be changed so that it's properties are {get; private set;} when constructing an object I prefer that it's properties cannot be changed.
/// <summary> | ||
/// Stores the initial access time and the numbers of calls made from that point | ||
/// </summary> | ||
public struct RateLimitCounter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can these properties be {get;private set}
|
||
namespace Ocelot.RateLimit | ||
{ | ||
public class RateLimitHeaders |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can these properties be {get;private set}
public string RetryAfterFrom(DateTime timestamp, RateLimitRule rule) | ||
{ | ||
var secondsPast = Convert.ToInt32((DateTime.UtcNow - timestamp).TotalSeconds); | ||
var retryAfter = Convert.ToInt32(rule.PeriodTimespan.Value.TotalSeconds); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe check this is not null before operation or change property so it is not nullable.
} | ||
|
||
return headers; | ||
throw new NotImplementedException(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably remove this
|
||
public bool IsWhitelisted(ClientRequestIdentity requestIdentity, RateLimitOptions option) | ||
{ | ||
if (option.ClientWhitelist != null && option.ClientWhitelist.Contains(requestIdentity.ClientId)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we set this list always then it cannot be null and we dont need to check here
@@ -0,0 +1,11 @@ | |||
namespace Ocelot.RateLimit | |||
{ | |||
public class ClientRequestIdentity |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the properties of this class be {get;private set;}
|
||
namespace Ocelot.AcceptanceTests | ||
{ | ||
public class ClientRateLimitTests : IDisposable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need one more acceptance test that checks if rate limiting is set the first request is not accidentally rate limited. The test should_call_withratelimiting() only checks the last reponse was rate limited. Perhaps we should check each response to make sure it is what we expect.
_builder.Start(); | ||
} | ||
|
||
//private void GetApiRateLimait(string url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should remove commented out code
test/Ocelot.ManualTest/Startup.cs
Outdated
@@ -37,7 +37,7 @@ public void ConfigureServices(IServiceCollection services) | |||
}) | |||
.WithDictionaryHandle(); | |||
}; | |||
|
|||
services.AddMemoryCache(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is required for rate limiting to work maybe we should add it in ServiceCollectionExtensions.AddOcelot
OK, changing for the better, consistent coding style |
@geffzhang I also think those properties are readonly maybe better(using C# 6 feature). |
@xyting 👍 |
@geffzhang looks good, feel free to merge! |
Merge Newest code
…imit # Conflicts: # src/Ocelot/Configuration/Builder/ReRouteBuilder.cs # src/Ocelot/Configuration/Creator/FileOcelotConfigurationCreator.cs # src/Ocelot/Configuration/QoSOptions.cs # src/Ocelot/Configuration/ReRoute.cs # test/Ocelot.AcceptanceTests/configuration.json
@TomPallister I have merged code |
implement Request Rate limit, this feature is options