-
When dynamic routing is enabled, as per the document at http://ocelot.readthedocs.io/en/latest/features/servicediscovery.html#dynamic-routing, the ReRoutes in configuration needs to be empty. Also, for features like rate limiting and tracing are only available with ReRoutes config and not dynamic routing. While using Ocelot, we have found dynamic routing to be useful as the microservice registers itself with the Consul agent and the api gateway queries the details from Consul using key. But, we also need to apply rate limiting per microservice when using dynamic routing. Is there any plans to support this or how it should look if anybody would want to implement this? should this rate limiting details be persisted for each downstream? |
Beta Was this translation helpful? Give feedback.
Replies: 13 comments
-
Hi @Rohitwagh thanks for your interest in the project. Ocelot does currently support rate limiting with dynamic routing as per the docs here. You can add it in the GlobalConfiguration. The limitation is that of course you cannot set the rate limiting options differently per route. However I think it is a good enough start. If this feature doesn't work let me know and I'll investigate. The other option you have is to store your configuration in consul, Ocelot will poll this. You can use some tool to update the config in consul and do your dynamic routing this way but it is not ideal! |
Beta Was this translation helpful? Give feedback.
-
Thanks @TomPallister for the information, i have gone through the link you posted and it is helpful but i want to apply rate limiting options on per route. I had thought of the option that you have suggested for storing configuration in consul and am looking for something ideal. Also, which can be integrated into the Ocelot and help someone with similar requirements. |
Beta Was this translation helpful? Give feedback.
-
@Rohitwagh ok cool that makes sense, the other option might be to store rate limiting meta data against the dynamic routed service in Consul and then at least you could apply the same settings per downstream service. This doesn’t give you per route options though. Just to clarify the global rate limiting is applied per route so a call to one doesn’t affect another. It is just the options that are shared. |
Beta Was this translation helpful? Give feedback.
-
Thanks for considering this. Yes, the global configuration for rate limit is helpful, but when it comes to rate limit options like period, limit and applying these on per service, just like we can do it in ReRoute file configuration. it is not available in dynamic routing. i'll check on your suggestion of setting rate limiting metadata against dynamic route in Consul or something for per route and will let you know how it works for me. |
Beta Was this translation helpful? Give feedback.
-
@Rohitwagh awesome if you want a challenge I would be happy to accept a PR if you have the time 😄 if not I will get round to this eventually! |
Beta Was this translation helpful? Give feedback.
-
Great!, i will write implementation for this where in, there will be a default provider for dynamic reroute configuration and if anyone want to, can write an external provider and use that as the default provider for dynamic configuration. I will send a PR once done. Thanks |
Beta Was this translation helpful? Give feedback.
-
@Rohitwagh Sorry for late reply, I have been away for a few days. Awesome let me know how it goes! Looking forward to seeing the code! |
Beta Was this translation helpful? Give feedback.
-
@TomPallister i have written the implementation and tested it, it is working fine for rate limit options. i have been busy with other stuff so could get much time on it, that is why the delay. However, i am not able to push the feature branch on this repository to create PR. Throws the authentication failed issue, while my Github credentials are working fine. Am i missing something or there is some other way to publish the feature branch? |
Beta Was this translation helpful? Give feedback.
-
@Rohitwagh that is awesome...you just need to to follow this process. |
Beta Was this translation helpful? Give feedback.
-
Thanks @TomPallister , that is an awesome getting started guide and very helpful. I have sent you PR at #501. Please have a look at it. |
Beta Was this translation helpful? Give feedback.
-
@Rohitwagh cool I will take a look asap. |
Beta Was this translation helpful? Give feedback.
-
@Rohitwagh I have implemented a way to set the rate limit per service when using dynamic routing for the disk and consul json configuration. The docs for this are here basically I have added the following to the configuration... "DynamicReRoutes": [
{
"ServiceName": "product",
"RateLimitRule": {
"ClientWhitelist": [],
"EnableRateLimiting": true,
"Period": "1s",
"PeriodTimespan": 1000.0,
"Limit": 3
}
}
], It will now be relatively easy to implement this for Redis. All you need to do is implement Redis version of IFileConfigurationRepository and then something like public IOcelotBuilder AddStoreOcelotConfigurationInRedis()
{
_services.AddHostedService<FileConfigurationPoller>();
_services.AddSingleton<IFileConfigurationRepository, RedisFileConfigurationRepository>();
return this;
} You will also need to change this in OcelotMiddlewareExtensions.cs to support a Redis implementation. private static bool UsingConsul(IFileConfigurationRepository fileConfigRepo)
{
return fileConfigRepo.GetType() == typeof(ConsulFileConfigurationRepository);
} Let me know if that doesn't make sense or there are any problems. |
Beta Was this translation helpful? Give feedback.
-
@Rohitwagh Dear author,
A brand new Rate Limiting was introduced in ASP.NET Core 7, see here.
You haven't replied to Tom. That's bad. I cannot get it... If you've prepared the PR, why is it closed? |
Beta Was this translation helpful? Give feedback.
@Rohitwagh Dear author,
Are you still with Ocelot?
A brand new Rate Limiting was introduced in ASP.NET Core 7, see here.
You haven't replied to Tom. That's bad.
I cannot get it... If you've prepared the PR, why is it closed?