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

Rate limit #37

Merged
merged 20 commits into from
Feb 15, 2017
Merged

Rate limit #37

merged 20 commits into from
Feb 15, 2017

Conversation

geffzhang
Copy link
Contributor

implement Request Rate limit, this feature is options

@geffzhang geffzhang mentioned this pull request Feb 11, 2017
@TomPallister
Copy link
Member

@geffzhang I will check this soon, thanks for the pull request.

@TomPallister
Copy link
Member

@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.

@geffzhang
Copy link
Contributor Author

@TomPallister yes,acceptance test very useful when refactoring. I have added two test

Copy link
Member

@TomPallister TomPallister left a 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
{
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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);
Copy link
Member

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();
Copy link
Member

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))
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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)
Copy link
Member

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

@@ -37,7 +37,7 @@ public void ConfigureServices(IServiceCollection services)
})
.WithDictionaryHandle();
};

services.AddMemoryCache();
Copy link
Member

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

@geffzhang
Copy link
Contributor Author

OK, changing for the better, consistent coding style

@rigofunc
Copy link

@geffzhang I also think those properties are readonly maybe better(using C# 6 feature).

@TomPallister
Copy link
Member

@xyting 👍

@TomPallister
Copy link
Member

@geffzhang looks good, feel free to merge!

…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
@geffzhang
Copy link
Contributor Author

@TomPallister I have merged code

@TomPallister TomPallister merged commit 9203e7f into ThreeMammals:develop Feb 15, 2017
@geffzhang geffzhang deleted the RateLimit branch February 17, 2017 05:54
@TomPallister TomPallister added this to Done in Ocelot Aug 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants